diff options
| author | cjd24 | 2018-04-23 15:32:02 +0100 |
|---|---|---|
| committer | cjd24 | 2018-04-23 15:32:02 +0100 |
| commit | 3987d5068881341c27150e37eff1794a27901cac (patch) | |
| tree | 6165dff18f9f0a31e4eecec056d264732f99bdd0 /src | |
| parent | PANIC COMMITS OMMGGGGG (diff) | |
| parent | ALL TESTS FIXXXXXXXED (diff) | |
| download | medicine-3987d5068881341c27150e37eff1794a27901cac.tar.gz medicine-3987d5068881341c27150e37eff1794a27901cac.zip | |
merge conflict
Diffstat (limited to 'src')
| -rw-r--r-- | src/FileRouter.ts | 10 | ||||
| -rw-r--r-- | src/app.ts | 2 | ||||
| -rw-r--r-- | src/conversion/csv/excel.ts | 4 | ||||
| -rw-r--r-- | src/files.ts | 15 | ||||
| -rw-r--r-- | src/index.ts | 3 |
5 files changed, 15 insertions, 19 deletions
diff --git a/src/FileRouter.ts b/src/FileRouter.ts index e977073..de75ded 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -589,7 +589,7 @@ const postProjectName: Middleware = async( if (project == null) { logger.debug('Adding new project'); const file: File = new File({ - uuid: uuid.generate(), + uuid: uuid.generate() }); file.mimetype = 'inode/directory'; file.name = ''; @@ -662,9 +662,7 @@ const getFileFromPath: (req: Request, res: Response) => Promise<void> = async( } return j; }; - const path: string = req.path.substring(nth(req.path, '/', 4) + 1); - res.locals.path = path; logger.debug(`Searching for path '${res.locals.path}'`); // Split path into parts @@ -674,7 +672,7 @@ const getFileFromPath: (req: Request, res: Response) => Promise<void> = async( ? fileNames[fileNames.length - 1] : ''; const project: Project | null = res.locals.project; - if (project == null) { + if (!project) { // Project should have been found by previous precondition logger.debug('Project was not found: skipping finding file'); throw new RequestError(404, 'project_not_found'); @@ -1117,6 +1115,6 @@ export class FileRouter { } // Create the FileRouter, and export its configured Express.Router -const fileRoutes: FileRouter = new FileRouter(); +//const fileRoutes: FileRouter = new FileRouter(); -export default fileRoutes.router; +export default new FileRouter().router; @@ -116,7 +116,7 @@ class App { defRouter.get('/', (req: ex.Request, res: ex.Response): void => { res.json({ message: 'Welcome to the CS3099 BE4 server!', - important: 'Endpoints start from /cs3099group-be-4' + important: 'Endpoints start from /cs3099group-be-4/' }); }); this.express.use('/cs3099group-be-4', FileRouter); diff --git a/src/conversion/csv/excel.ts b/src/conversion/csv/excel.ts index 3f5d30b..a9daecf 100644 --- a/src/conversion/csv/excel.ts +++ b/src/conversion/csv/excel.ts @@ -1,6 +1,6 @@ import { logger } from '../../logger'; import * as xlsx from 'xlsx'; -import * as fs from 'fs'; +import * as fs from 'fs-extra'; import { SupportedViews, writeJSONToFile } from '../types/helpers'; import * as csv from 'csv-parse'; import { extension } from '../../mimetype' @@ -10,7 +10,7 @@ const readFile = require('util').promisify(fs.readFile); const createFolder = require('util').promisify(fs.mkdir); const readDir = require('util').promisify(fs.readdir); const rename = require('util').promisify(fs.rename); -const copy = require('util').promisify(fs.copyFile); +const copy = require('util').promisify(fs.copy); const supportedViewsFromMem: (content: string) => Promise<SupportedViews> = (content: string): Promise<SupportedViews> => { return new Promise((res, rej) => { diff --git a/src/files.ts b/src/files.ts index 6e793d5..8b2d1d0 100644 --- a/src/files.ts +++ b/src/files.ts @@ -22,7 +22,7 @@ cache.on("error", function(err: any) { logger.error("Redis_Error: " + err); }) -const BASE_BASE: string = '/cs/scratch/cjd24/' +const BASE_BASE: string = `/cs/scratch/${require("os").userInfo().username}/` const CONTENT_BASE_DIRECTORY: string = BASE_BASE + 'files'; const LOG_BASE_DIRECTORY: string = BASE_BASE + 'logs'; const TEMP_BASE_DIRECTORY: string = BASE_BASE + 'files-temp'; @@ -129,18 +129,17 @@ export const tempPath: (file: string, project: string) => string = ( export const saveFile: (data: Buffer, projectName: string, fileId: string, query: Query) => Promise<void> = async(data: Buffer, projectName: string, fileId: string, query: Query): Promise<void> => { - // TODO only overwrite beginning of file and keep rest of data // 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 - const rStream: stream.PassThrough = new stream.PassThrough(); - rStream.end(data); - const wStream: fs.WriteStream = - fs.createWriteStream(path(fileId, projectName), { flags: 'a' }); - rStream.pipe(wStream).on('error', (err: Error) => { - throw new RequestError(500, `Error while saving file to proper location: ${err}`); + fs.writeFile(path(fileId, projectName), data, "binary", (err: any) => { + if (err) { + logger.failure(err); + } else { + logger.debug('The file was saved successfully'); + } }); }; diff --git a/src/index.ts b/src/index.ts index ad0d43e..884325e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -166,8 +166,7 @@ async function reset(): Promise<void> { process.exit(1); } -// await reset(); - + // await reset(); logger.info('Booting ExpressJS server'); app.listen(port, (err: Error) => { |
