From c061e4921624682462004afc9d49a6fabae8706e Mon Sep 17 00:00:00 2001 From: fflorent Date: Thu, 28 Mar 2024 16:47:59 +0100 Subject: [PATCH] Cleanup --- app/server/lib/BootProbes.ts | 4 ++-- app/server/lib/DocApi.ts | 8 ++++---- app/server/lib/FlexServer.ts | 16 ++++++++-------- app/server/lib/GristServer.ts | 2 +- app/server/lib/uploads.ts | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/server/lib/BootProbes.ts b/app/server/lib/BootProbes.ts index e0ed47fe..8edc28ae 100644 --- a/app/server/lib/BootProbes.ts +++ b/app/server/lib/BootProbes.ts @@ -77,7 +77,7 @@ const _homeUrlReachableProbe: Probe = { id: 'reachable', name: 'Grist is reachable', apply: async (server, req) => { - const url = server.getHomeInternalUrl(req); + const url = server.getHomeInternalUrl(); try { const resp = await fetch(url); if (resp.status !== 200) { @@ -102,7 +102,7 @@ const _statusCheckProbe: Probe = { id: 'health-check', name: 'Built-in Health check', apply: async (server, req) => { - const baseUrl = server.getHomeInternalUrl(req); + const baseUrl = server.getHomeInternalUrl(); const url = new URL(baseUrl); url.pathname = removeTrailingSlash(url.pathname) + '/status'; try { diff --git a/app/server/lib/DocApi.ts b/app/server/lib/DocApi.ts index 5eb391f2..d0946696 100644 --- a/app/server/lib/DocApi.ts +++ b/app/server/lib/DocApi.ts @@ -1098,7 +1098,7 @@ export class DocWorkerApi { if (req.body.sourceDocId) { options.sourceDocId = await this._confirmDocIdForRead(req, String(req.body.sourceDocId)); // Make sure that if we wanted to download the full source, we would be allowed. - const homeUrl = this._grist.getHomeInternalUrl(req, `/api/docs/${options.sourceDocId}/download?dryrun=1`); + const homeUrl = this._grist.getHomeInternalUrl(`/api/docs/${options.sourceDocId}/download?dryrun=1`); const result = await fetch(homeUrl, { method: 'GET', headers: { @@ -1112,7 +1112,7 @@ export class DocWorkerApi { } // We should make sure the source document has flushed recently. // It may not be served by the same worker, so work through the api. - await fetch(this._grist.getHomeInternalUrl(req, `/api/docs/${options.sourceDocId}/flush`), { + await fetch(this._grist.getHomeInternalUrl(`/api/docs/${options.sourceDocId}/flush`), { method: 'POST', headers: { ...getTransitiveHeaders(req), @@ -1171,7 +1171,7 @@ export class DocWorkerApi { const showDetails = isAffirmative(req.query.detail); const docSession = docSessionFromRequest(req); const {states} = await this._getStates(docSession, activeDoc); - const ref = await fetch(this._grist.getHomeInternalUrl(req, `/api/docs/${req.params.docId2}/states`), { + const ref = await fetch(this._grist.getHomeInternalUrl(`/api/docs/${req.params.docId2}/states`), { headers: { ...getTransitiveHeaders(req), 'Content-Type': 'application/json', @@ -1200,7 +1200,7 @@ export class DocWorkerApi { // Calculate changes from the (common) parent to the current version of the other document. const url = `/api/docs/${req.params.docId2}/compare?left=${parent.h}`; - const rightChangesReq = await fetch(this._grist.getHomeInternalUrl(req, url), { + const rightChangesReq = await fetch(this._grist.getHomeInternalUrl(url), { headers: { ...getTransitiveHeaders(req), 'Content-Type': 'application/json', diff --git a/app/server/lib/FlexServer.ts b/app/server/lib/FlexServer.ts index 9236ccb5..aa70817c 100644 --- a/app/server/lib/FlexServer.ts +++ b/app/server/lib/FlexServer.ts @@ -309,9 +309,9 @@ export class FlexServer implements GristServer { * If relPath is given, returns that path relative to homeUrl. If omitted, note that * getHomeUrl() will still return a URL ending in "/". */ - public getHomeUrl(req: express.Request, relPath: string = '', defaultHomeUrl = this.getDefaultHomeUrl()): string { + public getHomeUrl(req: express.Request, relPath: string = ''): string { // Get the default home url. - const homeUrl = new URL(relPath, defaultHomeUrl); + const homeUrl = new URL(relPath, this.getDefaultHomeUrl()); adaptServerUrl(homeUrl, req as RequestWithOrg); return homeUrl.href; } @@ -319,7 +319,7 @@ export class FlexServer implements GristServer { /** * Same as getHomeUrl, but for requesting internally. */ - public getHomeInternalUrl(req: express.Request, relPath: string = ''): string { + public getHomeInternalUrl(relPath: string = ''): string { const homeUrl = new URL(relPath, this.getDefaultHomeInternalUrl()); return homeUrl.href; } @@ -1444,12 +1444,12 @@ export class FlexServer implements GristServer { return this._sendAppPage(req, resp, {path: 'app.html', status: 200, config: {}}); })); - const createDoom = async (req: express.Request) => { + const createDoom = async () => { const dbManager = this.getHomeDBManager(); const permitStore = this.getPermitStore(); const notifier = this.getNotifier(); const loginSystem = await this.resolveLoginSystem(); - const homeUrl = this.getHomeInternalUrl(req).replace(/\/$/, ''); + const homeUrl = this.getHomeInternalUrl().replace(/\/$/, ''); return new Doom(dbManager, permitStore, notifier, loginSystem, homeUrl); }; @@ -1473,7 +1473,7 @@ export class FlexServer implements GristServer { // Reuse Doom cli tool for account deletion. It won't allow to delete account if it has access // to other (not public) team sites. - const doom = await createDoom(req); + const doom = await createDoom(); await doom.deleteUser(userId); this.getTelemetry().logEvent(req as RequestWithLogin, 'deletedAccount'); return resp.status(200).json(true); @@ -1506,7 +1506,7 @@ export class FlexServer implements GristServer { } // Reuse Doom cli tool for org deletion. Note, this removes everything as a super user. - const doom = await createDoom(req); + const doom = await createDoom(); await doom.deleteOrg(org.id); this.getTelemetry().logEvent(req as RequestWithLogin, 'deletedSite', { @@ -2433,7 +2433,7 @@ export class FlexServer implements GristServer { const workspace = workspaces.find(w => w.name === 'Home'); if (!workspace) { throw new Error('Home workspace not found'); } - const copyDocUrl = this.getHomeInternalUrl(req, '/api/docs'); + const copyDocUrl = this.getHomeInternalUrl('/api/docs'); const response = await fetch(copyDocUrl, { headers: { ...getTransitiveHeaders(req), diff --git a/app/server/lib/GristServer.ts b/app/server/lib/GristServer.ts index 125dffc3..f40bf109 100644 --- a/app/server/lib/GristServer.ts +++ b/app/server/lib/GristServer.ts @@ -35,7 +35,7 @@ export interface GristServer { settings?: Readonly>; getHost(): string; getHomeUrl(req: express.Request, relPath?: string): string; - getHomeInternalUrl(req: express.Request, relPath?: string): string; + getHomeInternalUrl(relPath?: string): string; getHomeUrlByDocId(docId: string, relPath?: string): Promise; getOwnUrl(): string; getOrgUrl(orgKey: string|number): Promise; diff --git a/app/server/lib/uploads.ts b/app/server/lib/uploads.ts index 631708e1..d0990c72 100644 --- a/app/server/lib/uploads.ts +++ b/app/server/lib/uploads.ts @@ -417,7 +417,7 @@ export async function fetchDoc(server: GristServer, docId: string, req: Request, // Find the doc worker responsible for the document we wish to copy. // The backend needs to be well configured for this to work. - const homeUrl = server.getHomeInternalUrl(req); + const homeUrl = server.getHomeInternalUrl(); const fetchUrl = new URL(`/api/worker/${docId}`, homeUrl); const response: FetchResponse = await Deps.fetch(fetchUrl.href, {headers}); await _checkForError(response);