diff --git a/package.json b/package.json index fb463269..a884b353 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "author": "Jannis Baum", "scripts": { "dev": "VIV_TIMEOUT=0 VIV_PORT=3000 NODE_ENV=development nodemon --exec node --loader ts-node/esm src/app.ts", + "win-dev": "set VIV_TIMEOUT=0& set VIV_PORT=3000& set NODE_ENV=development& nodemon --exec node --loader ts-node/esm src/app.ts", "viv": "VIV_PORT=3000 node --loader ts-node/esm src/app.ts", "lint": "eslint src static", "lint-markdown": "markdownlint-cli2 --config .github/.markdownlint-cli2.yaml", diff --git a/src/utils/path.ts b/src/utils/path.ts index 7c0397f6..7d145ee8 100644 --- a/src/utils/path.ts +++ b/src/utils/path.ts @@ -7,8 +7,11 @@ import { promisify } from 'util'; const execPromise = promisify(exec); export const pmime = async (path: string) => { + if (process.platform === 'win32') { + path = `C:${path.replaceAll('/', '\\')}`; // TODO: Some Windows hackery + } const [{ stdout: mime }, stats] = await Promise.all([ - execPromise(`file --mime-type -b '${path}'`), + execPromise(`file --mime-type -b "${path}"`), // Path needs to be wrapped in double quotes on Windows stat(path), ]); // empty files can also be `application/x-empty` @@ -54,7 +57,7 @@ export const urlToPath = (url: string) => { }; export const pathToURL = (path: string, route: string = 'viewer') => { - const withoutPrefix = path.startsWith('/') ? path.slice(1) : path; + const withoutPrefix = path.startsWith('/') || path.startsWith('\\') ? path.slice(1) : path; // TODO: Windows hack return `/${route}/${encodeURIComponent(withoutPrefix).replaceAll('%2F', '/')}`; };