diff --git a/src/common/entities/ContentWrapper.ts b/src/common/entities/ContentWrapper.ts index 761feb55..2c0bb8d9 100644 --- a/src/common/entities/ContentWrapper.ts +++ b/src/common/entities/ContentWrapper.ts @@ -565,7 +565,7 @@ export class ContentWrapper { lens: new Map(), camera: new Map(), directories: new Map() }; - if (cw.directory) { + if (cw?.directory) { ContentWrapper.packDirectory(cw, cw.directory); } else if (cw.searchResult) { ContentWrapper.packDirectory(cw, cw.searchResult, true); @@ -589,7 +589,7 @@ export class ContentWrapper { if (!cw || cw.notModified) { return cw; } - if (cw.directory) { + if (cw?.directory) { ContentWrapper.unPackDirectory(cw, cw.directory); } else if (cw.searchResult) { ContentWrapper.unPackDirectory(cw, cw.searchResult, true); diff --git a/src/frontend/app/ui/gallery/cache.gallery.service.ts b/src/frontend/app/ui/gallery/cache.gallery.service.ts index 94b33f38..cca01358 100644 --- a/src/frontend/app/ui/gallery/cache.gallery.service.ts +++ b/src/frontend/app/ui/gallery/cache.gallery.service.ts @@ -314,8 +314,8 @@ export class GalleryCacheService { const key = GalleryCacheService.CONTENT_PREFIX + - Utils.concatUrls(cw.directory.path, cw.directory.name); - if (cw.directory.isPartial === true && localStorage.getItem(key)) { + Utils.concatUrls(cw?.directory.path, cw?.directory.name); + if (cw?.directory?.isPartial === true && localStorage.getItem(key)) { return; } diff --git a/src/frontend/app/ui/gallery/contentLoader.service.ts b/src/frontend/app/ui/gallery/contentLoader.service.ts index 986644d0..2384ff92 100644 --- a/src/frontend/app/ui/gallery/contentLoader.service.ts +++ b/src/frontend/app/ui/gallery/contentLoader.service.ts @@ -34,7 +34,7 @@ export class ContentLoaderService { new ContentWrapperWithError() ); this.originalContent = this.content.pipe( - map((c) => (c.directory ? c.directory : c.searchResult)) + map((c) => (c?.directory ? c?.directory : c?.searchResult)) ); } @@ -64,15 +64,15 @@ export class ContentLoaderService { if ( !forceReload && - cw.directory && - cw.directory.lastModified && - cw.directory.lastScanned && - !cw.directory.isPartial + cw?.directory && + cw?.directory.lastModified && + cw?.directory.lastScanned && + !cw?.directory.isPartial ) { params[QueryParams.gallery.knownLastModified] = - cw.directory.lastModified; + cw?.directory.lastModified; params[QueryParams.gallery.knownLastScanned] = - cw.directory.lastScanned; + cw?.directory.lastScanned; } try { diff --git a/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.ts b/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.ts index d86524b5..4ec737ed 100644 --- a/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.ts +++ b/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.ts @@ -93,18 +93,18 @@ export class GalleryNavigatorComponent { this.routes = this.contentLoaderService.content.pipe( map((c) => { this.parentPath = null; - if (!c.directory && !this.isExactDirectorySearch(c)) { + if (!c?.directory && !this.isExactDirectorySearch(c)) { return []; } let path: string; let name: string; - if (c.directory) { + if (c?.directory) { path = c.directory.path; name = c.directory.name; } else { // Handle exact directory search - const searchQuery = c.searchResult.searchQuery as TextSearch; + const searchQuery = c?.searchResult.searchQuery as TextSearch; path = searchQuery.text.replace(/^\.\//, ''); // Remove leading ./ if present const lastSlashIndex = path.lastIndexOf('/'); if (lastSlashIndex !== -1) { @@ -265,7 +265,7 @@ export class GalleryNavigatorComponent { searchQuery = { type: SearchQueryTypes.directory, matchType: TextSearchQueryMatchTypes.exact_match, - text: Utils.concatUrls('./', c.directory.path, c.directory.name) + text: Utils.concatUrls('./', c?.directory.path, c?.directory.name) } as TextSearch; } else { return null; @@ -293,7 +293,7 @@ export class GalleryNavigatorComponent { return JSON.stringify({ type: SearchQueryTypes.directory, matchType: TextSearchQueryMatchTypes.like, - text: Utils.concatUrls('./', c.directory.path, c.directory.name), + text: Utils.concatUrls('./', c?.directory.path, c?.directory.name), } as TextSearch); } diff --git a/src/frontend/app/ui/gallery/random-query-builder/random-query-builder.gallery.component.ts b/src/frontend/app/ui/gallery/random-query-builder/random-query-builder.gallery.component.ts index aeaa5e46..5dd96001 100644 --- a/src/frontend/app/ui/gallery/random-query-builder/random-query-builder.gallery.component.ts +++ b/src/frontend/app/ui/gallery/random-query-builder/random-query-builder.gallery.component.ts @@ -73,7 +73,7 @@ export class RandomQueryBuilderGalleryComponent implements OnInit, OnDestroy { ngOnInit(): void { this.contentSubscription = this.contentLoaderService.content.subscribe( (content: ContentWrapper) => { - this.enabled = !!content.directory; + this.enabled = !!content?.directory; if (!this.enabled) { return; } diff --git a/src/frontend/app/ui/gallery/share/share.gallery.component.ts b/src/frontend/app/ui/gallery/share/share.gallery.component.ts index 49a0dc76..4055c83b 100644 --- a/src/frontend/app/ui/gallery/share/share.gallery.component.ts +++ b/src/frontend/app/ui/gallery/share/share.gallery.component.ts @@ -86,23 +86,23 @@ export class GalleryShareComponent implements OnInit, OnDestroy { this.contentSubscription = this.galleryService.content.subscribe( async (content: ContentWrapper) => { this.activeShares = []; - this.enabled = !!(content.directory || (content as any).searchResult); + this.enabled = !!(content?.directory || (content as any)?.searchResult); this.currentDir = ''; this.currentQuery = null; this.sharingTarget = ''; this.currentMediaCount = 0; this.currentMediaCountIsLowerBound = false; - if ((content as any).searchResult) { + if ((content as any)?.searchResult) { const sr = (content as any).searchResult; this.currentQuery = sr.searchQuery as SearchQueryDTO; this.sharingTarget = $localize`Search query`; this.currentMediaCount = (sr.media ? sr.media.length : 0); this.currentMediaCountIsLowerBound = !!sr.resultOverflow; - } else if (content.directory) { + } else if (content?.directory) { this.currentDir = Utils.concatUrls( - content.directory.path, - content.directory.name + content?.directory.path, + content?.directory.name ); this.currentQuery = { type: SearchQueryTypes.directory, @@ -111,7 +111,7 @@ export class GalleryShareComponent implements OnInit, OnDestroy { } as TextSearch; this.sharingTarget = this.currentDir; // Prefer mediaCount, fallback to media length if needed - this.currentMediaCount = (typeof content.directory.cache?.mediaCount === 'number' ? content.directory.cache?.mediaCount : (content.directory.media ? content.directory.media.length : 0)); + this.currentMediaCount = (typeof content?.directory.cache?.mediaCount === 'number' ? content.directory.cache?.mediaCount : (content.directory.media ? content.directory.media.length : 0)); this.currentMediaCountIsLowerBound = false; } diff --git a/test/common/unit/ContentWrapper.spec.ts b/test/common/unit/ContentWrapper.spec.ts index 9130bbec..2ecb9f2e 100644 --- a/test/common/unit/ContentWrapper.spec.ts +++ b/test/common/unit/ContentWrapper.spec.ts @@ -17,7 +17,7 @@ describe('ContentWrapper', () => { delete cw.notModified; } - const content = (cw.directory ? cw.directory : cw.searchResult); + const content = (cw?.directory ? cw.directory : cw?.searchResult); for (let i = 0; i < content.media.length; ++i) { const m = content.media[i]; if (MediaDTOUtils.isPhoto(m)) {