Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/22 windows support #161

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions src/utils/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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', '/')}`;
};

Expand Down