From 4cf1536d5fe157a22b802fc0ad1dcf8049494d33 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sat, 1 Dec 2018 23:53:58 +0100 Subject: [PATCH] fixing random photo bug --- backend/middlewares/GalleryMWs.ts | 6 +++--- backend/model/sql/GalleryManager.ts | 14 ++++++++++---- backend/routes/GalleryRouter.ts | 13 ++++++------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/backend/middlewares/GalleryMWs.ts b/backend/middlewares/GalleryMWs.ts index 5ae1eb4d..1834925f 100644 --- a/backend/middlewares/GalleryMWs.ts +++ b/backend/middlewares/GalleryMWs.ts @@ -145,17 +145,17 @@ export class GalleryMWs { } req.params.mediaPath = path.join(photo.directory.path, photo.directory.name, photo.name); + return next(); } catch (e) { return next(new ErrorDTO(ErrorCodes.GENERAL_ERROR, 'Can\'t get random photo: ' + e.toString())); } - return next(); } public static loadFile(req: Request, res: Response, next: NextFunction) { - if (!(req.params.filePath)) { + if (!(req.params.mediaPath)) { return next(); } - const fullMediaPath = path.join(ProjectPath.ImageFolder, req.params.filePath); + const fullMediaPath = path.join(ProjectPath.ImageFolder, req.params.mediaPath); // check if thumbnail already exist if (fs.existsSync(fullMediaPath) === false) { diff --git a/backend/model/sql/GalleryManager.ts b/backend/model/sql/GalleryManager.ts index c0d0c8cf..2485c4f7 100644 --- a/backend/model/sql/GalleryManager.ts +++ b/backend/model/sql/GalleryManager.ts @@ -19,11 +19,12 @@ import {MediaDTO} from '../../../common/entities/MediaDTO'; import {VideoEntity} from './enitites/VideoEntity'; import {FileEntity} from './enitites/FileEntity'; import {FileDTO} from '../../../common/entities/FileDTO'; +import {NotificationManager} from '../NotifocationManager'; export class GalleryManager implements IGalleryManager, ISQLGalleryManager { protected async selectParentDir(connection: Connection, directoryName: string, directoryParent: string): Promise { - return await connection + const query = connection .getRepository(DirectoryEntity) .createQueryBuilder('directory') .where('directory.name = :name AND directory.path = :path', { @@ -31,9 +32,13 @@ export class GalleryManager implements IGalleryManager, ISQLGalleryManager { path: directoryParent }) .leftJoinAndSelect('directory.directories', 'directories') - .leftJoinAndSelect('directory.media', 'media') - .leftJoinAndSelect('directory.metaFile', 'metaFile') - .getOne(); + .leftJoinAndSelect('directory.media', 'media'); + + if (Config.Client.MetaFile.enabled == true) { + query.leftJoinAndSelect('directory.metaFile', 'metaFile'); + } + + return await query.getOne(); } protected async fillParentDir(connection: Connection, dir: DirectoryEntity): Promise { @@ -133,6 +138,7 @@ export class GalleryManager implements IGalleryManager, ISQLGalleryManager { await this.saveToDB(scannedDirectory); } catch (error) { + NotificationManager.warning('Unknown indexing error', error.toString()); console.error(error); return reject(error); } diff --git a/backend/routes/GalleryRouter.ts b/backend/routes/GalleryRouter.ts index 6b112635..9e3b140f 100644 --- a/backend/routes/GalleryRouter.ts +++ b/backend/routes/GalleryRouter.ts @@ -36,7 +36,7 @@ export class GalleryRouter { private static addGetImage(app: Express) { - app.get(['/api/gallery/content/:filePath(*\.(jpg|bmp|png|gif|jpeg))'], + app.get(['/api/gallery/content/:mediaPath(*\.(jpg|bmp|png|gif|jpeg))'], AuthenticationMWs.authenticate, // TODO: authorize path GalleryMWs.loadFile, @@ -45,7 +45,7 @@ export class GalleryRouter { } private static addGetVideo(app: Express) { - app.get(['/api/gallery/content/:filePath(*\.(mp4|ogg|ogv|webm))'], + app.get(['/api/gallery/content/:mediaPath(*\.(mp4|ogg|ogv|webm))'], AuthenticationMWs.authenticate, // TODO: authorize path GalleryMWs.loadFile, @@ -54,7 +54,7 @@ export class GalleryRouter { } private static addGetMetaFile(app: Express) { - app.get(['/api/gallery/content/:filePath(*\.(gpx))'], + app.get(['/api/gallery/content/:mediaPath(*\.(gpx))'], AuthenticationMWs.authenticate, // TODO: authorize path GalleryMWs.loadFile, @@ -65,7 +65,6 @@ export class GalleryRouter { private static addRandom(app: Express) { app.get(['/api/gallery/random'], AuthenticationMWs.authenticate, - AuthenticationMWs.authorise(UserRoles.Guest), // TODO: authorize path GalleryMWs.getRandomImage, GalleryMWs.loadFile, @@ -74,7 +73,7 @@ export class GalleryRouter { } private static addGetImageThumbnail(app: Express) { - app.get('/api/gallery/content/:filePath(*\.(jpg|bmp|png|gif|jpeg))/thumbnail/:size?', + app.get('/api/gallery/content/:mediaPath(*\.(jpg|bmp|png|gif|jpeg))/thumbnail/:size?', AuthenticationMWs.authenticate, // TODO: authorize path GalleryMWs.loadFile, @@ -84,7 +83,7 @@ export class GalleryRouter { } private static addGetVideoThumbnail(app: Express) { - app.get('/api/gallery/content/:filePath(*\.(mp4|ogg|ogv|webm))/thumbnail/:size?', + app.get('/api/gallery/content/:mediaPath(*\.(mp4|ogg|ogv|webm))/thumbnail/:size?', AuthenticationMWs.authenticate, // TODO: authorize path GalleryMWs.loadFile, @@ -94,7 +93,7 @@ export class GalleryRouter { } private static addGetImageIcon(app: Express) { - app.get('/api/gallery/content/:filePath(*\.(jpg|bmp|png|gif|jpeg))/icon', + app.get('/api/gallery/content/:mediaPath(*\.(jpg|bmp|png|gif|jpeg))/icon', AuthenticationMWs.authenticate, // TODO: authorize path GalleryMWs.loadFile,