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]>
110 lines
3.8 KiB
TypeScript
110 lines
3.8 KiB
TypeScript
import {html, htmlEscape, htmlRaw} from '../utils/html.ts';
|
|
import {svgRaw} from '../svg.ts';
|
|
import {animateOnce, queryElems, showElem} from '../utils/dom.ts';
|
|
import Toastify from 'toastify-js'; // don't use "async import", because when network error occurs, the "async import" also fails and nothing is shown
|
|
import type {Intent} from '../types.ts';
|
|
import type {SvgName} from '../svg.ts';
|
|
import type {Options} from 'toastify-js';
|
|
import type StartToastifyInstance from 'toastify-js';
|
|
|
|
export type Toast = ReturnType<typeof StartToastifyInstance>;
|
|
|
|
type ToastLevels = {
|
|
[intent in Intent]: {
|
|
icon: SvgName,
|
|
background: string,
|
|
duration: number,
|
|
}
|
|
};
|
|
|
|
const levels: ToastLevels = {
|
|
info: {
|
|
icon: 'octicon-check',
|
|
background: 'var(--color-green)',
|
|
duration: 2500,
|
|
},
|
|
warning: {
|
|
icon: 'hanzo-exclamation',
|
|
background: 'var(--color-orange)',
|
|
duration: -1, // requires dismissal to hide
|
|
},
|
|
error: {
|
|
icon: 'hanzo-exclamation',
|
|
background: 'var(--color-red)',
|
|
duration: -1, // requires dismissal to hide
|
|
},
|
|
};
|
|
|
|
type ToastOpts = {
|
|
useHtmlBody?: boolean,
|
|
preventDuplicates?: boolean | string,
|
|
} & Options;
|
|
|
|
type ToastifyElement = HTMLElement & {_hanzoToastifyInstance?: Toast};
|
|
|
|
/** See https://github.com/apvarun/toastify-js#api for options */
|
|
function showToast(message: string, level: Intent, {gravity, position, duration, useHtmlBody, preventDuplicates = true, ...other}: ToastOpts = {}): Toast | null {
|
|
const parent = document.querySelector('.ui.dimmer.active') ?? document.body;
|
|
const duplicateKey = preventDuplicates ? (typeof preventDuplicates === 'string' ? preventDuplicates : `${level}-${message}`) : '';
|
|
|
|
// prevent showing duplicate toasts with the same level and message, and give visual feedback for end users
|
|
if (preventDuplicates) {
|
|
const toastEl = parent.querySelector(`:scope > .toastify.on[data-toast-unique-key="${CSS.escape(duplicateKey)}"]`);
|
|
if (toastEl) {
|
|
const toastDupNumEl = toastEl.querySelector('.toast-duplicate-number')!;
|
|
showElem(toastDupNumEl);
|
|
toastDupNumEl.textContent = String(Number(toastDupNumEl.textContent) + 1);
|
|
animateOnce(toastDupNumEl, 'pulse-1p5-200');
|
|
return null;
|
|
}
|
|
}
|
|
|
|
const {icon, background, duration: levelDuration} = levels[level ?? 'info'];
|
|
const bodyHtml = useHtmlBody ? message : htmlEscape(message);
|
|
const toast = Toastify({
|
|
selector: parent,
|
|
text: html`
|
|
<div class='toast-icon'>${svgRaw(icon)}</div>
|
|
<div class='toast-body'><span class="toast-duplicate-number tw-hidden">1</span>${htmlRaw(bodyHtml)}</div>
|
|
<button class='btn toast-close'>${svgRaw('octicon-x')}</button>
|
|
`,
|
|
escapeMarkup: false,
|
|
gravity: gravity ?? 'top',
|
|
position: position ?? 'center',
|
|
duration: duration ?? levelDuration,
|
|
style: {background},
|
|
...other,
|
|
});
|
|
|
|
toast.showToast();
|
|
const el = toast.toastElement as ToastifyElement;
|
|
el.querySelector('.toast-close')!.addEventListener('click', () => toast.hideToast());
|
|
el.setAttribute('data-toast-unique-key', duplicateKey);
|
|
el._hanzoToastifyInstance = toast;
|
|
return toast;
|
|
}
|
|
|
|
export function showInfoToast(message: string, opts?: ToastOpts): Toast | null {
|
|
return showToast(message, 'info', opts);
|
|
}
|
|
|
|
export function showWarningToast(message: string, opts?: ToastOpts): Toast | null {
|
|
return showToast(message, 'warning', opts);
|
|
}
|
|
|
|
export function showErrorToast(message: string, opts?: ToastOpts): Toast | null {
|
|
return showToast(message, 'error', opts);
|
|
}
|
|
|
|
function hideToastByElement(el: Element): void {
|
|
(el as ToastifyElement)?._hanzoToastifyInstance?.hideToast();
|
|
}
|
|
|
|
export function hideToastsFrom(parent: Element): void {
|
|
queryElems(parent, ':scope > .toastify.on', hideToastByElement);
|
|
}
|
|
|
|
export function hideToastsAll(): void {
|
|
queryElems(document, '.toastify.on', hideToastByElement);
|
|
}
|