1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-11-27 22:38:10 +02:00

Fix when contentWrapper is null

fixes #924
This commit is contained in:
Patrik J. Braun
2025-09-29 23:12:55 +02:00
parent 690cd78926
commit c1a77b5eea
7 changed files with 24 additions and 24 deletions

View File

@@ -565,7 +565,7 @@ export class ContentWrapper {
lens: new Map(), camera: new Map(), directories: new Map() lens: new Map(), camera: new Map(), directories: new Map()
}; };
if (cw.directory) { if (cw?.directory) {
ContentWrapper.packDirectory(cw, cw.directory); ContentWrapper.packDirectory(cw, cw.directory);
} else if (cw.searchResult) { } else if (cw.searchResult) {
ContentWrapper.packDirectory(cw, cw.searchResult, true); ContentWrapper.packDirectory(cw, cw.searchResult, true);
@@ -589,7 +589,7 @@ export class ContentWrapper {
if (!cw || cw.notModified) { if (!cw || cw.notModified) {
return cw; return cw;
} }
if (cw.directory) { if (cw?.directory) {
ContentWrapper.unPackDirectory(cw, cw.directory); ContentWrapper.unPackDirectory(cw, cw.directory);
} else if (cw.searchResult) { } else if (cw.searchResult) {
ContentWrapper.unPackDirectory(cw, cw.searchResult, true); ContentWrapper.unPackDirectory(cw, cw.searchResult, true);

View File

@@ -314,8 +314,8 @@ export class GalleryCacheService {
const key = const key =
GalleryCacheService.CONTENT_PREFIX + GalleryCacheService.CONTENT_PREFIX +
Utils.concatUrls(cw.directory.path, cw.directory.name); Utils.concatUrls(cw?.directory.path, cw?.directory.name);
if (cw.directory.isPartial === true && localStorage.getItem(key)) { if (cw?.directory?.isPartial === true && localStorage.getItem(key)) {
return; return;
} }

View File

@@ -34,7 +34,7 @@ export class ContentLoaderService {
new ContentWrapperWithError() new ContentWrapperWithError()
); );
this.originalContent = this.content.pipe( 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 ( if (
!forceReload && !forceReload &&
cw.directory && cw?.directory &&
cw.directory.lastModified && cw?.directory.lastModified &&
cw.directory.lastScanned && cw?.directory.lastScanned &&
!cw.directory.isPartial !cw?.directory.isPartial
) { ) {
params[QueryParams.gallery.knownLastModified] = params[QueryParams.gallery.knownLastModified] =
cw.directory.lastModified; cw?.directory.lastModified;
params[QueryParams.gallery.knownLastScanned] = params[QueryParams.gallery.knownLastScanned] =
cw.directory.lastScanned; cw?.directory.lastScanned;
} }
try { try {

View File

@@ -93,18 +93,18 @@ export class GalleryNavigatorComponent {
this.routes = this.contentLoaderService.content.pipe( this.routes = this.contentLoaderService.content.pipe(
map((c) => { map((c) => {
this.parentPath = null; this.parentPath = null;
if (!c.directory && !this.isExactDirectorySearch(c)) { if (!c?.directory && !this.isExactDirectorySearch(c)) {
return []; return [];
} }
let path: string; let path: string;
let name: string; let name: string;
if (c.directory) { if (c?.directory) {
path = c.directory.path; path = c.directory.path;
name = c.directory.name; name = c.directory.name;
} else { } else {
// Handle exact directory search // 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 path = searchQuery.text.replace(/^\.\//, ''); // Remove leading ./ if present
const lastSlashIndex = path.lastIndexOf('/'); const lastSlashIndex = path.lastIndexOf('/');
if (lastSlashIndex !== -1) { if (lastSlashIndex !== -1) {
@@ -265,7 +265,7 @@ export class GalleryNavigatorComponent {
searchQuery = { searchQuery = {
type: SearchQueryTypes.directory, type: SearchQueryTypes.directory,
matchType: TextSearchQueryMatchTypes.exact_match, matchType: TextSearchQueryMatchTypes.exact_match,
text: Utils.concatUrls('./', c.directory.path, c.directory.name) text: Utils.concatUrls('./', c?.directory.path, c?.directory.name)
} as TextSearch; } as TextSearch;
} else { } else {
return null; return null;
@@ -293,7 +293,7 @@ export class GalleryNavigatorComponent {
return JSON.stringify({ return JSON.stringify({
type: SearchQueryTypes.directory, type: SearchQueryTypes.directory,
matchType: TextSearchQueryMatchTypes.like, matchType: TextSearchQueryMatchTypes.like,
text: Utils.concatUrls('./', c.directory.path, c.directory.name), text: Utils.concatUrls('./', c?.directory.path, c?.directory.name),
} as TextSearch); } as TextSearch);
} }

View File

@@ -73,7 +73,7 @@ export class RandomQueryBuilderGalleryComponent implements OnInit, OnDestroy {
ngOnInit(): void { ngOnInit(): void {
this.contentSubscription = this.contentLoaderService.content.subscribe( this.contentSubscription = this.contentLoaderService.content.subscribe(
(content: ContentWrapper) => { (content: ContentWrapper) => {
this.enabled = !!content.directory; this.enabled = !!content?.directory;
if (!this.enabled) { if (!this.enabled) {
return; return;
} }

View File

@@ -86,23 +86,23 @@ export class GalleryShareComponent implements OnInit, OnDestroy {
this.contentSubscription = this.galleryService.content.subscribe( this.contentSubscription = this.galleryService.content.subscribe(
async (content: ContentWrapper) => { async (content: ContentWrapper) => {
this.activeShares = []; this.activeShares = [];
this.enabled = !!(content.directory || (content as any).searchResult); this.enabled = !!(content?.directory || (content as any)?.searchResult);
this.currentDir = ''; this.currentDir = '';
this.currentQuery = null; this.currentQuery = null;
this.sharingTarget = ''; this.sharingTarget = '';
this.currentMediaCount = 0; this.currentMediaCount = 0;
this.currentMediaCountIsLowerBound = false; this.currentMediaCountIsLowerBound = false;
if ((content as any).searchResult) { if ((content as any)?.searchResult) {
const sr = (content as any).searchResult; const sr = (content as any).searchResult;
this.currentQuery = sr.searchQuery as SearchQueryDTO; this.currentQuery = sr.searchQuery as SearchQueryDTO;
this.sharingTarget = $localize`Search query`; this.sharingTarget = $localize`Search query`;
this.currentMediaCount = (sr.media ? sr.media.length : 0); this.currentMediaCount = (sr.media ? sr.media.length : 0);
this.currentMediaCountIsLowerBound = !!sr.resultOverflow; this.currentMediaCountIsLowerBound = !!sr.resultOverflow;
} else if (content.directory) { } else if (content?.directory) {
this.currentDir = Utils.concatUrls( this.currentDir = Utils.concatUrls(
content.directory.path, content?.directory.path,
content.directory.name content?.directory.name
); );
this.currentQuery = { this.currentQuery = {
type: SearchQueryTypes.directory, type: SearchQueryTypes.directory,
@@ -111,7 +111,7 @@ export class GalleryShareComponent implements OnInit, OnDestroy {
} as TextSearch; } as TextSearch;
this.sharingTarget = this.currentDir; this.sharingTarget = this.currentDir;
// Prefer mediaCount, fallback to media length if needed // 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; this.currentMediaCountIsLowerBound = false;
} }

View File

@@ -17,7 +17,7 @@ describe('ContentWrapper', () => {
delete cw.notModified; 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) { for (let i = 0; i < content.media.length; ++i) {
const m = content.media[i]; const m = content.media[i];
if (MediaDTOUtils.isPhoto(m)) { if (MediaDTOUtils.isPhoto(m)) {