From d171409301aea775672091bfd51e5a0e7011efaf Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 26 Mar 2026 15:18:15 +0200 Subject: [PATCH] chore(setup): remove old files --- apps/client/src/setup_old.ts | 177 ------------------------- apps/server/src/assets/views/setup.ejs | 136 ------------------- apps/server/src/routes/index.ts | 3 +- 3 files changed, 2 insertions(+), 314 deletions(-) delete mode 100644 apps/client/src/setup_old.ts delete mode 100644 apps/server/src/assets/views/setup.ejs diff --git a/apps/client/src/setup_old.ts b/apps/client/src/setup_old.ts deleted file mode 100644 index c04435475a..0000000000 --- a/apps/client/src/setup_old.ts +++ /dev/null @@ -1,177 +0,0 @@ -import "jquery"; - -import utils from "./services/utils.js"; - -type SetupStep = "sync-in-progress" | "setup-type" | "new-document-in-progress" | "sync-from-desktop" | "sync-from-server"; -type SetupType = "new-document" | "sync-from-desktop" | "sync-from-server" | ""; - -class SetupController { - private step: SetupStep; - private setupType: SetupType = ""; - private syncPollIntervalId: number | null = null; - private rootNode: HTMLElement; - private setupTypeForm: HTMLFormElement; - private syncFromServerForm: HTMLFormElement; - private setupTypeNextButton: HTMLButtonElement; - private setupTypeInputs: HTMLInputElement[]; - private syncServerHostInput: HTMLInputElement; - private passwordInput: HTMLInputElement; - private sections: Record; - - constructor(rootNode: HTMLElement, syncInProgress: boolean) { - this.rootNode = rootNode; - this.step = syncInProgress ? "sync-in-progress" : "setup-type"; - this.setupTypeForm = mustGetElement("setup-type-form", HTMLFormElement); - this.syncFromServerForm = mustGetElement("sync-from-server-form", HTMLFormElement); - this.setupTypeNextButton = mustGetElement("setup-type-next", HTMLButtonElement); - this.setupTypeInputs = Array.from(document.querySelectorAll("input[name='setup-type']")); - this.syncServerHostInput = mustGetElement("sync-server-host", HTMLInputElement); - this.passwordInput = mustGetElement("password", HTMLInputElement); - this.sections = { - "setup-type": mustGetElement("setup-type-section", HTMLElement), - "new-document-in-progress": mustGetElement("new-document-in-progress-section", HTMLElement), - "sync-from-desktop": mustGetElement("sync-from-desktop-section", HTMLElement), - "sync-from-server": mustGetElement("sync-from-server-section", HTMLElement), - "sync-in-progress": mustGetElement("sync-in-progress-section", HTMLElement) - }; - } - - init() { - this.setupTypeForm.addEventListener("submit", (event) => { - event.preventDefault(); - void this.selectSetupType(); - }); - - this.syncFromServerForm.addEventListener("submit", (event) => { - event.preventDefault(); - void this.finish(); - }); - - for (const input of this.setupTypeInputs) { - input.addEventListener("change", () => { - this.setupType = input.value as SetupType; - this.render(); - }); - } - - for (const backButton of document.querySelectorAll("[data-action='back']")) { - backButton.addEventListener("click", () => { - this.back(); - }); - } - - const serverAddress = `${location.protocol}//${location.host}`; - $("#current-host").html(serverAddress); - - if (this.step === "sync-in-progress") { - this.startSyncPolling(); - } - - this.render(); - this.rootNode.style.display = ""; - } - - private async selectSetupType() { - if (this.setupType === "new-document") { - this.setStep("new-document-in-progress"); - - await $.post("api/setup/new-document"); - window.location.replace("./setup"); - return; - } - - if (this.setupType) { - this.setStep(this.setupType); - } - } - - private back() { - this.setStep("setup-type"); - this.setupType = ""; - - for (const input of this.setupTypeInputs) { - input.checked = false; - } - - this.render(); - } - - private async finish() { - const syncServerHost = this.syncServerHostInput.value.trim(); - const syncProxy = this.syncProxyInput.value.trim(); - const password = this.passwordInput.value; - - if (resp.result === "success") { - hideAlert(); - this.setStep("sync-in-progress"); - this.startSyncPolling(); - } else { - showAlert(`Sync setup failed: ${resp.error}`); - } - } - - private setStep(step: SetupStep) { - this.step = step; - this.render(); - } - - private render() { - for (const [step, section] of Object.entries(this.sections) as [SetupStep, HTMLElement][]) { - section.style.display = step === this.step ? "" : "none"; - } - - this.setupTypeNextButton.disabled = !this.setupType; - } - - private getSelectedSetupType(): SetupType { - return (this.setupTypeInputs.find((input) => input.checked)?.value ?? "") as SetupType; - } -} - -async function checkOutstandingSyncs() { - const { outstandingPullCount, initialized } = await $.get("api/sync/stats"); - - if (initialized) { - if (utils.isElectron()) { - const remote = utils.dynamicRequire("@electron/remote"); - remote.app.relaunch(); - remote.app.exit(0); - } else { - utils.reloadFrontendApp(); - } - } else { - $("#outstanding-syncs").html(outstandingPullCount); - } -} - -function showAlert(message: string) { - $("#alert").text(message); - $("#alert").show(); -} - -function hideAlert() { - $("#alert").hide(); -} - -function getSyncInProgress() { - const el = document.getElementById("syncInProgress"); - if (!el || !(el instanceof HTMLMetaElement)) return false; - return !!parseInt(el.content); -} - -function mustGetElement(id: string, ctor: T): InstanceType { - const element = document.getElementById(id); - - if (!element || !(element instanceof ctor)) { - throw new Error(`Expected element #${id}`); - } - - return element as InstanceType; -} - -addEventListener("DOMContentLoaded", (event) => { - const rootNode = document.getElementById("setup-dialog"); - if (!rootNode || !(rootNode instanceof HTMLElement)) return; - - new SetupController(rootNode, getSyncInProgress()).init(); -}); diff --git a/apps/server/src/assets/views/setup.ejs b/apps/server/src/assets/views/setup.ejs deleted file mode 100644 index 154249b67b..0000000000 --- a/apps/server/src/assets/views/setup.ejs +++ /dev/null @@ -1,136 +0,0 @@ - - - - - - - <%= t("setup.title") %> - - - - - - -
- -
- - - - - - - - - - - - diff --git a/apps/server/src/routes/index.ts b/apps/server/src/routes/index.ts index 14eec1714c..f1ce6cd8cd 100644 --- a/apps/server/src/routes/index.ts +++ b/apps/server/src/routes/index.ts @@ -30,7 +30,8 @@ export function bootstrap(req: Request, res: Response) { if (!isDbInitialized) { res.send({ ...commonItems, - baseApiUrl: "api/" + baseApiUrl: "api/", + componentId: "" }); return; }