From 9c0ff9a0b7d73e5e2a12c4f87d1aa586c59adec9 Mon Sep 17 00:00:00 2001 From: jw255 Date: Fri, 13 Apr 2018 21:12:53 +0100 Subject: only 12 failing tests :D --- src/FileRouter.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/FileRouter.ts') diff --git a/src/FileRouter.ts b/src/FileRouter.ts index e890241..4ee42dc 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -547,7 +547,7 @@ const getFileId: Middleware = getFile; const postFilePath: Middleware = ( req: Request, res: Response, next: NextFunction ): void => { - logger.debug('Receiving file'); + logger.debug('Receiving file to ' + res.locals.parentFolder); if (res.locals.file != null) { next(new RequestError(400, 'file_exists')); } @@ -556,7 +556,18 @@ const postFilePath: Middleware = ( name: res.locals.filename, parentFolder: res.locals.parentFolder }); - req.pipe(files.writableStream(file.uuid, res.locals.project.name)); + /* + console.log("1: " + file.uuid + " -- " + res.locals.project.name) + try { + let x = files.writableStream(file.uuid, res.locals.project.name); + console.log("2") + req.pipe(x); + console.log("3") + } catch (err) { + console.log(err); + } + console.log("4") + */ next(); }; @@ -652,11 +663,12 @@ export class FileRouter { // Fetch a file from its path: this.router.param( - 'file', + 'path', async( req: Request, res: Response, next: NextFunction, filename: string ): Promise => { + console.log("wrong precond") logger.debug(`Searching for file ${filename}`); const fileNames: string[] = req.params.path.split('/'); const project: Project | null = res.locals.project; @@ -709,18 +721,15 @@ export class FileRouter { req: Request, res: Response, next: NextFunction, fileId: string ): Promise => { - logger.debug(`Searching for file ${fileId}`); + console.log(`Searching for file ${fileId}`); const file: File | null = await File.findOne({ include: [{all: true}], where: { uuid: fileId } }); - if (file == null) { - return next(new RequestError(404, 'file_not_found')); - } else { - res.locals.file = file; - } + res.locals.file = file; + console.log("precondition: " + file) next(); } ); -- cgit v1.2.1 From 71a674b70f0003e215f6d9ba5e5b94db36a83b36 Mon Sep 17 00:00:00 2001 From: Hafeez Date: Sat, 14 Apr 2018 19:47:18 +0100 Subject: think i fixed something --- src/FileRouter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/FileRouter.ts') diff --git a/src/FileRouter.ts b/src/FileRouter.ts index 4ee42dc..ff0e65d 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -425,7 +425,7 @@ const getProjects: Middleware = async( }); res.locals.data = projects.map( (p: Project): ProjectFullInfo => p.fullInfo - ); + ); next(); }; -- cgit v1.2.1 From 1e6cb08fcdec54f1263eb1f6fdae6e0f438dfc97 Mon Sep 17 00:00:00 2001 From: jw255 Date: Sun, 15 Apr 2018 17:24:10 +0100 Subject: fixed logging --- src/FileRouter.ts | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'src/FileRouter.ts') diff --git a/src/FileRouter.ts b/src/FileRouter.ts index ff0e65d..4e32fb3 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -65,6 +65,7 @@ const getProtocols: Middleware = ( const postLog: Middleware = ( req: Request, res: Response, next: NextFunction ): void => { + res.locals.modified = true; logger.debug('Adding forwarded log'); if (!req.user.hasPrivilege('logging')) { next(new RequestError(401, 'invalid_privilege')); @@ -108,9 +109,15 @@ const getLog: Middleware = ( req: Request, res: Response, next: NextFunction ): void => { logger.debug('Fetching log'); + res.locals.modified = true; if (!req.user.hasPrivilege('admin')) { next(new RequestError(401, 'invalid_privilege')); } + /* 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); + /* tslint:enable */ res.locals.data = logger.fetch( req.params.level, { before: new Date(req.params.before), @@ -165,6 +172,7 @@ const postProperties: Middleware = ( req: Request, res: Response, next: NextFunction ): void => { logger.debug('Editing server properties'); + res.locals.modified = true; for (const newProp of req.body) { const prop: Property | undefined = serverConfig.find( (p: Property): boolean => p.id === newProp.id @@ -257,6 +265,7 @@ const getUserProperties: Middleware = ( req: Request, res: Response, next: NextFunction ): void => { logger.debug('Listing additional properties for a user'); + res.locals.modified = true; if (res.locals.user == null) { next(new RequestError(404, 'user_not_found')); return; @@ -289,6 +298,7 @@ const getUsername: Middleware = ( req: Request, res: Response, next: NextFunction ): void => { logger.debug(`Listing user ${res.locals.user}`); + res.locals.modified = true; if (res.locals.user == null) { next(new RequestError(404, 'user_not_found')); return; @@ -327,6 +337,7 @@ const postCurUser: Middleware = async( req: Request, res: Response, next: NextFunction ): Promise => { logger.debug('Editing current user'); + res.locals.modified = true; try { await req.user.updateInfo(req.body); await req.user.save(); @@ -357,14 +368,15 @@ const postUsername: Middleware = async( req: Request, res: Response, next: NextFunction ): Promise => { let user: User | null | undefined = res.locals.user; + res.locals.modified = true; if (user == null) { - console.log('Adding new user'); + logger.debug('Adding new user'); user = new User({ username: req.params.username, password: req.params.password }); } else { - console.log('Editing user'); + logger.debug('Editing user'); user.password = req.params.password; } if (req.body) { @@ -387,6 +399,7 @@ const postUsername: Middleware = async( const getProjectRoles: Middleware = async( req: Request, res: Response, next: NextFunction ): Promise => { + res.locals.modified = true; logger.debug('Listing available project roles'); const roles: ContributorGroup[] = await ContributorGroup.findAll(); res.locals.data = roles.filter( @@ -418,6 +431,7 @@ const getProjects: Middleware = async( req: Request, res: Response, next: NextFunction ): Promise => { logger.debug('Listing all projects'); + res.locals.modified = true; const projects: Project[] = await Project.findAll({ include: [ User @@ -425,7 +439,7 @@ const getProjects: Middleware = async( }); res.locals.data = projects.map( (p: Project): ProjectFullInfo => p.fullInfo - ); + ); next(); }; @@ -450,6 +464,7 @@ const getProjectName: Middleware = async( req: Request, res: Response, next: NextFunction ): Promise => { logger.debug('Getting project properties'); + res.locals.modified = true; const project: Project | null = res.locals.project; if (project == null) { return next(new RequestError(404, 'project_not_found')); @@ -476,6 +491,7 @@ const postProjectName: Middleware = async( req: Request, res: Response, next: NextFunction ): Promise => { let project: Project | null = res.locals.project; + res.locals.modified = true; let promise: PromiseLike | null = null; if (project == null) { logger.debug('Adding new project'); @@ -505,6 +521,7 @@ const getProjectProperties: Middleware = ( req: Request, res: Response, next: NextFunction ): void => { logger.debug('Getting project properties'); + res.locals.modified = true; if (res.locals.project == null) { next(new RequestError(404, 'project_not_found')); } else { @@ -520,6 +537,7 @@ const getFile: Middleware = async( req: Request, res: Response, next: NextFunction ): Promise => { logger.debug(`Getting file in ${req.query.view} view`); + res.locals.modified = true; const file: File | null = res.locals.file; if (file == null) { return next(new RequestError(404, 'file_not_found')); @@ -547,7 +565,8 @@ const getFileId: Middleware = getFile; const postFilePath: Middleware = ( req: Request, res: Response, next: NextFunction ): void => { - logger.debug('Receiving file to ' + res.locals.parentFolder); + logger.debug(`Receiving file to ${res.locals.parentFolder}`); + res.locals.modified = true; if (res.locals.file != null) { next(new RequestError(400, 'file_exists')); } @@ -611,7 +630,7 @@ 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/:id', postFilePath); + this.router.post('/projects/:project_name/files/:path', postFilePath); this.router.get ('/projects/:project_name/files_by_id/:id', getFileId); } @@ -668,7 +687,7 @@ export class FileRouter { req: Request, res: Response, next: NextFunction, filename: string ): Promise => { - console.log("wrong precond") + console.log(`parsing path ${filename}`) logger.debug(`Searching for file ${filename}`); const fileNames: string[] = req.params.path.split('/'); const project: Project | null = res.locals.project; @@ -721,7 +740,7 @@ export class FileRouter { req: Request, res: Response, next: NextFunction, fileId: string ): Promise => { - console.log(`Searching for file ${fileId}`); + console.log(`parsing id ${fileId}`); const file: File | null = await File.findOne({ include: [{all: true}], where: { @@ -729,7 +748,6 @@ export class FileRouter { } }); res.locals.file = file; - console.log("precondition: " + file) next(); } ); -- cgit v1.2.1 From 848f02bcacc11578314ab2e75ccb5b65dba0a6bc Mon Sep 17 00:00:00 2001 From: Hafeez Date: Sun, 15 Apr 2018 18:22:05 +0100 Subject: started modifying file upload --- src/FileRouter.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'src/FileRouter.ts') diff --git a/src/FileRouter.ts b/src/FileRouter.ts index ff0e65d..0a8d06a 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -556,6 +556,7 @@ const postFilePath: Middleware = ( name: res.locals.filename, parentFolder: res.locals.parentFolder }); + console.log(res.locals); /* console.log("1: " + file.uuid + " -- " + res.locals.project.name) try { -- cgit v1.2.1 From acd2cd460ef781ba5ae37d579ac984ca4ee1948c Mon Sep 17 00:00:00 2001 From: Hafeez Date: Sun, 15 Apr 2018 19:44:38 +0100 Subject: file upload works, i thnk --- src/FileRouter.ts | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'src/FileRouter.ts') diff --git a/src/FileRouter.ts b/src/FileRouter.ts index d6cea53..9a7dcac 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -575,19 +575,8 @@ const postFilePath: Middleware = ( name: res.locals.filename, parentFolder: res.locals.parentFolder }); - console.log(res.locals); - /* - console.log("1: " + file.uuid + " -- " + res.locals.project.name) - try { - let x = files.writableStream(file.uuid, res.locals.project.name); - console.log("2") - req.pipe(x); - console.log("3") - } catch (err) { - console.log(err); - } - console.log("4") - */ + //console.log(res.locals); + req.pipe(files.writableStream(file.uuid, res.locals.project.name)); next(); }; @@ -714,13 +703,14 @@ export class FileRouter { } const parentFolder: File | null = await File.findOne({ include: [ - { model: File, as: 'containedFiles' } + { model: File, as: 'containedFilesInternal'}, ], where: { - parentFolder: file, - name: fileNames[0] + //parentFolder: file, + //name: fileNames[0] } }); + //console.log(parentFolder); if (parentFolder == null) { return next(); } -- cgit v1.2.1 From a41380c2ab3b06dd78f61f723f83b84a386b83a8 Mon Sep 17 00:00:00 2001 From: Hafeez Date: Mon, 16 Apr 2018 16:07:21 +0100 Subject: precondition files works --- src/FileRouter.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/FileRouter.ts') diff --git a/src/FileRouter.ts b/src/FileRouter.ts index 9a7dcac..f941dd6 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -575,7 +575,7 @@ const postFilePath: Middleware = ( name: res.locals.filename, parentFolder: res.locals.parentFolder }); - //console.log(res.locals); + //console.log(res.locals); req.pipe(files.writableStream(file.uuid, res.locals.project.name)); next(); }; @@ -701,13 +701,16 @@ export class FileRouter { } fileNames.splice(0, 1); } + if (file == null) { + return next(); + } const parentFolder: File | null = await File.findOne({ include: [ { model: File, as: 'containedFilesInternal'}, ], where: { - //parentFolder: file, - //name: fileNames[0] + parentFolderId: file.id, + name: fileNames[0] } }); //console.log(parentFolder); -- cgit v1.2.1 From d628ed540c883764eff623c7a059bcb588c017bc Mon Sep 17 00:00:00 2001 From: jw255 Date: Mon, 16 Apr 2018 16:08:08 +0100 Subject: nothing major --- src/FileRouter.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/FileRouter.ts') diff --git a/src/FileRouter.ts b/src/FileRouter.ts index 9a7dcac..f7a1809 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -689,6 +689,7 @@ export class FileRouter { // TODO Rewrite using sub-queries instead of repeated queries. while (fileNames.length > 2) { const fileOrNull: File | null = await File.findOne({ + include: [{all: true}], where: { name: fileNames[0], parentFolder: file @@ -703,7 +704,7 @@ export class FileRouter { } const parentFolder: File | null = await File.findOne({ include: [ - { model: File, as: 'containedFilesInternal'}, + { model: File, as: 'containedFilesInternal'} ], where: { //parentFolder: file, -- cgit v1.2.1 From 4ec93e886fc10de2c65e9599dbfca2a70db578e3 Mon Sep 17 00:00:00 2001 From: jw255 Date: Mon, 16 Apr 2018 19:34:57 +0100 Subject: World War Files, part 1\nRoot folder is automatically created at the start of the server. also project folder should now appear in the filesystem --- src/FileRouter.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/FileRouter.ts') diff --git a/src/FileRouter.ts b/src/FileRouter.ts index 70243c3..ca2ed50 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -8,7 +8,7 @@ import { default as UserGroup } from './db/model/UserGroup'; import { NextFunction, Request, Response, Router } from 'express'; import { RequestError } from './errors/errorware'; -import { View, files, views } from './files'; +import { View, files, views, rootPathId, createProjectFolder } from './files'; import { logger } from './logger'; import { Property, default as serverConfig } from './serverConfig'; import { uuid } from './uuid'; @@ -497,9 +497,12 @@ const postProjectName: Middleware = async( logger.debug('Adding new project'); const file: File = new File({ uuid: uuid.generate(), - mimetype: 'inode/directory' + mimetype: 'inode/directory', + name: req.params.project_name, + parentFolderId: rootPathId }); promise = file.save(); + createProjectFolder(req.params.project_name); project = new Project({ name: req.params.project_name, rootFolder: file @@ -575,7 +578,6 @@ const postFilePath: Middleware = ( name: res.locals.filename, parentFolder: res.locals.parentFolder }); - //console.log(res.locals); req.pipe(files.writableStream(file.uuid, res.locals.project.name)); next(); }; @@ -677,11 +679,12 @@ export class FileRouter { req: Request, res: Response, next: NextFunction, filename: string ): Promise => { - console.log(`parsing path ${filename}`) + filename = filename.replace(/\+/g, "/"); // Replace + with / logger.debug(`Searching for file ${filename}`); const fileNames: string[] = req.params.path.split('/'); const project: Project | null = res.locals.project; if (project == null) { + // Project should have been found by previous precondition logger.debug('Project was not found: skipping finding file'); return next(new RequestError(404, 'project_not_found')); } @@ -696,15 +699,21 @@ export class FileRouter { } }); if (fileOrNull == null) { + console.log("fileOrNull was null") return next(); } else { + console.log("^^") + console.log(file) file = fileOrNull; } fileNames.splice(0, 1); } + if (file == null) { + console.log("file was null") return next(); } + console.log(file) const parentFolder: File | null = await File.findOne({ include: [ { model: File, as: 'containedFilesInternal'} @@ -714,7 +723,8 @@ export class FileRouter { name: fileNames[0] } }); - //console.log(parentFolder); + console.log("parent folder: ") + console.log(parentFolder); if (parentFolder == null) { return next(); } -- cgit v1.2.1 From c7874c8d2407fc7d046b6ba6856ebfdb46a30f37 Mon Sep 17 00:00:00 2001 From: jw255 Date: Mon, 16 Apr 2018 20:34:29 +0100 Subject: World War Files - ideas all there, but SQLize part still missing. --- src/FileRouter.ts | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) (limited to 'src/FileRouter.ts') diff --git a/src/FileRouter.ts b/src/FileRouter.ts index ca2ed50..df7ca94 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -8,7 +8,7 @@ import { default as UserGroup } from './db/model/UserGroup'; import { NextFunction, Request, Response, Router } from 'express'; import { RequestError } from './errors/errorware'; -import { View, files, views, rootPathId, createProjectFolder } from './files'; +import { addSubFileToFolder, View, files, views, rootPathId, createProjectFolder } from './files'; import { logger } from './logger'; import { Property, default as serverConfig } from './serverConfig'; import { uuid } from './uuid'; @@ -565,22 +565,56 @@ const getFileId: Middleware = getFile; /** * Post a File. / delete / move / etc */ -const postFilePath: Middleware = ( +/* tslint:disable */ +const postFilePath: Middleware = async( req: Request, res: Response, next: NextFunction -): void => { +): Promise => { logger.debug(`Receiving file to ${res.locals.parentFolder}`); - res.locals.modified = true; + if (res.locals.file != null) { next(new RequestError(400, 'file_exists')); } + + // lets have a res.locals.deepestFolderName (and Id) which is a string of the deepest parent folder found + let remainingPath: string = res.locals.path.split(res.locals.deepestFolderName)[1]; + console.log(`remainingPath: ${remainingPath}`) + + while((remainingPath.match(/\//g) || []).length > 1){ + // If there are more subfolders that dont exist, then create them + const subFolder: string = remainingPath.split("/")[1] + logger.debug(`Adding subfolder \'${subFolder}`); + const dir: File = new File({ + uuid: uuid.generate(), + mimetype: 'inode/directory', + name: subFolder, + parentFolderId: res.locals.deepestFolderId + }); + await dir.save(); + + // update parent directory of new directory + addSubFileToFolder(res.locals.deepestFolderId, dir.id); + + // update vars + remainingPath = remainingPath.split(subFolder)[1] + res.locals.deepestFolderName = subFolder; + res.locals.deepestFolderId = dir.id; + console.log(`\tremainingPath: ${remainingPath}`) + console.log(`\tdeepestFolderName: ${res.locals.deepestFolderName}`) + console.log(`\tdeepestFolderId: ${res.locals.deepestFolderId}`) + } + const file: File = new File({ uuid: uuid.generate(), name: res.locals.filename, - parentFolder: res.locals.parentFolder + parentFolder: res.locals.deepestFolderId }); + // update parent directory of new directory + addSubFileToFolder(res.locals.deepestFolderId, file.id); + // pipe the data req.pipe(files.writableStream(file.uuid, res.locals.project.name)); next(); }; +/* tslint:enable */ export class FileRouter { public router: Router; @@ -679,8 +713,14 @@ export class FileRouter { req: Request, res: Response, next: NextFunction, filename: string ): Promise => { - filename = filename.replace(/\+/g, "/"); // Replace + with / + // TODO \/ + // We need to find the res.locals.deepestFolderName (and Id) for the currently requested path + + // Replace + with / + filename = filename.replace(/\+/g, '/'); logger.debug(`Searching for file ${filename}`); + res.locals.path = filename; + const fileNames: string[] = req.params.path.split('/'); const project: Project | null = res.locals.project; if (project == null) { -- cgit v1.2.1 From 7905240ed1655f9db3f571976034e287d88e1315 Mon Sep 17 00:00:00 2001 From: jw255 Date: Tue, 17 Apr 2018 10:38:32 +0100 Subject: World War Files - changed precondition + filled addSubFileToFolder() function. Need to test tho --- src/FileRouter.ts | 79 +++++++++++++++++++++++++------------------------------ 1 file changed, 36 insertions(+), 43 deletions(-) (limited to 'src/FileRouter.ts') diff --git a/src/FileRouter.ts b/src/FileRouter.ts index df7ca94..4b56b19 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -13,9 +13,6 @@ import { logger } from './logger'; import { Property, default as serverConfig } from './serverConfig'; import { uuid } from './uuid'; -// TODO: figure this out -const BASE_FILE_STORAGE: string = 'TODO: figure this out'; - /** * The type of an Express middleware callback. */ @@ -540,7 +537,6 @@ const getFile: Middleware = async( req: Request, res: Response, next: NextFunction ): Promise => { logger.debug(`Getting file in ${req.query.view} view`); - res.locals.modified = true; const file: File | null = res.locals.file; if (file == null) { return next(new RequestError(404, 'file_not_found')); @@ -566,9 +562,7 @@ const getFileId: Middleware = getFile; * Post a File. / delete / move / etc */ /* tslint:disable */ -const postFilePath: Middleware = async( - req: Request, res: Response, next: NextFunction -): Promise => { +const postFilePath: Middleware = async(req: Request, res: Response, next: NextFunction): Promise => { logger.debug(`Receiving file to ${res.locals.parentFolder}`); if (res.locals.file != null) { @@ -579,6 +573,7 @@ const postFilePath: Middleware = async( let remainingPath: string = res.locals.path.split(res.locals.deepestFolderName)[1]; console.log(`remainingPath: ${remainingPath}`) + // Loop the part of the path that doesn't exist yet and create all the folders while((remainingPath.match(/\//g) || []).length > 1){ // If there are more subfolders that dont exist, then create them const subFolder: string = remainingPath.split("/")[1] @@ -610,6 +605,8 @@ const postFilePath: Middleware = async( }); // update parent directory of new directory addSubFileToFolder(res.locals.deepestFolderId, file.id); + + // TODO respond to correct query params (like update metadata, move, etc) // pipe the data req.pipe(files.writableStream(file.uuid, res.locals.project.name)); next(); @@ -721,59 +718,49 @@ export class FileRouter { logger.debug(`Searching for file ${filename}`); res.locals.path = filename; + // split path into parts const fileNames: string[] = req.params.path.split('/'); + res.locals.filename = fileNames[-1]; const project: Project | null = res.locals.project; if (project == null) { // Project should have been found by previous precondition logger.debug('Project was not found: skipping finding file'); return next(new RequestError(404, 'project_not_found')); } - let file: File = project.rootFolder; - // TODO Rewrite using sub-queries instead of repeated queries. - while (fileNames.length > 2) { + console.debug(fileNames); + + let curDir: File | null = project.rootFolder; + res.locals.deepestFolderId = curDir.id; + res.locals.deepestFolderName = curDir.name; + let i: number = 0; + + // Loop through the path and find the deepest folder that exists. Also find the file if possible. + while (curDir && i < fileNames.length) { const fileOrNull: File | null = await File.findOne({ include: [{all: true}], where: { - name: fileNames[0], - parentFolder: file + name: fileNames[i], + parentFolder: curDir } }); if (fileOrNull == null) { - console.log("fileOrNull was null") + console.log("next subdir not found in DB"); return next(); - } else { - console.log("^^") - console.log(file) - file = fileOrNull; + } + + if(i < fileNames.length-1){ + // Found next subdirectory + console.log(`found subdir ${fileOrNull.name}`); + res.locals.deepestFolderId = fileOrNull.id; + res.locals.deepestFolderName = fileOrNull.name; + }else{ + // Found actual file + console.log(`found file ${fileOrNull.name}`); + res.locals.file = fileOrNull; } - fileNames.splice(0, 1); + curDir = fileOrNull; } - if (file == null) { - console.log("file was null") - return next(); - } - console.log(file) - const parentFolder: File | null = await File.findOne({ - include: [ - { model: File, as: 'containedFilesInternal'} - ], - where: { - parentFolderId: file.id, - name: fileNames[0] - } - }); - console.log("parent folder: ") - console.log(parentFolder); - if (parentFolder == null) { - return next(); - } - res.locals.parentFolder = parentFolder; - const tFile: File | undefined = parentFolder.containedFiles.find( - (f: File): boolean => f.name === fileNames[1] - ); - res.locals.file = tFile; - res.locals.filename = fileNames[1]; next(); } ); @@ -793,6 +780,12 @@ export class FileRouter { } }); res.locals.file = file; + if(file) { + res.locals.filename = file.name; + res.locals.deepestFolderId = file.parentFolderId; + if(file.parentFolder) res.locals.deepestFolderName = file.parentFolder.name; + else console.log("parentfolder not set!") + } next(); } ); -- cgit v1.2.1