aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/FileRouter.ts30
-rw-r--r--src/files.ts22
-rw-r--r--src/index.ts2
3 files changed, 26 insertions, 28 deletions
diff --git a/src/FileRouter.ts b/src/FileRouter.ts
index b4cd403..546c694 100644
--- a/src/FileRouter.ts
+++ b/src/FileRouter.ts
@@ -909,25 +909,17 @@ const postFilePath: Middleware = async(
}
} else {
if (req.query.overwrite) {
- if (req.query.truncate) {
- await saveFile(
- req.body,
- res.locals.project.name,
- res.locals.file.uuid,
- req.query
- );
- if (req.query.final) {
- res.locals.file.status = 'preprocessing';
- await res.locals.file.save();
- preprocess(res.locals.file, res.locals.project);
- }
- } else {
- logger.warn('overwriting without truncating not supported');
- return next(new RequestError(
- 500,
- 'not_implemented',
- 'please specify truncate parameter'
- ));
+ console.log("overwriting from offset " + (req.query.offset || 0))
+ await saveFile(
+ req.body,
+ res.locals.project.name,
+ res.locals.file.uuid,
+ req.query
+ );
+ if (req.query.final) {
+ res.locals.file.status = 'preprocessing';
+ await res.locals.file.save();
+ preprocess(res.locals.file, res.locals.project);
}
} else {
return next(new RequestError(400, 'file_already_exists'));
diff --git a/src/files.ts b/src/files.ts
index f5d5986..412f0c3 100644
--- a/src/files.ts
+++ b/src/files.ts
@@ -120,18 +120,24 @@ export const tempPath: (file: string, project: string) => string = (
): string =>
`${TEMP_BASE_DIRECTORY}/${uuid.generate()}`;
-export const saveFile: (data: Buffer, projectName: string, fileId: string, query: Query) => Promise<void> =
- async(data: Buffer, projectName: string, fileId: string, query: Query): Promise<void> => {
+export const saveFile: (data: Buffer, projectName: string,
+ fileId: string, query: Query) => Promise<void> =
+ async(data: Buffer, projectName: string,
+ fileId: string, query: Query): Promise<void> => {
// Ensure file exists
await fs.ensureFile(path(fileId, projectName));
// Truncate to offset
- await truncateFile(fileId, projectName, query.offset || 0);
- // Open streams to append to file
- fs.writeFile(path(fileId, projectName), data, "binary", (err: any) => {
+ if (!!query.truncate) {
+ await truncateFile(fileId, projectName, query.offset || 0);
+ }
+ const fuckingOffset: number = query.offset || 0;
+ // Open file
+ const fd: number = await fs.open(path(fileId, projectName), 'r+');
+ // Write data to file
+ fs.write(fd, data, 0, data.length, Number(fuckingOffset), (err: any, bytesWritten: number, buffer: Buffer) => {
+ console.log("written: " + bytesWritten)
if (err) {
- logger.failure(err);
- } else {
- logger.debug('The file was saved successfully');
+ logger.failure("Error while writing to file: " + err);
}
});
};
diff --git a/src/index.ts b/src/index.ts
index 884325e..30f82bf 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -166,7 +166,7 @@ async function reset(): Promise<void> {
process.exit(1);
}
- // await reset();
+ //await reset();
logger.info('Booting ExpressJS server');
app.listen(port, (err: Error) => {