From b8ed41883fb0b9faf2733632657243c7dece4d6e Mon Sep 17 00:00:00 2001 From: jw255 Date: Thu, 19 Apr 2018 21:10:18 +0100 Subject: reduced # of failing tests --- src/FileRouter.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/FileRouter.ts') diff --git a/src/FileRouter.ts b/src/FileRouter.ts index 53fc537..3f966c2 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -168,7 +168,7 @@ const getProperties: Middleware = ( const postProperties: Middleware = ( req: Request, res: Response, next: NextFunction ): void => { - logger.debug('Editing server properties'); + console.log('Editing server properties'); res.locals.modified = true; for (const newProp of req.body) { const prop: Property | undefined = serverConfig.find( @@ -189,6 +189,7 @@ const postProperties: Middleware = ( return; } } + console.log("Posted Properties successfully"); next(); }; @@ -629,7 +630,8 @@ const postFilePath: Middleware = async(req: Request, res: Response, next: NextFu // Sets final if requested if (res.locals.file && qH.isFinal(req)) { - res.locals.file.status = 'final'; + res.locals.file.status = 'preprocessing'; + // start file conversion } // Sets Metadata if requested @@ -767,7 +769,7 @@ export class FileRouter { // File access this.router.get ('/projects/:project_name/files/:path', getFilePath); this.router.post('/projects/:project_name/files/:path', - upload.single('userfile'), postFilePath); + upload.single('userfile'), postFilePath); this.router.get ('/projects/:project_name/files_by_id/:id', getFileId); } -- cgit v1.2.1 From 8d0293af5592402448769451f85ce666ed407cb4 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Fri, 20 Apr 2018 15:15:46 +0100 Subject: Finalise CORS support with package corser --- src/FileRouter.ts | 75 ++++++++++++++++++++++--------------------------------- 1 file changed, 30 insertions(+), 45 deletions(-) (limited to 'src/FileRouter.ts') diff --git a/src/FileRouter.ts b/src/FileRouter.ts index 3f966c2..9059e88 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -5,14 +5,14 @@ import { ProjectFullInfo, default as Project } from './db/model/Project'; import { UserFullInfo, default as User } from './db/model/User'; import { default as UserGroup } from './db/model/UserGroup'; -import { NextFunction, Request, Response, Router } from 'express'; import { RequestError } from './errors/errorware'; -import { addSubFileToFolder, View, files, views, rootPathId, createProjectFolder, upload, deleteFile, truncateFile, saveFile } from './files'; +import { NextFunction, Request, Response, Router } from 'express'; +import { View, addSubFileToFolder, createProjectFolder, deleteFile, rootPathId, + saveFile, upload, views } from './files'; import { logger } from './logger'; import { Property, default as serverConfig } from './serverConfig'; import { uuid } from './uuid'; - /** * The type of an Express middleware callback. */ @@ -110,7 +110,7 @@ const getLog: Middleware = ( if (!req.user.hasPrivilege('admin')) { next(new RequestError(401, 'invalid_privilege')); } - /* tslint:disable */ + /* tslint:disable */ if(!req.params.level) req.params.level = 'info'; if(!req.params.before) req.params.before = new Date(); if(!req.params.after) req.params.after = new Date(0); @@ -168,7 +168,7 @@ const getProperties: Middleware = ( const postProperties: Middleware = ( req: Request, res: Response, next: NextFunction ): void => { - console.log('Editing server properties'); + logger.debug('Editing server properties'); res.locals.modified = true; for (const newProp of req.body) { const prop: Property | undefined = serverConfig.find( @@ -189,7 +189,7 @@ const postProperties: Middleware = ( return; } } - console.log("Posted Properties successfully"); + logger.debug('Posted Properties successfully'); next(); }; @@ -567,41 +567,25 @@ const getFileId: Middleware = getFile; /** * Checks the parameters for file posting */ -namespace qH { - export const hasAction: ((req: Request) => boolean) = (req: Request): boolean => { - return (req.query.action ? true : false); - } - export const setsMetadata: ((req: Request) => boolean) = (req: Request): boolean => { - return (req.query.action && req.query.action == 'set_metadata' ? true : false); - } - export const mksDir: ((req: Request) => boolean) = (req: Request): boolean => { - return (req.query.action && req.query.action == 'mkdir' ? true : false); - } - export const deletes: ((req: Request) => boolean) = (req: Request): boolean => { - return (req.query.action && req.query.action == 'delete' ? true : false); - } - export const moves: ((req: Request) => boolean) = (req: Request): boolean => { - return (req.query.action && req.query.action == 'move' ? true : false); - } - export const copys: ((req: Request) => boolean) = (req: Request): boolean => { - return (req.query.action && req.query.action == 'copy' ? true : false); - } - export const overwrites: ((req: Request) => boolean) = (req: Request): boolean => { - return (req.query.overwrite ? req.query.overwrite : false); - } - export const offset: ((req: Request) => number) = (req: Request): number => { - return (req.query.offset ? req.query.offset : 0); - } - export const truncates: ((req: Request) => boolean) = (req: Request): boolean => { - return (req.query.truncate ? req.query.truncate : false); - } - export const isFinal: ((req: Request) => boolean) = (req: Request): boolean => { - return (req.query.final ? req.query.final : false); - } - export const nothingSet: ((req: Request) => boolean) = (req: Request): boolean => { - return (!hasAction(req) && !overwrites(req) && !truncates(req) && !isFinal(req)); - } -} +const qH: { + [key: string]: Function; +} = { + hasAction: (req: Request): boolean => !!req.query.action, + setsMetadata: (req: Request): boolean => + req.query.action === 'set_metadata', + mksDir: (req: Request): boolean => req.query.action === 'mkdir', + deletes: (req: Request): boolean => req.query.action === 'delete', + moves: (req: Request): boolean => req.query.action === 'move', + copys: (req: Request): boolean => req.query.action === 'copy', + overwrites: (req: Request): boolean => !!req.query.overwrite, + offset: (req: Request): number => + req.query.offset ? req.query.offset : 0, + truncates: (req: Request): boolean => !!req.query.truncate, + isFinal: (req: Request): boolean => !!req.query.final, + nothingSet: (req: Request): boolean => + !qH.hasAction(req) && !qH.overwrites(req) && + !qH.truncates(req) && !qH.isFinal(req) +}; /** * Post a File. / delete / move / etc @@ -722,9 +706,9 @@ const postFilePath: Middleware = async(req: Request, res: Response, next: NextFu if (qH.isFinal(req)) { res.locals.file.status = 'final'; } - + next(); - + }; /* tslint:enable */ @@ -768,8 +752,9 @@ export class FileRouter { this.router.get ('/projects/:project_name/properties', getProjectProperties); // File access this.router.get ('/projects/:project_name/files/:path', getFilePath); - this.router.post('/projects/:project_name/files/:path', - upload.single('userfile'), postFilePath); + this.router.post( + '/projects/:project_name/files/:path', + upload.single('userfile'), postFilePath); this.router.get ('/projects/:project_name/files_by_id/:id', getFileId); } -- cgit v1.2.1