Skip to content

Commit

Permalink
Hacks to make Windows paths work
Browse files Browse the repository at this point in the history
  • Loading branch information
Tweekism committed Aug 9, 2024
1 parent ee27dbf commit 9d59928
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 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,8 @@ 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

0 comments on commit 9d59928

Please sign in to comment.