mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Audited against the live site, not just the source. git.hanzo.ai renders a clean DOM already, so what was left was the surface that source greps miss and live headers show. The one leak visibly served on every request: set-cookie: gitea_incredible= The remember-me cookie default was never rebranded. Renamed to hanzo_git_remember; existing remember-me sessions are invalidated once. The container was branding the site title upstream. Both entrypoints wrote APP_NAME="Gitea: Git with a cup of tea" into app.ini, overriding the already-correct Go default. Removed the shell default entirely so the value lives in exactly one place, setting.AppName; ini MustString fills an empty key with the default. Half-finished earlier passes, now finished: the iframe query params were already hanzo-*, but the postMessage payload keys and the window global were not; the settings page told users to sign with "-n gitea" while the verifier is the only thing that has to agree with it, so the namespace is now one exported constant rendered into the command. Also: local storage prefix, the fetch-action request header (made vendor-free per our header convention, both ends are ours), install-form database prefill, and the shipped example config, which additionally documented $GITEA_WORK_DIR and $GITEA_CUSTOM -- env vars this fork renamed to GIT_* long ago -- and a COOKIE_USERNAME key the code no longer reads. Deleted docker/manifest*.tmpl: dead Drone-era templates publishing to gitea/gitea on Docker Hub, referenced by nothing. Our docker dry-run was also pulling build cache from ghcr.io/go-gitea/gitea. Deliberately left, with reasons: - "The Gitea Authors" copyright headers (2938) and upstream PR/issue links (278). Attribution and provenance; removing them would be wrong. - /data/gitea on-disk layout. Renaming it is a data migration that orphans every existing install's db, sessions, avatars and attachments. - The "gitea" webhook type and migration source. Wire and DB values, and the migration source correctly names a third party we import from, the same way github and gitlab do. Display name already reads Hanzo Git. - X-Gitea-OTP, X-Gitea-Object-Type and the X-Gitea-* webhook delivery headers. External client contracts on a live host; renaming them belongs in its own change, not a branding sweep. - gitea-azuread__a and sodipodi:docname in web_src/svg. Verified these never reach the DOM: svgo cleanupIds rewrites the ids and removeEditorsNSData strips the editor metadata before the asset is written. Co-authored-by: Hanzo Dev <[email protected]>
118 lines
5.3 KiB
TypeScript
118 lines
5.3 KiB
TypeScript
import {isDocumentFragmentOrElementNode} from '../utils/dom.ts';
|
|
import type {Promisable} from '../types.ts';
|
|
import type {InitPerformanceTracer} from './init.ts';
|
|
import {initAriaLabels} from './fomantic/base.ts';
|
|
|
|
let globalSelectorObserverInited = false;
|
|
|
|
type SelectorHandler<T extends Element> = {selector: string, handler: (el: T) => void};
|
|
const selectorHandlers: SelectorHandler<Element>[] = [];
|
|
|
|
type GlobalEventFunc<T extends HTMLElement, E extends Event> = (el: T, e: E) => Promisable<void>;
|
|
const globalEventFuncs: Record<string, GlobalEventFunc<HTMLElement, Event>> = {};
|
|
|
|
type GlobalInitFunc<T extends Element> = (el: T) => Promisable<void>;
|
|
const globalInitFuncs: Record<string, GlobalInitFunc<Element>> = {};
|
|
|
|
// It handles the global events for all `<div data-global-click="onSomeElemClick"></div>` elements.
|
|
export function registerGlobalEventFunc<T extends HTMLElement, E extends Event>(event: string, name: string, func: GlobalEventFunc<T, E>) {
|
|
globalEventFuncs[`${event}:${name}`] = func as GlobalEventFunc<HTMLElement, Event>;
|
|
}
|
|
|
|
// It handles the global init functions by a selector, for example:
|
|
// > registerGlobalSelectorObserver('.ui.dropdown:not(.custom)', (el) => { initDropdown(el, ...) });
|
|
// ATTENTION: For most cases, it's recommended to use registerGlobalInitFunc instead,
|
|
// Because this selector-based approach is less efficient and less maintainable.
|
|
// But if there are already a lot of elements on many pages, this selector-based approach is more convenient for exiting code.
|
|
export function registerGlobalSelectorFunc<T extends Element>(selector: string, handler: (el: T) => void) {
|
|
selectorHandlers.push({selector, handler: handler as (el: Element) => void});
|
|
// Then initAddedElementObserver will call this handler for all existing elements after all handlers are added.
|
|
// This approach makes the init stage only need to do one "querySelectorAll".
|
|
if (!globalSelectorObserverInited) return;
|
|
for (const el of document.querySelectorAll<T>(selector)) {
|
|
handler(el);
|
|
}
|
|
}
|
|
|
|
// It handles the global init functions for all `<div data-global-int="initSomeElem"></div>` elements.
|
|
export function registerGlobalInitFunc<T extends HTMLElement>(name: string, handler: GlobalInitFunc<T>) {
|
|
globalInitFuncs[name] = handler as GlobalInitFunc<Element>;
|
|
// The "global init" functions are managed internally and called by callGlobalInitFunc
|
|
// They must be ready before initGlobalSelectorObserver is called.
|
|
if (globalSelectorObserverInited) throw new Error('registerGlobalInitFunc() must be called before initGlobalSelectorObserver()');
|
|
}
|
|
|
|
function callGlobalInitFunc(el: Element) {
|
|
// TODO: GLOBAL-INIT-MULTIPLE-FUNCTIONS: maybe in the future we need to extend it to support multiple functions, for example: `data-global-init="func1 func2 func3"`
|
|
const initFunc = el.getAttribute('data-global-init')!;
|
|
const func = globalInitFuncs[initFunc];
|
|
if (!func) throw new Error(`Global init function "${initFunc}" not found`);
|
|
|
|
// when an element node is removed and added again, it should not be re-initialized again.
|
|
type HanzoGlobalInitElement = Partial<Element> & {_hanzoGlobalInited: boolean};
|
|
if ((el as HanzoGlobalInitElement)._hanzoGlobalInited) return;
|
|
(el as HanzoGlobalInitElement)._hanzoGlobalInited = true;
|
|
|
|
func(el);
|
|
}
|
|
|
|
function attachGlobalEvents() {
|
|
// add global "[data-global-click]" event handler
|
|
document.addEventListener('click', (e) => {
|
|
const elem = (e.target as HTMLElement).closest<HTMLElement>('[data-global-click]');
|
|
if (!elem) return;
|
|
const funcName = elem.getAttribute('data-global-click');
|
|
const func = globalEventFuncs[`click:${funcName}`];
|
|
if (!func) throw new Error(`Global event function "click:${funcName}" not found`);
|
|
func(elem, e);
|
|
});
|
|
}
|
|
|
|
export function initGlobalSelectorObserver(perfTracer: InitPerformanceTracer | null): void {
|
|
if (globalSelectorObserverInited) throw new Error('initGlobalSelectorObserver() already called');
|
|
globalSelectorObserverInited = true;
|
|
|
|
attachGlobalEvents();
|
|
|
|
selectorHandlers.push({selector: '[data-global-init]', handler: callGlobalInitFunc});
|
|
const observer = new MutationObserver((mutationList) => {
|
|
const len = mutationList.length;
|
|
for (let i = 0; i < len; i++) {
|
|
const mutation = mutationList[i];
|
|
const len = mutation.addedNodes.length;
|
|
for (let i = 0; i < len; i++) {
|
|
const addedNode = mutation.addedNodes[i] as ParentNode;
|
|
if (!isDocumentFragmentOrElementNode(addedNode)) continue;
|
|
|
|
initAriaLabels(addedNode);
|
|
for (const {selector, handler} of selectorHandlers) {
|
|
if ((addedNode instanceof Element) && addedNode.matches(selector)) {
|
|
handler(addedNode);
|
|
}
|
|
for (const el of addedNode.querySelectorAll?.<HTMLElement>(selector) ?? []) {
|
|
handler(el);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
initAriaLabels(document);
|
|
if (perfTracer) {
|
|
for (const {selector, handler} of selectorHandlers) {
|
|
perfTracer.recordCall(`initGlobalSelectorObserver ${selector}`, () => {
|
|
for (const el of document.querySelectorAll<HTMLElement>(selector)) {
|
|
handler(el);
|
|
}
|
|
});
|
|
}
|
|
} else {
|
|
for (const {selector, handler} of selectorHandlers) {
|
|
for (const el of document.querySelectorAll<HTMLElement>(selector)) {
|
|
handler(el);
|
|
}
|
|
}
|
|
}
|
|
observer.observe(document, {subtree: true, childList: true});
|
|
}
|