Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/backend/model/database/IndexingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,9 @@ export class IndexingManager {
if (entities.length === 0) {
return [];
}
// Clean NaN values before saving to prevent database write failures
// NaN can appear in EXIF metadata (e.g., malformed GPS coordinates)
entities.forEach(e => Utils.cleanNaN(e));
if (entities.length < size) {
return await repository.save(entities);
}
Expand Down
34 changes: 34 additions & 0 deletions src/common/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,19 @@ export class Utils {
return curr;
}

/**
* Returns the first element in the sorted array that is >= num.
* If all elements are smaller than num, returns the largest element.
*/
public static findCeilinginSorted(num: number, arr: number[]): number {
for (const item of arr) {
if (item >= num) {
return item;
}
}
return arr[arr.length - 1];
}

public static asciiToUTF8(text: string): string {
if (text) {
// Check for corrupted IPTC data - very long strings with binary content indicate corruption
Expand Down Expand Up @@ -575,6 +588,27 @@ export class Utils {
.filter(s => s && s.length > 0)
.join(',');
}

/**
* Recursively cleans NaN values from an object, replacing them with null.
* Catches both number NaN and string "NaN" values that can appear in EXIF metadata.
* This prevents database write failures when NaN values are present.
*/
public static cleanNaN(obj: unknown): void {
if (obj !== null && typeof obj === 'object') {
for (const key of Object.keys(obj as Record<string, unknown>)) {
const val = (obj as Record<string, unknown>)[key];
if (val !== null && typeof val === 'object') {
Utils.cleanNaN(val);
} else if (typeof val === 'number' && isNaN(val)) {
(obj as Record<string, unknown>)[key] = null;
} else if (typeof val === 'string' && val === 'NaN') {
(obj as Record<string, unknown>)[key] = null;
}
}
}
}

}

export class LRU<V> {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/app/ui/gallery/MediaIcon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class MediaIcon {

getMediaSize(renderWidth: number, renderHeight: number): number {
const longerEdge = Math.max(renderWidth, renderHeight);
return Utils.findClosestinSorted(longerEdge, MediaIcon.sortedThumbnailSizes);
return Utils.findCeilinginSorted(longerEdge, MediaIcon.sortedThumbnailSizes);
}

/**
Expand Down
Loading