Skip to content

Commit

Permalink
fix(#147): decode path for client VIV_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
jannis-baum committed Aug 1, 2024
1 parent 9dd90af commit 7778491
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/routes/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -81,7 +81,7 @@ router.get(/.*/, async (req: Request, res: Response) => {
</body>
<script>
window.VIV_PORT = "${config.port}";
window.VIV_PATH = "${absPath(req.path)}";
window.VIV_PATH = "${urlToPath(req.path)}";
</script>
${config.scripts ? `<script type="text/javascript">${config.scripts}</script>` : ''}
<script type="text/javascript" src="/static/client.js"></script>
Expand Down
6 changes: 3 additions & 3 deletions src/utils/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down

0 comments on commit 7778491

Please sign in to comment.