From b76c4c489b56624e1c86e60ec8372a525890dedf 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 b457c0b52bc..ce2a5bd0101 100644 --- a/app/server/lib/BootProbes.ts +++ b/app/server/lib/BootProbes.ts @@ -71,7 +71,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) { @@ -96,7 +96,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 6d8d57ee56a..b4bb91fdae5 100644 --- a/app/server/lib/DocApi.ts +++ b/app/server/lib/DocApi.ts @@ -1070,7 +1070,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: { @@ -1084,7 +1084,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), @@ -1143,7 +1143,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', @@ -1172,7 +1172,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 24f583c6331..b04f2eb7ed2 100644 --- a/app/server/lib/FlexServer.ts +++ b/app/server/lib/FlexServer.ts @@ -302,9 +302,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; } @@ -312,7 +312,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; } @@ -1374,12 +1374,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); }; @@ -1403,7 +1403,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); @@ -1436,7 +1436,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', { @@ -2314,7 +2314,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 acee04b3443..0536e41daa7 100644 --- a/app/server/lib/GristServer.ts +++ b/app/server/lib/GristServer.ts @@ -33,7 +33,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 d34fcdf0289..0d2e4fdc822 100644 --- a/app/server/lib/uploads.ts +++ b/app/server/lib/uploads.ts @@ -411,7 +411,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);