diff options
| author | jw255 | 2018-04-17 22:58:03 +0100 |
|---|---|---|
| committer | jw255 | 2018-04-17 22:58:03 +0100 |
| commit | 505ae2d6af5ce31360f0f0b018a75cfee59cf3ac (patch) | |
| tree | 3fedd05c1f5fe402915a2bb02131d861f7fbf6f3 /src/files.ts | |
| parent | Files - now actually works (diff) | |
| download | medicine-505ae2d6af5ce31360f0f0b018a75cfee59cf3ac.tar.gz medicine-505ae2d6af5ce31360f0f0b018a75cfee59cf3ac.zip | |
using multer for files now
Diffstat (limited to 'src/files.ts')
| -rw-r--r-- | src/files.ts | 20 |
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; |
