Fix: proxy fs on windows (#3229)

This commit is contained in:
Erez Rokah 2020-02-11 12:48:02 +02:00 committed by GitHub
parent a399310513
commit 4b8c941da1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -11,7 +11,7 @@ const port = process.env.PORT || 8081;
(async () => {
app.use(morgan('combined'));
app.use(cors());
app.use(express.json());
app.use(express.json({ limit: '50mb' }));
try {
const mode = process.env.MODE || 'fs';

View File

@ -9,6 +9,9 @@ const sha256 = (buffer: Buffer) => {
.digest('hex');
};
// normalize windows os path format
const normalizePath = (path: string) => path.replace(/\\/g, '/');
export const entriesFromFiles = async (repoPath: string, files: string[]) => {
return Promise.all(
files.map(async file => {
@ -16,7 +19,7 @@ export const entriesFromFiles = async (repoPath: string, files: string[]) => {
const content = await fs.readFile(path.join(repoPath, file));
return {
data: content.toString(),
file: { path: file, id: sha256(content) },
file: { path: normalizePath(file), id: sha256(content) },
};
} catch (e) {
return { data: null, file: { path: file, id: null } };
@ -34,7 +37,7 @@ export const readMediaFile = async (repoPath: string, file: string) => {
id,
content: buffer.toString(encoding),
encoding,
path: file,
path: normalizePath(file),
name: path.basename(file),
};
};