aboutsummaryrefslogtreecommitdiff
path: root/src/files.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/files.ts')
-rw-r--r--src/files.ts20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/files.ts b/src/files.ts
index 9be0381..b0e63aa 100644
--- a/src/files.ts
+++ b/src/files.ts
@@ -1,6 +1,7 @@
import { Request, Response } from 'express';
-import * as fs from 'fs';
+import * as fs from 'fs-extra';
import { logger } from './logger';
+import * as Multer from 'multer';
import { default as File } from './db/model/File';
import { default as Project } from './db/model/Project';
@@ -38,6 +39,23 @@ const logPath: (type: string, projectName?: string) => string = (
: `${LOG_BASE_DIRECTORY}/general/${type}`;
};
+let storage = Multer.diskStorage({
+ destination: function (req, file, cb) {
+ cb(null, CONTENT_BASE_DIRECTORY)
+ },
+ filename: function (req, file, cb) {
+ cb(null, `temp-${file.originalname}`)
+ }
+});
+
+export const upload: Multer.Instance = Multer({ storage: storage });
+
+export const moveFile: (filename: string, projectname: string, fileId: string) => void =
+ (filename: string, projectname: string, fileId: string): void => {
+
+ fs.moveSync(`${CONTENT_BASE_DIRECTORY}/temp-${filename}`, `${CONTENT_BASE_DIRECTORY}/${projectname}/${fileId}`);
+}
+
export const files: {
path: (f: string, p: string) => string;
writableStream: (f: string, p: string) => fs.WriteStream;