From ec07ac5ec5da0e9649b36c3b138696a993ac9451 Mon Sep 17 00:00:00 2001 From: Jason Fairchild Date: Tue, 30 Jul 2024 16:56:31 +1000 Subject: [PATCH 1/3] strip env vars for win-dev yarn script --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index fb463269..953eb539 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": "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", From ee27dbf76f719159305da49b4ddf23d953c88343 Mon Sep 17 00:00:00 2001 From: Jason Fairchild Date: Tue, 30 Jul 2024 23:03:28 +1000 Subject: [PATCH 2/3] Add Windows specific env vars --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 953eb539..a884b353 100644 --- a/package.json +++ b/package.json @@ -4,7 +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": "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", From f43d496511bb98246c74fb5ce6ecfd0429d88494 Mon Sep 17 00:00:00 2001 From: Jason Fairchild Date: Wed, 31 Jul 2024 12:06:36 +1000 Subject: [PATCH 3/3] Hacks to make Windows paths work --- src/utils/path.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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', '/')}`; };