diff --git a/src/routes/viewer.ts b/src/routes/viewer.ts index 8ba4343e..1aae6cf3 100644 --- a/src/routes/viewer.ts +++ b/src/routes/viewer.ts @@ -6,7 +6,7 @@ import { Request, Response, Router } from 'express'; import { clientsAt, messageClients } from '../app.js'; import config from '../config.js'; -import { absPath, pcomponents, pmime, preferredPath } from '../utils/path.js'; +import { pcomponents, pmime, preferredPath, urlToPath } from '../utils/path.js'; import { renderDirectory, renderTextFile, shouldRender } from '../parser/parser.js'; export const router = Router(); @@ -81,7 +81,7 @@ router.get(/.*/, async (req: Request, res: Response) => { ${config.scripts ? `` : ''} diff --git a/src/utils/path.ts b/src/utils/path.ts index 5e0cff13..99fb4926 100644 --- a/src/utils/path.ts +++ b/src/utils/path.ts @@ -21,10 +21,10 @@ export const pcomponents = (path: string) => { return components; }; -export const absPath = (path: string) => path.replace(/^\/~/, homedir()).replace(/\/+$/, ''); - export const urlToPath = (url: string) => { - const path = absPath(decodeURIComponent(url.replace(/^\/(viewer|health)/, ''))); + const path = decodeURIComponent(url.replace(/^\/(viewer|health)/, '')) + .replace(/^\/~/, homedir()) + .replace(/\/+$/, ''); return path === '' ? '/' : path; };