fix(scanner): fallback to original filename when title is missing in patterns

The default upload file naming patterns for single file and folder per book previously relied exclusively on the title. If multiple files lacked a title, they would map to the same path. This changes the default patterns to fall back to the original filename if the title is missing, preventing files without metadata from clumping.

Closes #308
This commit is contained in:
neon
2026-06-12 05:27:59 +00:00
parent 280aad0712
commit b81ba163ce
2 changed files with 29 additions and 2 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
export const DEFAULT_UPLOAD_PATTERN_BOOK_PER_FILE = "<{authors:first}|Unknown Author>/<{series}/><{seriesIndex}. >{title}< ({year})>";
export const DEFAULT_UPLOAD_PATTERN_BOOK_PER_FILE = "<{authors:first}|Unknown Author>/<{series}/><{seriesIndex}. ><{title}|{originalFilename}>< ({year})>";
export const DEFAULT_UPLOAD_PATTERN_BOOK_PER_FOLDER =
"<{authors:first}|Unknown Author>/<{series}/><{seriesIndex}. >{title}< ({year})>/<{seriesIndex}. >{title}< ({year})>";
"<{authors:first}|Unknown Author>/<{series}/><{seriesIndex}. ><{title}|{originalFilename}>< ({year})>/<{seriesIndex}. ><{title}|{originalFilename}>< ({year})>";
export const DEFAULT_DOWNLOAD_PATTERN = "{originalFilename}";
export const EXAMPLE_PATTERN_METADATA: Record<string, string> = {
@@ -2,6 +2,7 @@ import {
applyModifier,
DEFAULT_DOWNLOAD_PATTERN,
DEFAULT_UPLOAD_PATTERN_BOOK_PER_FILE,
DEFAULT_UPLOAD_PATTERN_BOOK_PER_FOLDER,
EXAMPLE_PATTERN_METADATA,
replacePlaceholders,
resolveDownloadFilename,
@@ -549,6 +550,12 @@ describe('DEFAULT_UPLOAD_PATTERN_BOOK_PER_FILE', () => {
expect(resolveUploadPath(P, { title: 'Untitled', originalFilename: 'untitled', extension: 'epub' }, 'epub')).toBe('Unknown Author/Untitled.epub');
});
it('no title: falls back to original filename', () => {
expect(resolveUploadPath(P, { authors: '', title: '', originalFilename: 'original-stem', extension: 'epub' }, 'epub')).toBe(
'Unknown Author/original-stem.epub',
);
});
it('multiple authors: uses only the first', () => {
expect(resolveUploadPath(P, MULTI_AUTHOR, 'epub')).toBe('Bruce Sterling/Sprawl/01. Neuromancer (1984).epub');
});
@@ -569,3 +576,23 @@ describe('DEFAULT_UPLOAD_PATTERN_BOOK_PER_FILE', () => {
expect(validatePattern(P)).toBe(true);
});
});
// ── DEFAULT_UPLOAD_PATTERN_BOOK_PER_FOLDER integration ───────────────────────
describe('DEFAULT_UPLOAD_PATTERN_BOOK_PER_FOLDER', () => {
const P = DEFAULT_UPLOAD_PATTERN_BOOK_PER_FOLDER;
it('full metadata: author / series / index. title (year) / index. title (year)', () => {
expect(resolveUploadPath(P, FULL, 'epub')).toBe('William Gibson/Sprawl/01. Neuromancer (1984)/01. Neuromancer (1984).epub');
});
it('no title: falls back to original filename in folder and file segments', () => {
expect(resolveUploadPath(P, { authors: '', title: '', originalFilename: 'original-stem', extension: 'epub' }, 'epub')).toBe(
'Unknown Author/original-stem/original-stem.epub',
);
});
it('passes validatePattern', () => {
expect(validatePattern(P)).toBe(true);
});
});