From 6d613aa6f3133d339fe7251b2efe18ed47cdd4be Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sat, 26 May 2018 21:44:32 -0400 Subject: [PATCH] handling broken directory path --- backend/middlewares/GalleryMWs.ts | 3 +- frontend/app/gallery/gallery.component.ts | 2 +- frontend/app/gallery/gallery.service.ts | 35 ++++++++++++----------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/backend/middlewares/GalleryMWs.ts b/backend/middlewares/GalleryMWs.ts index cda96758..6e767440 100644 --- a/backend/middlewares/GalleryMWs.ts +++ b/backend/middlewares/GalleryMWs.ts @@ -21,7 +21,8 @@ export class GalleryMWs { const directoryName = req.params.directory || '/'; const absoluteDirectoryName = path.join(ProjectPath.ImageFolder, directoryName); - if (!fs.statSync(absoluteDirectoryName).isDirectory()) { + if (!fs.existsSync(absoluteDirectoryName) || + !fs.statSync(absoluteDirectoryName).isDirectory()) { return next(); } diff --git a/frontend/app/gallery/gallery.component.ts b/frontend/app/gallery/gallery.component.ts index 66199675..dc704ea9 100644 --- a/frontend/app/gallery/gallery.component.ts +++ b/frontend/app/gallery/gallery.component.ts @@ -92,7 +92,7 @@ export class GalleryComponent implements OnInit, OnDestroy { let directoryName = params['directory']; directoryName = directoryName || ''; - this._galleryService.getDirectory(directoryName); + this._galleryService.loadDirectory(directoryName); }; diff --git a/frontend/app/gallery/gallery.service.ts b/frontend/app/gallery/gallery.service.ts index 8127b28c..ee375d21 100644 --- a/frontend/app/gallery/gallery.service.ts +++ b/frontend/app/gallery/gallery.service.ts @@ -8,6 +8,7 @@ import {BehaviorSubject} from 'rxjs'; import {SharingDTO} from '../../../common/entities/SharingDTO'; import {Config} from '../../../common/config/public/Config'; import {ShareService} from './share.service'; +import {NavigationService} from '../model/navigation.service'; @Injectable() export class GalleryService { @@ -18,7 +19,8 @@ export class GalleryService { constructor(private networkService: NetworkService, private galleryCacheService: GalleryCacheService, - private _shareService: ShareService) { + private _shareService: ShareService, + private navigatoinService: NavigationService) { this.content = new BehaviorSubject(new ContentWrapper()); } @@ -26,7 +28,7 @@ export class GalleryService { directory: null }; - public async getDirectory(directoryName: string): Promise { + public loadDirectory(directoryName: string): void { const content = new ContentWrapper(); content.directory = this.galleryCacheService.getDirectory(directoryName); @@ -49,29 +51,30 @@ export class GalleryService { } - const cw = await this.networkService.getJson('/gallery/content/' + directoryName, params); + this.networkService.getJson('/gallery/content/' + directoryName, params).then((cw) => { - if (!cw || cw.notModified === true) { - return; - } + if (!cw || cw.notModified === true) { + return; + } - this.galleryCacheService.setDirectory(cw.directory); // save it before adding references + this.galleryCacheService.setDirectory(cw.directory); // save it before adding references - if (this.lastRequest.directory !== directoryName) { - return; - } + if (this.lastRequest.directory !== directoryName) { + return; + } - DirectoryDTO.addReferences(cw.directory); + DirectoryDTO.addReferences(cw.directory); - this.lastDirectory = cw.directory; - this.content.next(cw); + this.lastDirectory = cw.directory; + this.content.next(cw); - return cw; - + }).catch(() => { + this.navigatoinService.toGallery(); + }); } public async search(text: string, type?: SearchTypes): Promise { @@ -105,7 +108,7 @@ export class GalleryService { clearTimeout(this.searchId); } if (!this.lastDirectory) { - this.getDirectory('/'); + this.loadDirectory('/'); } return null; }