Support File Move Operations with Watcher Refactor for Accurate Tracking
This commit is contained in:
committed by
Aditya Chandel
parent
1c9c09628a
commit
841e359b92
@@ -6,6 +6,8 @@ import {MetadataFetchOptionsComponent} from '../../metadata/metadata-options-dia
|
||||
import {MetadataRefreshType} from '../../metadata/model/request/metadata-refresh-type.enum';
|
||||
import {BulkMetadataUpdateComponent} from '../../metadata/bulk-metadata-update-component/bulk-metadata-update-component';
|
||||
import {MultiBookMetadataEditorComponent} from '../../metadata/multi-book-metadata-editor-component/multi-book-metadata-editor-component';
|
||||
import {FileMoverComponent} from '../../../file-mover-component/file-mover-component';
|
||||
import {count} from 'rxjs';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class BookDialogHelperService {
|
||||
@@ -87,4 +89,22 @@ export class BookDialogHelperService {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openFileMoverDialog(selectedBooks: Set<number>) {
|
||||
const count = selectedBooks.size;
|
||||
return this.dialogService.open(FileMoverComponent, {
|
||||
header: `Relocate Book Files (${count} book${count !== 1 ? 's' : ''})`,
|
||||
showHeader: true,
|
||||
modal: true,
|
||||
closable: true,
|
||||
closeOnEscape: false,
|
||||
dismissableMask: false,
|
||||
style: {
|
||||
width: '90vw'
|
||||
},
|
||||
data: {
|
||||
bookIds: selectedBooks
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,6 +259,14 @@
|
||||
pTooltip="Lock/Unlock metadata"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
<p-button
|
||||
outlined="true"
|
||||
icon="pi pi-arrows-h"
|
||||
severity="info"
|
||||
(click)="moveFiles()"
|
||||
pTooltip="Move Books"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
.book-browser-footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 25%;
|
||||
right: 25%;
|
||||
left: 10%;
|
||||
right: 10%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 1rem 0.5rem 0.5rem;
|
||||
|
||||
@@ -670,4 +670,8 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
multiBookEditMetadata(): void {
|
||||
this.dialogHelperService.openMultibookMetadataEditerDialog(this.selectedBooks);
|
||||
}
|
||||
|
||||
moveFiles() {
|
||||
this.dialogHelperService.openFileMoverDialog(this.selectedBooks);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
</p-tab>
|
||||
}
|
||||
</p-tablist>
|
||||
<p-tabpanels class="overflow-auto" style="height: calc(100vh - 10rem);">
|
||||
<p-tabpanels class="overflow-auto" style="height: calc(100vh - 9.7rem);">
|
||||
<p-tabpanel value="view">
|
||||
<app-metadata-viewer [book$]="book$" [recommendedBooks]="recommendedBooks"></app-metadata-viewer>
|
||||
</p-tabpanel>
|
||||
|
||||
-1
@@ -371,7 +371,6 @@
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p-divider></p-divider>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -15,10 +15,13 @@ export interface Book {
|
||||
pdfProgress?: PdfProgress;
|
||||
cbxProgress?: CbxProgress;
|
||||
filePath?: string;
|
||||
fileSubPath?: string;
|
||||
fileName?: string;
|
||||
fileSizeKb?: number;
|
||||
seriesCount?: number | null;
|
||||
metadataMatchScore?: number | null;
|
||||
readStatus?: ReadStatus;
|
||||
libraryPath?: { id: number };
|
||||
}
|
||||
|
||||
export interface EpubProgress {
|
||||
|
||||
@@ -420,9 +420,9 @@ export class BookService {
|
||||
|
||||
handleBookUpdate(updatedBook: Book) {
|
||||
const currentState = this.bookStateSubject.value;
|
||||
const updatedBooks = (currentState.books || []).map(book => {
|
||||
return book.id == updatedBook.id ? {...book, metadata: updatedBook.metadata} : book
|
||||
});
|
||||
const updatedBooks = (currentState.books || []).map(book =>
|
||||
book.id === updatedBook.id ? updatedBook : book
|
||||
);
|
||||
this.bookStateSubject.next({...currentState, books: updatedBooks});
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,11 @@ export class LibraryShelfMenuService {
|
||||
header: 'Confirmation',
|
||||
rejectButtonProps: {
|
||||
label: 'Cancel',
|
||||
severity: 'secondary',
|
||||
},
|
||||
acceptButtonProps: {
|
||||
label: 'Yes',
|
||||
severity: 'success',
|
||||
},
|
||||
accept: () => {
|
||||
this.libraryService.deleteLibrary(entity?.id!).subscribe({
|
||||
@@ -84,6 +89,11 @@ export class LibraryShelfMenuService {
|
||||
header: 'Confirmation',
|
||||
rejectButtonProps: {
|
||||
label: 'Cancel',
|
||||
severity: 'secondary',
|
||||
},
|
||||
acceptButtonProps: {
|
||||
label: 'Yes',
|
||||
severity: 'success',
|
||||
},
|
||||
accept: () => {
|
||||
this.libraryService.refreshLibrary(entity?.id!).subscribe({
|
||||
|
||||
@@ -120,7 +120,16 @@ export class LibraryService {
|
||||
return this.libraryStateSubject.value.libraries || [];
|
||||
}
|
||||
|
||||
getAllLibrariesFromAPI(): Observable<Library[]> {
|
||||
return this.http.get <Library[]>(`${this.url}`);
|
||||
getLibraryPathById(pathId: number): string | undefined {
|
||||
const libraries = this.libraryStateSubject.value.libraries || [];
|
||||
|
||||
for (const library of libraries) {
|
||||
const match = library.paths.find(p => p.id === pathId);
|
||||
if (match) {
|
||||
return match.path;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ export interface AppSettings {
|
||||
metadataRefreshOptions: MetadataRefreshOptions;
|
||||
coverResolution: string;
|
||||
uploadPattern: string;
|
||||
movePattern: string;
|
||||
opdsServerEnabled: boolean;
|
||||
remoteAuthEnabled: boolean;
|
||||
oidcEnabled: boolean;
|
||||
@@ -106,5 +107,6 @@ export enum AppSettingKey {
|
||||
METADATA_PROVIDER_SETTINGS = 'METADATA_PROVIDER_SETTINGS',
|
||||
METADATA_MATCH_WEIGHTS = 'METADATA_MATCH_WEIGHTS',
|
||||
METADATA_PERSISTENCE_SETTINGS = 'METADATA_PERSISTENCE_SETTINGS',
|
||||
MOVE_FILE_PATTERN = 'MOVE_FILE_PATTERN',
|
||||
BOOK_DELETION_ENABLED = 'BOOK_DELETION_ENABLED'
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
<div class="w-full h-[calc(100vh-12.1rem)] overflow-y-auto border rounded-lg enclosing-container">
|
||||
<div class="w-full h-[calc(100vh-11.65rem)] overflow-y-auto border rounded-lg enclosing-container">
|
||||
|
||||
<div class="p-4">
|
||||
<p class="text-lg gap-2 pb-4 pt-4">Internal Authentication:</p>
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
<div class="p-fluid px-4 py-2 rounded-xl flex flex-col h-[800px]">
|
||||
|
||||
<div class="px-4 mx-2 mb-4 py-3 rounded-lg border border-[var(--border-color)] transition-all">
|
||||
<p class="text-[var(--primary-color)] font-semibold mb-1">
|
||||
Customize Your File Organization
|
||||
</p>
|
||||
<p class="text-sm text-gray-300 leading-relaxed">
|
||||
Define a naming pattern to reorganize selected book files on your system. Use dynamic placeholders like
|
||||
<code class="bg-gray-800 px-1 py-0.5 rounded text-[var(--primary-color)] font-mono text-xs">{{ '{title}' }}</code>
|
||||
or
|
||||
<code class="bg-gray-800 px-1 py-0.5 rounded text-[var(--primary-color)] font-mono text-xs">{{ '{authors}' }}</code>
|
||||
to automatically insert metadata. <br>
|
||||
A preview below shows how files will be renamed and moved.
|
||||
Once you're satisfied, click <span class="font-semibold text-green-400">Apply</span> to proceed.
|
||||
<span class="text-yellow-500 font-medium flex items-center gap-2">
|
||||
<i class="pi pi-exclamation-triangle text-yellow-400"></i>
|
||||
Files will be physically moved on your system when you apply changes.
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="mb-2 px-1 text-sm text-muted">
|
||||
<p-button
|
||||
size="small"
|
||||
text
|
||||
severity="info"
|
||||
(click)="placeholdersVisible = !placeholdersVisible">
|
||||
{{ placeholdersVisible ? 'Hide' : 'Show' }} available placeholders
|
||||
</p-button>
|
||||
|
||||
@if (placeholdersVisible) {
|
||||
<div class="mx-4 my-2 flex flex-wrap gap-4">
|
||||
<ul class="list-disc pl-4 min-w-[250px]">
|
||||
<li><code>{{ '{title}' }}</code> - Book title</li>
|
||||
<li><code>{{ '{authors}' }}</code> - Author(s)</li>
|
||||
<li><code>{{ '{year}' }}</code> - Full year (e.g. 2025)</li>
|
||||
<li><code>{{ '{series}' }}</code> - Series name</li>
|
||||
<li><code>{{ '{seriesIndex}' }}</code> - Series index (e.g. 01)</li>
|
||||
<li><code>{{ '{language}' }}</code> - Language (e.g. en)</li>
|
||||
<li><code>{{ '{publisher}' }}</code> - Publisher</li>
|
||||
<li><code>{{ '{isbn}' }}</code> - ISBN</li>
|
||||
<li><code>{{ '{currentFilename}' }}</code> - Original file name (with extension)</li>
|
||||
</ul>
|
||||
|
||||
<p-divider layout="vertical"></p-divider>
|
||||
|
||||
<div class="text-sm p-3 min-w-[250px]">
|
||||
<p class="mb-1 font-medium">Tip: Optional placeholders</p>
|
||||
<p>Wrap parts of your pattern in angle brackets <code>{{ '<...>' }}</code> to make them optional.</p>
|
||||
<p>If any placeholder inside has no value, the whole block is removed.</p>
|
||||
<p class="mt-1 font-semibold">Example:</p>
|
||||
<p><code>{{ '<{seriesIndex} - >{title}' }}</code></p>
|
||||
<p class="pl-4 mt-1">• <code>{{ '01 - Dune' }}</code> (if <code>{{ '{seriesIndex}' }}</code> is present)</p>
|
||||
<p class="pl-4">• <code>{{ 'Dune' }}</code> (if <code>{{ '{seriesIndex}' }}</code> is missing)</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="flex gap-2 mb-4 px-2 items-center w-full">
|
||||
<input
|
||||
type="text"
|
||||
pInputText
|
||||
[(ngModel)]="movePattern"
|
||||
(ngModelChange)="applyPattern()"
|
||||
[placeholder]="movePattern.trim() ? '' : getDefaultPattern()"
|
||||
class="flex-1"
|
||||
/>
|
||||
|
||||
<p-button
|
||||
icon="pi pi-save"
|
||||
label="Make Default"
|
||||
severity="info"
|
||||
outlined
|
||||
(click)="setDefaultPattern()"
|
||||
></p-button>
|
||||
</div>
|
||||
|
||||
<div class="flex-grow overflow-y-auto mt-4">
|
||||
<p-table
|
||||
[value]="filePreviews"
|
||||
[responsiveLayout]="'scroll'"
|
||||
class="block min-w-full"
|
||||
>
|
||||
<ng-template pTemplate="header">
|
||||
<tr>
|
||||
<th style="width: 0.5rem; text-align: center;">ID</th>
|
||||
<th>Current Path</th>
|
||||
<th></th>
|
||||
<th>New Path</th>
|
||||
</tr>
|
||||
</ng-template>
|
||||
<ng-template pTemplate="body" let-preview let-i="rowIndex">
|
||||
<tr>
|
||||
<td class="text-center">{{ preview.bookId }}</td>
|
||||
<td class="w-auto">
|
||||
<p>
|
||||
<span class="text-gray-400 select-none">{{ preview.libraryPathPrefix }}/</span><span>{{ preview.relativeOriginalPath }}</span>
|
||||
</p>
|
||||
</td>
|
||||
<td class="w-auto text-[var(--primary-color)] text-center">→</td>
|
||||
<td class="w-auto">
|
||||
<p>
|
||||
<span class="text-gray-400 select-none">{{ preview.libraryPathPrefix }}/</span><span>{{ preview.relativeNewPath }}</span>
|
||||
</p>
|
||||
</td>
|
||||
<td class="w-auto text-center">
|
||||
@if (preview.isMoved) {
|
||||
<i class="pi pi-check-circle text-green-600"></i>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
</p-table>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="flex justify-end items-center gap-4 flex-shrink-0 px-4">
|
||||
@if (movedFileCount > 0) {
|
||||
<span class="text-green-500 flex items-center font-semibold drop-shadow-sm select-none">
|
||||
{{ movedFileCount }} file{{ movedFileCount > 1 ? 's' : '' }} successfully moved
|
||||
<i
|
||||
class="pi pi-check-circle ml-2 text-green-500 animate-bounce"
|
||||
style="animation-duration: 1.5s;"
|
||||
aria-label="Success"
|
||||
role="img"
|
||||
></i>
|
||||
</span>
|
||||
}
|
||||
@if (movedFileCount === 0) {
|
||||
<p-button
|
||||
[label]="loading ? 'Moving...' : 'Move Files'"
|
||||
[icon]="loading ? 'pi pi-spin pi-spinner' : 'pi pi-arrows-h'"
|
||||
severity="success"
|
||||
(click)="saveChanges()"
|
||||
[disabled]="loading || filePreviews.length === 0"
|
||||
></p-button>
|
||||
<p-button
|
||||
label="Cancel"
|
||||
icon="pi pi-times"
|
||||
severity="danger"
|
||||
(click)="cancel()"
|
||||
></p-button>
|
||||
} @else {
|
||||
<p-button
|
||||
label="Close"
|
||||
icon="pi pi-times"
|
||||
severity="success"
|
||||
(click)="cancel()"
|
||||
></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,3 @@
|
||||
:host ::ng-deep .p-datatable-tbody > tr > td {
|
||||
padding: 0.5rem 1rem !important;
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
import {Component, inject} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {TableModule} from 'primeng/table';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {filter, take} from 'rxjs/operators';
|
||||
|
||||
import {BookService} from '../book/service/book.service';
|
||||
import {Book} from '../book/model/book.model';
|
||||
import {FileMoveRequest, FileOperationsService} from '../file-operations-service';
|
||||
import {LibraryService} from "../book/service/library.service";
|
||||
import {AppSettingsService} from '../core/service/app-settings.service';
|
||||
import {AppSettingKey} from '../core/model/app-settings.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-file-mover-component',
|
||||
standalone: true,
|
||||
imports: [Button, FormsModule, TableModule, InputText, Divider],
|
||||
templateUrl: './file-mover-component.html',
|
||||
styleUrl: './file-mover-component.scss'
|
||||
})
|
||||
export class FileMoverComponent {
|
||||
private config = inject(DynamicDialogConfig);
|
||||
private ref = inject(DynamicDialogRef);
|
||||
private bookService = inject(BookService);
|
||||
private libraryService = inject(LibraryService);
|
||||
private fileOperationsService = inject(FileOperationsService);
|
||||
private messageService = inject(MessageService);
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
|
||||
movePattern = '';
|
||||
placeholdersVisible = false;
|
||||
loading = false;
|
||||
|
||||
bookIds: Set<number> = new Set();
|
||||
books: Book[] = [];
|
||||
filePreviews: { originalPath: string; newPath: string; isMoved?: boolean }[] = [];
|
||||
|
||||
constructor() {
|
||||
this.bookIds = new Set(this.config.data?.bookIds ?? []);
|
||||
this.books = this.bookService.getBooksByIdsFromState([...this.bookIds]);
|
||||
|
||||
this.appSettingsService.appSettings$.pipe(
|
||||
filter(settings => settings != null),
|
||||
take(1)
|
||||
).subscribe(settings => {
|
||||
this.movePattern = settings?.movePattern;
|
||||
this.applyPattern();
|
||||
});
|
||||
}
|
||||
|
||||
applyPattern(): void {
|
||||
this.filePreviews = this.books.map(book => {
|
||||
const meta = book.metadata!;
|
||||
const fileName = book.fileName ?? '';
|
||||
const extension = fileName.match(/\.[^.]+$/)?.[0] ?? '';
|
||||
const fileSubPath = book.fileSubPath ? `${book.fileSubPath.replace(/\/+$/g, '')}/` : '';
|
||||
|
||||
const relativeOriginalPath = `${fileSubPath}${fileName}`;
|
||||
const libraryPathPrefix =
|
||||
book.libraryPath?.id != null
|
||||
? this.libraryService.getLibraryPathById(book.libraryPath.id)?.replace(/\/+$/g, '') ?? ''
|
||||
: '';
|
||||
const originalPath = `${libraryPathPrefix}/${relativeOriginalPath}`.replace(/\/\/+/g, '/');
|
||||
|
||||
const values: Record<string, string> = {
|
||||
authors: this.sanitize(meta.authors?.join(', ') || 'Unknown Author'),
|
||||
title: this.sanitize(meta.title || 'Untitled'),
|
||||
year: this.formatYear(meta.publishedDate),
|
||||
series: this.sanitize(meta.seriesName || ''),
|
||||
seriesIndex: this.formatSeriesIndex(meta.seriesNumber ?? undefined),
|
||||
language: this.sanitize(meta.language || ''),
|
||||
publisher: this.sanitize(meta.publisher || ''),
|
||||
isbn: this.sanitize(meta.isbn13 || meta.isbn10 || ''),
|
||||
currentFilename: this.sanitize(fileName)
|
||||
};
|
||||
|
||||
let newPath: string;
|
||||
|
||||
if (!this.movePattern?.trim()) {
|
||||
// If pattern empty, just use current filename as the new path
|
||||
newPath = `${fileSubPath}${fileName}`; // preserve subpath + filename
|
||||
} else {
|
||||
newPath = this.movePattern.replace(/<([^<>]+)>/g, (_, block) => {
|
||||
const placeholders = [...block.matchAll(/{(.*?)}/g)].map(m => m[1]);
|
||||
const allHaveValues = placeholders.every(key => values[key]?.trim());
|
||||
return allHaveValues
|
||||
? block.replace(/{(.*?)}/g, (_: string, key: string) => values[key] ?? '')
|
||||
: '';
|
||||
});
|
||||
|
||||
newPath = newPath.replace(/{(.*?)}/g, (_, key) => values[key] ?? '');
|
||||
|
||||
// Append extension if not already present (most patterns won't include extension)
|
||||
if (!newPath.endsWith(extension)) {
|
||||
newPath += extension;
|
||||
}
|
||||
}
|
||||
|
||||
const relativeNewPath = newPath;
|
||||
const fullNewPath = `${libraryPathPrefix}/${relativeNewPath}`.replace(/\/\/+/g, '/');
|
||||
|
||||
return {
|
||||
bookId: book.id,
|
||||
originalPath,
|
||||
relativeOriginalPath,
|
||||
libraryPathPrefix,
|
||||
newPath: fullNewPath,
|
||||
relativeNewPath
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
get movedFileCount(): number {
|
||||
return this.filePreviews.filter(p => p.isMoved).length;
|
||||
}
|
||||
|
||||
sanitize(input: string | undefined): string {
|
||||
return input?.replace(/[\\/:*?"<>|]/g, '')
|
||||
.replace(/[\x00-\x1F\x7F]/g, '')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim() ?? '';
|
||||
}
|
||||
|
||||
formatYear(dateStr?: string): string {
|
||||
if (!dateStr) return '';
|
||||
const date = new Date(dateStr);
|
||||
return isNaN(date.getTime()) ? '' : date.getFullYear().toString();
|
||||
}
|
||||
|
||||
formatSeriesIndex(seriesNumber?: number): string {
|
||||
if (seriesNumber == null) return '';
|
||||
return this.sanitize(seriesNumber.toString());
|
||||
}
|
||||
|
||||
getDefaultPattern(): string {
|
||||
return 'e.g. {authors}/<{series}/><{seriesIndex}. >{title} - {authors}< ({year})>';
|
||||
}
|
||||
|
||||
saveChanges(): void {
|
||||
if (!this.movePattern?.trim()) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Missing Pattern',
|
||||
detail: 'Move pattern cannot be empty. Please enter a valid pattern.',
|
||||
life: 3000
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.loading = true;
|
||||
const request: FileMoveRequest = {
|
||||
bookIds: [...this.bookIds],
|
||||
pattern: this.movePattern
|
||||
};
|
||||
|
||||
this.fileOperationsService.moveFiles(request).subscribe({
|
||||
next: () => {
|
||||
this.loading = false;
|
||||
this.filePreviews.forEach(p => (p.isMoved = true));
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Files Moved',
|
||||
detail: `${this.filePreviews.length} file(s) successfully relocated.`,
|
||||
life: 3000
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.loading = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Move Failed',
|
||||
detail: 'An error occurred while moving the files.',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setDefaultPattern(): void {
|
||||
const trimmedPattern = this.movePattern?.trim();
|
||||
|
||||
if (!trimmedPattern) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Cannot Save',
|
||||
detail: 'Move pattern cannot be empty.'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = [
|
||||
{
|
||||
key: AppSettingKey.MOVE_FILE_PATTERN,
|
||||
newValue: trimmedPattern
|
||||
}
|
||||
];
|
||||
|
||||
this.appSettingsService.saveSettings(payload).subscribe({
|
||||
next: () => this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Saved',
|
||||
detail: 'Move pattern saved as default.'
|
||||
}),
|
||||
error: () => this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to save default move pattern.'
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
cancel(): void {
|
||||
this.ref.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from './config/api-config';
|
||||
|
||||
export interface FileMoveRequest {
|
||||
bookIds: number[];
|
||||
pattern: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class FileOperationsService {
|
||||
private readonly baseUrl = `${API_CONFIG.BASE_URL}/api/v1/files`;
|
||||
|
||||
private http = inject(HttpClient);
|
||||
|
||||
moveFiles(request: FileMoveRequest): Observable<void> {
|
||||
return this.http.post<void>(`${this.baseUrl}/move`, request);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="w-full h-[calc(100vh-12.1rem)] overflow-y-auto border rounded-lg p-4 enclosing-container">
|
||||
<div class="w-full h-[calc(100vh-11.65rem)] overflow-y-auto border rounded-lg p-4 enclosing-container">
|
||||
<div class="pt-2">
|
||||
<app-email-provider></app-email-provider>
|
||||
</div>
|
||||
|
||||
+222
-72
@@ -1,85 +1,235 @@
|
||||
<p class="text-lg ">
|
||||
Uploaded Files Pattern
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Define a naming pattern for future uploads using available metadata. Existing files will remain unchanged."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
<p class="text-lg flex items-center gap-2">
|
||||
File Naming Patterns
|
||||
<i
|
||||
class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Define custom naming patterns for uploaded files and for moving files within your library. Use metadata placeholders to automate organization."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</p>
|
||||
|
||||
<div class="flex flex-col space-y-6 p-4 m-4 custom-border">
|
||||
|
||||
<div>
|
||||
<h2 class="mb-3 text-lg">Enter Custom File Naming Pattern:</h2>
|
||||
<h2 class="mb-3 text-lg">Enter Upload File Naming Pattern:</h2>
|
||||
<p class="mb-3 text-sm text-gray-400">
|
||||
Define how newly uploaded files are named and organized using book metadata.
|
||||
</p>
|
||||
<div class="flex gap-4 items-center">
|
||||
<input
|
||||
type="text"
|
||||
[(ngModel)]="uploadPattern"
|
||||
class="p-inputtext w-[500px]"
|
||||
placeholder="e.g., {title} - {authors}"
|
||||
(input)="onPatternChange(uploadPattern)"
|
||||
/>
|
||||
<p-button
|
||||
label="Save"
|
||||
(onClick)="savePattern()"
|
||||
severity="primary"
|
||||
outlined="true"
|
||||
[disabled]="!!errorMessage">
|
||||
</p-button>
|
||||
<input type="text" [(ngModel)]="uploadPattern" class="p-inputtext w-[700px]" placeholder="e.g., {title} - {authors}" (input)="onUploadPatternChange(uploadPattern)"/>
|
||||
<p-button label="Save" (onClick)="savePatterns()" severity="primary" outlined="true" [disabled]="!!uploadErrorMessage || !!moveErrorMessage"></p-button>
|
||||
</div>
|
||||
@if (uploadErrorMessage) {
|
||||
<div class="text-red-500 mt-1">{{ uploadErrorMessage }}</div>
|
||||
}
|
||||
|
||||
<h3 class="mt-4 mb-2">Upload Pattern Preview:</h3>
|
||||
<p class="text-lg text-green-500">{{ generateUploadPreview() }}</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h3 class="mb-2">Preview:</h3>
|
||||
<p class="text-lg text-green-500">{{ generatePreview() }}</p>
|
||||
</div>
|
||||
|
||||
<div class="text-gray-400">
|
||||
<h3 class="mb-1 ">Example Patterns:</h3>
|
||||
<div class="overflow-x-auto">
|
||||
<table class=" table-auto">
|
||||
<colgroup>
|
||||
<col style="width: auto;"/>
|
||||
<col style="width: 20px;"/>
|
||||
<col/>
|
||||
</colgroup>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="pr-2 break-words text-left">{title} - {authors}/filename.pdf</td>
|
||||
<td class="text-gray-300 text-center">→</td>
|
||||
<td class="pl-2 break-words text-left">/The Book Thief - Markus Zusak/filename.pdf</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="pr-2 break-words text-left">{title}/{authors}/filename.pdf</td>
|
||||
<td class="text-gray-300 text-center">→</td>
|
||||
<td class="pl-2 break-words text-left">/The Book Thief/Markus Zusak/filename.pdf</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="pr-2 break-words text-left">{title} ({authors})/filename.pdf</td>
|
||||
<td class="text-gray-300 text-center">→</td>
|
||||
<td class="pl-2 break-words text-left">/The Book Thief (Markus Zusak)/filename.pdf</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="pr-2 break-words text-left">{title}/filename.pdf</td>
|
||||
<td class="text-gray-300 text-center">→</td>
|
||||
<td class="pl-2 break-words text-left">/The Book Thief/filename.pdf</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="pr-2 break-words text-left">EMPTY</td>
|
||||
<td class="text-gray-300 text-center">→</td>
|
||||
<td class="pl-2 break-words text-left">/filename.pdf</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h2 class="mb-3 text-lg">Enter File Move Naming Pattern:</h2>
|
||||
<p class="mb-3 text-sm text-gray-400">
|
||||
Specify how book files should be renamed and relocated using metadata such as title, authors, or series. This pattern is applied when using the Move Files feature.
|
||||
</p>
|
||||
<div class="flex gap-4 items-center">
|
||||
<input type="text" [(ngModel)]="movePattern" class="p-inputtext w-[700px]" placeholder="e.g., {authors}/<{series}/><{seriesIndex}. >{title} - {authors}< ({year})>.pdf"
|
||||
(input)="onMovePatternChange(movePattern)"/>
|
||||
<p-button label="Save" (onClick)="savePatterns()" severity="primary" outlined="true" [disabled]="!!uploadErrorMessage || !!moveErrorMessage"></p-button>
|
||||
</div>
|
||||
@if (moveErrorMessage) {
|
||||
<div class="text-red-500 mt-1">{{ moveErrorMessage }}</div>
|
||||
}
|
||||
|
||||
<h3 class="mt-4 mb-2">Move Pattern Preview:</h3>
|
||||
<p class="text-lg text-green-500">{{ generateMovePreview() }}</p>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<p class="pt-4">Available Placeholders:</p>
|
||||
|
||||
<p class="text-sm text-gray-400 mb-2 mt-2">
|
||||
Use placeholders to dynamically insert book metadata into file names and folder paths. These will be replaced with actual values when uploading or moving files.
|
||||
You can also wrap parts of the pattern in <code>{{ '{{<...>}' }}</code> to make them optional, if any placeholder inside is missing, that section will be omitted entirely.
|
||||
</p>
|
||||
|
||||
<div class="mt-2">
|
||||
<div class="mx-4 my-2 flex flex-wrap gap-4">
|
||||
<ul class="list-disc pl-4 min-w-[250px] text-gray-300">
|
||||
<li><code class="text-orange-400">{{ '{title}' }}</code> – Book title</li>
|
||||
<li><code class="text-orange-400">{{ '{authors}' }}</code> – Author(s)</li>
|
||||
<li><code class="text-orange-400">{{ '{year}' }}</code> – Full year (e.g. 2025)</li>
|
||||
<li><code class="text-orange-400">{{ '{series}' }}</code> – Series name</li>
|
||||
<li><code class="text-orange-400">{{ '{seriesIndex}' }}</code> – Series index (e.g. 01)</li>
|
||||
<li><code class="text-orange-400">{{ '{language}' }}</code> – Language code (e.g. en)</li>
|
||||
<li><code class="text-orange-400">{{ '{publisher}' }}</code> – Publisher name</li>
|
||||
<li><code class="text-orange-400">{{ '{isbn}' }}</code> – ISBN number</li>
|
||||
<li><code class="text-orange-400">{{ '{currentFilename}' }}</code> Original file name (with extension)</li>
|
||||
</ul>
|
||||
|
||||
<p-divider layout="vertical"></p-divider>
|
||||
|
||||
<div class="text-sm p-3 min-w-[250px]">
|
||||
<p class="mb-1 font-bold text-gray-200 text">Optional blocks</p>
|
||||
<p class="text-gray-300">
|
||||
Surround parts of your pattern with angle brackets
|
||||
<code class="text-blue-400">{{ '{<...>}' }}</code>
|
||||
to make them optional. <br> If any placeholder inside the block has no value, the whole block is excluded.
|
||||
</p>
|
||||
<p class="mt-2 font-semibold text-gray-300">Example:</p>
|
||||
<p><code>{{ '{<{seriesIndex} - >{title}' }}</code></p>
|
||||
<p class="pl-4 mt-1 text-gray-300">• <code>01 - Dune</code> (if <code>{{ '{seriesIndex}' }}</code> exists)</p>
|
||||
<p class="pl-4 text-gray-300">• <code>Dune</code> (if <code>{{ '{seriesIndex}' }}</code> is missing)</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="mt-6">
|
||||
<p class="mb-4">Example Patterns & Output:</p>
|
||||
|
||||
<div class="px-4 text-sm space-y-4">
|
||||
<p class="text-base font-semibold text-gray-200 mt-6 mb-2">Examples with Full Metadata</p>
|
||||
<p class="text-gray-400 mb-4">
|
||||
<span class="block">title: <code>Harry Potter and the Sorcerer's Stone</code></span>
|
||||
<span class="block">authors: <code>J.K. Rowling</code></span>
|
||||
<span class="block">series: <code>Harry Potter</code></span>
|
||||
<span class="block">seriesIndex: <code>01</code></span>
|
||||
<span class="block">year: <code>1997</code></span>
|
||||
<span class="block">currentFilename: <code>harry1_original.epub</code></span>
|
||||
</p>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Basic pattern:</strong><code class="text-gray-400"> {{ '{authors} - {title}' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> J.K. Rowling - Harry Potter and the Sorcerer's Stone.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Pattern with punctuation:</strong><code class="text-gray-400"> {{ '{title}: {series}' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> Harry Potter and the Sorcerer's Stone: Harry Potter.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Series in folder path:</strong><code class="text-gray-400"> {{ '{authors}/{series}/{seriesIndex} - {title}' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> J.K. Rowling/Harry Potter/01 - Harry Potter and the Sorcerer's Stone.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Folder only:</strong><code class="text-gray-400"> {{ '{title}/' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> /Harry Potter and the Sorcerer's Stone/harry1_original.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Absolute path:</strong><code class="text-gray-400"> {{ '/{authors}/{title}' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> /J.K. Rowling/Harry Potter and the Sorcerer's Stone.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Reuse original filename in path:</strong><code class="text-gray-400"> {{ '{authors}/{series}/{currentFilename}' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> J.K. Rowling/Harry Potter/harry1_original.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Preserve original filename only:</strong><code class="text-gray-400"> {{ '{currentFilename}' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> harry1_original.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Empty pattern (defaults to current filename):</strong><code class="text-gray-400"> {{ '' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> harry1_original.epub</code></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="px-4 text-sm space-y-4 mt-10">
|
||||
<p class="text-base font-semibold text-gray-200 mb-2">Examples with Missing Optional Fields</p>
|
||||
<p class="text-gray-400 mb-4">
|
||||
<span class="block">title: <code>Project Hail Mary</code></span>
|
||||
<span class="block">authors: <code>Andy Weir</code></span>
|
||||
<span class="block">year: <code>2021</code></span>
|
||||
<span class="block">series: <code>(not provided)</code></span>
|
||||
<span class="block">seriesIndex: <code>(not provided)</code></span>
|
||||
<span class="block">currentFilename: <code>project_hail_mary_final.epub</code></span>
|
||||
</p>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Pattern with optional blocks:</strong><code
|
||||
class="text-gray-400"> {{ '{authors}/<{series}/><{seriesIndex}. >{title}< ({year})>' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> Andy Weir/Project Hail Mary (2021).epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Fallback with seriesIndex and dash:</strong><code
|
||||
class="text-gray-400"> {{ '<{seriesIndex}. >{title}< - {authors}>' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> Project Hail Mary - Andy Weir.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Brackets & punctuation fallback:</strong><code class="text-gray-400"> {{ '<[{series}] >{title} - {authors}' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> Project Hail Mary - Andy Weir.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Series + punctuation fallback:</strong><code class="text-gray-400"> {{ '<{series}: >{title} by {authors}' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> Project Hail Mary by Andy Weir.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Only folders, no filename:</strong><code class="text-gray-400"> {{ '{authors}/' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> Andy Weir/project_hail_mary_final.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Deep nested folders:</strong><code class="text-gray-400"> {{ '{authors}/books/<{series}/>{title}/' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> Andy Weir/books/Project Hail Mary/project_hail_mary_final.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">With static folder prefix:</strong><code class="text-gray-400"> {{ 'Books/<{series}/>{authors} - {title}' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> Books/Andy Weir - Project Hail Mary.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Use original filename in path:</strong><code
|
||||
class="text-gray-400"> {{ '{authors}/books/<{series}/>{currentFilename}' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> Andy Weir/books/project_hail_mary_final.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Prefix current filename manually:</strong><code class="text-gray-400"> {{ '{authors}/final__{currentFilename}' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> Andy Weir/final__project_hail_mary_final.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Filename preserved, renamed folder:</strong><code class="text-gray-400"> {{ '{title}/source/{currentFilename}' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> Project Hail Mary/source/project_hail_mary_final.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Use current filename with year suffix:</strong><code
|
||||
class="text-gray-400"> {{ '{authors}/{year}__{currentFilename}' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> Andy Weir/2021__project_hail_mary_final.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Fallback with optional + extras folder:</strong><code
|
||||
class="text-gray-400"> {{ '<{series}/>{authors}/extras/{currentFilename}' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> Andy Weir/extras/project_hail_mary_final.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Archive structure using original name:</strong><code
|
||||
class="text-gray-400"> {{ 'archive/<{series}/>{year}/{currentFilename}' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> archive/2021/project_hail_mary_final.epub</code></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-1"><strong class="text-gray-300">Structured folder + renamed file:</strong><code
|
||||
class="text-gray-400"> {{ '{authors}/<{series}/>{title} ({year}) by {authors}' }}</code></p>
|
||||
<p><strong class="text-gray-300">Output:</strong><code class="text-gray-400"> Andy Weir/Project Hail Mary (2021) by Andy Weir.epub</code></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text text-gray-400">
|
||||
<strong>Note:</strong>
|
||||
<ul class="list-disc pl-6">
|
||||
<li>Only the placeholders {title} and {authors} are supported. These values will be extracted from the metadata of the uploaded PDF or EPUB file.</li>
|
||||
<li>Multiple authors will be joined using commas.</li>
|
||||
<li>If <code>{title}</code> is used but is missing in uploaded book's metadata, the path will fall back to <code>/filename.pdf</code>.</li>
|
||||
<li>If <code>{authors}</code> is used but is missing in uploaded book's metadata, the path will fall back to <code>{title}/filename.pdf</code> if the title exists, otherwise <code>/filename.pdf</code>.
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+101
-32
@@ -4,22 +4,35 @@ import {Button} from 'primeng/button';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {AppSettingsService} from '../../../core/service/app-settings.service';
|
||||
import {Observable} from 'rxjs';
|
||||
import {AppSettings} from '../../../core/model/app-settings.model';
|
||||
import {AppSettingKey, AppSettings} from '../../../core/model/app-settings.model';
|
||||
import {filter, take} from 'rxjs/operators';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
|
||||
@Component({
|
||||
selector: 'app-file-upload-pattern',
|
||||
templateUrl: './file-upload-pattern.component.html',
|
||||
standalone: true,
|
||||
imports: [FormsModule, Button, Tooltip],
|
||||
styleUrls: ['./file-upload-pattern.component.scss']
|
||||
imports: [FormsModule, Button, Divider, Tooltip],
|
||||
styleUrls: ['./file-upload-pattern.component.scss'],
|
||||
})
|
||||
export class FileUploadPatternComponent implements OnInit {
|
||||
title: string = 'The Book Thief';
|
||||
authors: string = 'Markus Zusak';
|
||||
uploadPattern: string = '';
|
||||
errorMessage: string = '';
|
||||
readonly exampleMetadata: Record<string, string> = {
|
||||
title: 'The Fellowship of the Ring',
|
||||
authors: 'J.R.R. Tolkien',
|
||||
year: '1954',
|
||||
series: 'The Lord of the Rings',
|
||||
seriesIndex: '01',
|
||||
language: 'en',
|
||||
publisher: 'Allen & Unwin',
|
||||
isbn: '9780618574940',
|
||||
};
|
||||
|
||||
uploadPattern = '';
|
||||
movePattern = '';
|
||||
|
||||
uploadErrorMessage = '';
|
||||
moveErrorMessage = '';
|
||||
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private messageService = inject(MessageService);
|
||||
@@ -27,43 +40,99 @@ export class FileUploadPatternComponent implements OnInit {
|
||||
appSettings$: Observable<AppSettings | null> = this.appSettingsService.appSettings$;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.appSettings$.pipe(
|
||||
filter(settings => settings != null),
|
||||
take(1)
|
||||
).subscribe(settings => {
|
||||
this.uploadPattern = settings?.uploadPattern || '';
|
||||
this.appSettings$
|
||||
.pipe(filter((settings) => settings != null), take(1))
|
||||
.subscribe((settings) => {
|
||||
this.uploadPattern = settings?.uploadPattern ?? '';
|
||||
this.movePattern = settings?.movePattern ?? '';
|
||||
});
|
||||
}
|
||||
|
||||
private replacePlaceholders(pattern: string, values: Record<string, string>): string {
|
||||
pattern = pattern.replace(/<([^<>]+)>/g, (_, block) => {
|
||||
const placeholders = [...block.matchAll(/{(.*?)}/g)].map((m) => m[1]);
|
||||
const allHaveValues = placeholders.every((key) => values[key]?.trim());
|
||||
return allHaveValues
|
||||
? block.replace(/{(.*?)}/g, (_: string, key: string) => values[key] ?? '')
|
||||
: '';
|
||||
});
|
||||
return pattern.replace(/{(.*?)}/g, (_, key) => values[key] ?? '').trim();
|
||||
}
|
||||
|
||||
generatePreview(): string {
|
||||
let path = this.uploadPattern
|
||||
.replace('{title}', this.title)
|
||||
.replace('{authors}', this.authors)
|
||||
.replace(/\/+$/, '')
|
||||
.trim();
|
||||
|
||||
return path ? `/${path}/filename.pdf` : '/filename.pdf';
|
||||
private appendExtensionIfMissing(path: string, ext = '.pdf'): string {
|
||||
const lastSegment = path.split('/').pop() ?? '';
|
||||
const hasExtension = /\.[a-z0-9]{2,5}$/i.test(lastSegment);
|
||||
return hasExtension ? path : path + ext;
|
||||
}
|
||||
|
||||
validatePattern(pattern: string): void {
|
||||
const isValid = /^[\w\s\-{}\/().]*$/.test(pattern);
|
||||
this.errorMessage = isValid ? '' : 'Pattern contains invalid characters.';
|
||||
generateUploadPreview(): string {
|
||||
let path = this.replacePlaceholders(this.uploadPattern || '', this.exampleMetadata);
|
||||
|
||||
if (!path) return '/original_filename.pdf';
|
||||
|
||||
// If pattern ends with slash, append original filename
|
||||
if (path.endsWith('/')) {
|
||||
return path + 'original_filename.pdf';
|
||||
}
|
||||
|
||||
// Replace {originalFilename} placeholder if present
|
||||
if (path.includes('{originalFilename}')) {
|
||||
path = path.replace('{originalFilename}', 'original_filename.pdf');
|
||||
return path.startsWith('/') ? path : `/${path}`;
|
||||
}
|
||||
|
||||
path = this.appendExtensionIfMissing(path);
|
||||
return path.startsWith('/') ? path : `/${path}`;
|
||||
}
|
||||
|
||||
onPatternChange(pattern: string): void {
|
||||
generateMovePreview(): string {
|
||||
let path = this.replacePlaceholders(this.movePattern || '', this.exampleMetadata);
|
||||
|
||||
if (!path) return '/original_filename.pdf';
|
||||
|
||||
if (path.endsWith('/')) {
|
||||
return path + 'original_filename.pdf';
|
||||
}
|
||||
|
||||
if (path.includes('{originalFilename}')) {
|
||||
path = path.replace('{originalFilename}', 'original_filename.pdf');
|
||||
return path.startsWith('/') ? path : `/${path}`;
|
||||
}
|
||||
|
||||
path = this.appendExtensionIfMissing(path);
|
||||
return path.startsWith('/') ? path : `/${path}`;
|
||||
}
|
||||
|
||||
validatePattern(pattern: string): boolean {
|
||||
// Allow letters, numbers, whitespace, common punctuation and placeholders syntax
|
||||
const validPatternRegex = /^[\w\s\-{}\/().<>.,:'"]*$/;
|
||||
return validPatternRegex.test(pattern);
|
||||
}
|
||||
|
||||
onUploadPatternChange(pattern: string): void {
|
||||
this.uploadPattern = pattern;
|
||||
this.validatePattern(pattern);
|
||||
this.uploadErrorMessage = this.validatePattern(pattern) ? '' : 'Pattern contains invalid characters.';
|
||||
}
|
||||
|
||||
savePattern(): void {
|
||||
this.saveSetting('UPLOAD_FILE_PATTERN', this.uploadPattern);
|
||||
onMovePatternChange(pattern: string): void {
|
||||
this.movePattern = pattern;
|
||||
this.moveErrorMessage = this.validatePattern(pattern) ? '' : 'Pattern contains invalid characters.';
|
||||
}
|
||||
|
||||
private saveSetting(key: string, value: unknown): void {
|
||||
this.appSettingsService.saveSettings([{key, newValue: value}]).subscribe({
|
||||
next: () => this.showMessage('success', 'Settings Saved', 'The settings were successfully saved!'),
|
||||
error: () => this.showMessage('error', 'Error', 'There was an error saving the settings.')
|
||||
});
|
||||
savePatterns(): void {
|
||||
if (this.uploadErrorMessage || this.moveErrorMessage) {
|
||||
this.showMessage('error', 'Invalid Pattern', 'Please fix errors before saving.');
|
||||
return;
|
||||
}
|
||||
this.appSettingsService
|
||||
.saveSettings([
|
||||
{key: AppSettingKey.UPLOAD_FILE_PATTERN, newValue: this.uploadPattern},
|
||||
{key: AppSettingKey.MOVE_FILE_PATTERN, newValue: this.movePattern},
|
||||
])
|
||||
.subscribe({
|
||||
next: () => this.showMessage('success', 'Settings Saved', 'The patterns were successfully saved!'),
|
||||
error: () => this.showMessage('error', 'Error', 'There was an error saving the settings.'),
|
||||
});
|
||||
}
|
||||
|
||||
private showMessage(severity: 'success' | 'error', summary: string, detail: string): void {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="w-full h-[calc(100vh-12.1rem)] overflow-y-auto border rounded-lg enclosing-container">
|
||||
<div class="w-full h-[calc(100vh-11.65rem)] overflow-y-auto border rounded-lg enclosing-container">
|
||||
|
||||
<div class="p-4">
|
||||
<div class="px-4 pt-4 pb-2">
|
||||
<div class="flex items-center gap-2 pb-4 pt-4">
|
||||
<p class="text-lg ">Book Cover Image</p>
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
@@ -130,7 +130,7 @@
|
||||
<p-divider></p-divider>
|
||||
</div>
|
||||
|
||||
<div class="p-4">
|
||||
<div class="px-4 py-2">
|
||||
<app-opds-settings></app-opds-settings>
|
||||
</div>
|
||||
|
||||
@@ -138,7 +138,7 @@
|
||||
<p-divider></p-divider>
|
||||
</div>
|
||||
|
||||
<div class="p-4">
|
||||
<div class="px-4 py-2">
|
||||
<app-file-upload-pattern></app-file-upload-pattern>
|
||||
</div>
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
<p class="text-lg flex items-center gap-2">
|
||||
<p class="text-lg flex items-center gap-2">
|
||||
OPDS Server Settings
|
||||
<i
|
||||
class="pi pi-info-circle text-sky-600"
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
<div class="w-full h-[calc(100vh-12.1rem)] overflow-y-auto border rounded-lg enclosing-container">
|
||||
<div class="w-full h-[calc(100vh-11.65rem)] overflow-y-auto border rounded-lg enclosing-container">
|
||||
|
||||
<div class="p-4 pt-6">
|
||||
<p class="text-lg pb-4 pt-2">Metadata Persistence:</p>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="w-full h-[calc(100vh-12.1rem)] overflow-y-auto border rounded-lg enclosing-container">
|
||||
<div class="w-full h-[calc(100vh-11.65rem)] overflow-y-auto border rounded-lg enclosing-container">
|
||||
<div class="p-4">
|
||||
<p class="text-lg pb-4 pt-4 ">
|
||||
Book Reader Settings: Global or Per-Book
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="w-full h-[calc(100vh-12.1rem)] overflow-y-auto border rounded-lg p-4 enclosing-container">
|
||||
<div class="w-full h-[calc(100vh-11.65rem)] overflow-y-auto border rounded-lg p-4 enclosing-container">
|
||||
|
||||
<div class="flex justify-between items-center pb-2 pt-2">
|
||||
<h2 class="text-lg flex items-center gap-2">
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
<div class="w-full h-[calc(100vh-12.1rem)] overflow-y-auto border rounded-lg enclosing-container">
|
||||
<div class="w-full h-[calc(100vh-11.65rem)] overflow-y-auto border rounded-lg enclosing-container">
|
||||
<app-view-preferences></app-view-preferences>
|
||||
<p-divider></p-divider>
|
||||
<app-sidebar-sorting-preferences></app-sidebar-sorting-preferences>
|
||||
|
||||
Reference in New Issue
Block a user