feat(sidecar): add sidecar JSON metadata file support (#2657)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
+11
@@ -37,6 +37,12 @@
|
||||
Search Metadata
|
||||
</p-tab>
|
||||
}
|
||||
@if (admin || canEditMetadata) {
|
||||
<p-tab value="sidecar">
|
||||
<i [class]="'pi pi-file'"></i>
|
||||
Sidecar
|
||||
</p-tab>
|
||||
}
|
||||
</p-tablist>
|
||||
<p-tabpanels class="tabpanels-responsive">
|
||||
<p-tabpanel value="view">
|
||||
@@ -57,6 +63,11 @@
|
||||
<app-metadata-searcher [book$]="book$"></app-metadata-searcher>
|
||||
</p-tabpanel>
|
||||
}
|
||||
@if (admin || canEditMetadata) {
|
||||
<p-tabpanel value="sidecar">
|
||||
<app-sidecar-viewer [book$]="book$"></app-sidecar-viewer>
|
||||
</p-tabpanel>
|
||||
}
|
||||
</p-tabpanels>
|
||||
</p-tabs>
|
||||
</div>
|
||||
|
||||
+3
-1
@@ -13,6 +13,7 @@ import {BookMetadataHostService} from '../../../../shared/service/book-metadata-
|
||||
import {MetadataViewerComponent} from './metadata-viewer/metadata-viewer.component';
|
||||
import {MetadataEditorComponent} from './metadata-editor/metadata-editor.component';
|
||||
import {MetadataSearcherComponent} from './metadata-searcher/metadata-searcher.component';
|
||||
import {SidecarViewerComponent} from './sidecar-viewer/sidecar-viewer.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-metadata-center',
|
||||
@@ -27,6 +28,7 @@ import {MetadataSearcherComponent} from './metadata-searcher/metadata-searcher.c
|
||||
MetadataViewerComponent,
|
||||
MetadataEditorComponent,
|
||||
MetadataSearcherComponent,
|
||||
SidecarViewerComponent,
|
||||
Button
|
||||
],
|
||||
styleUrls: ['./book-metadata-center.component.scss'],
|
||||
@@ -48,7 +50,7 @@ export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
||||
|
||||
private appSettings$ = this.appSettingsService.appSettings$;
|
||||
private currentBookId$ = new BehaviorSubject<number | null>(null);
|
||||
private validTabs = ['view', 'edit', 'match'];
|
||||
private validTabs = ['view', 'edit', 'match', 'sidecar'];
|
||||
|
||||
get tab(): string {
|
||||
return this._tab;
|
||||
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
<div class="sidecar-viewer">
|
||||
<div class="sidecar-header">
|
||||
<div class="header-info">
|
||||
<h3>Sidecar Metadata</h3>
|
||||
<p class="header-description">
|
||||
View and manage the .metadata.json file stored alongside your book file.
|
||||
</p>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<p-tag
|
||||
[value]="getSyncStatusLabel()"
|
||||
[severity]="getSyncStatusSeverity()"
|
||||
styleClass="sync-status-tag"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (loading) {
|
||||
<div class="loading-state">
|
||||
<i class="pi pi-spin pi-spinner"></i>
|
||||
<span>Loading sidecar data...</span>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="sidecar-actions">
|
||||
<p-button
|
||||
label="Export to Sidecar"
|
||||
icon="pi pi-upload"
|
||||
[loading]="exporting"
|
||||
(onClick)="exportToSidecar()"
|
||||
severity="primary"
|
||||
size="small"
|
||||
pTooltip="Create or update the sidecar JSON file with current database metadata"
|
||||
tooltipPosition="top"
|
||||
/>
|
||||
<p-button
|
||||
label="Import from Sidecar"
|
||||
icon="pi pi-download"
|
||||
[loading]="importing"
|
||||
[disabled]="syncStatus === 'MISSING'"
|
||||
(onClick)="importFromSidecar()"
|
||||
severity="secondary"
|
||||
size="small"
|
||||
pTooltip="Import metadata from the sidecar JSON file into the database"
|
||||
tooltipPosition="top"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@if (syncStatus === 'MISSING') {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-file"></i>
|
||||
<h4>No Sidecar File Found</h4>
|
||||
<p>
|
||||
No .metadata.json file exists for this book yet.
|
||||
Click "Export to Sidecar" to create one with the current metadata.
|
||||
</p>
|
||||
</div>
|
||||
} @else if (sidecarContent) {
|
||||
<div class="sidecar-content">
|
||||
<div class="content-header">
|
||||
<div class="content-meta">
|
||||
<span class="meta-item">
|
||||
<i class="pi pi-clock"></i>
|
||||
Generated: {{ sidecarContent.generatedAt | date:'medium' }}
|
||||
</span>
|
||||
<span class="meta-item">
|
||||
<i class="pi pi-tag"></i>
|
||||
Version: {{ sidecarContent.version }}
|
||||
</span>
|
||||
<span class="meta-item">
|
||||
<i class="pi pi-cog"></i>
|
||||
By: {{ sidecarContent.generatedBy }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="json-viewer">
|
||||
<pre class="json-content">{{ sidecarContent | json }}</pre>
|
||||
</div>
|
||||
|
||||
@if (sidecarContent.cover) {
|
||||
<div class="cover-info">
|
||||
<i class="pi pi-image"></i>
|
||||
<span>Cover file: {{ sidecarContent.cover.path }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
.sidecar-viewer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
min-height: 100%;
|
||||
animation: fadeIn 0.3s ease-in;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.sidecar-header {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
padding-bottom: 1rem;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
|
||||
@media (min-width: 640px) {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
}
|
||||
|
||||
.header-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
|
||||
h3 {
|
||||
margin: 0;
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.header-description {
|
||||
margin: 0;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-color-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
::ng-deep .sync-status-tag {
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.loading-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 3rem;
|
||||
gap: 1rem;
|
||||
color: var(--text-color-secondary);
|
||||
|
||||
i {
|
||||
font-size: 2rem;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
span {
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
}
|
||||
|
||||
.sidecar-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 3rem 2rem;
|
||||
text-align: center;
|
||||
background: var(--surface-ground);
|
||||
border: 1px dashed var(--border-color);
|
||||
border-radius: 0.75rem;
|
||||
|
||||
i {
|
||||
font-size: 3rem;
|
||||
color: var(--text-color-secondary);
|
||||
opacity: 0.5;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
h4 {
|
||||
margin: 0 0 0.5rem;
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-color-secondary);
|
||||
max-width: 400px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.sidecar-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.content-header {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.content-meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.meta-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-color-secondary);
|
||||
|
||||
i {
|
||||
font-size: 0.875rem;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.json-viewer {
|
||||
background: var(--surface-ground);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 0.5rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.json-content {
|
||||
margin: 0;
|
||||
padding: 1rem;
|
||||
font-family: 'SF Mono', 'Consolas', 'Monaco', 'Menlo', monospace;
|
||||
font-size: 0.8rem;
|
||||
line-height: 1.6;
|
||||
color: var(--text-color);
|
||||
overflow-x: auto;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
max-height: 50vh;
|
||||
overflow-y: auto;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: var(--border-color);
|
||||
border-radius: 4px;
|
||||
|
||||
&:hover {
|
||||
background: var(--text-color-secondary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.cover-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.75rem 1rem;
|
||||
background: var(--surface-ground);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-color);
|
||||
|
||||
i {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
import {Component, inject, Input, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Observable, Subject} from 'rxjs';
|
||||
import {filter, switchMap, takeUntil} from 'rxjs/operators';
|
||||
import {Book} from '../../../../book/model/book.model';
|
||||
import {SidecarMetadata, SidecarService, SidecarSyncStatus} from '../../../service/sidecar.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Tag} from 'primeng/tag';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {DatePipe, JsonPipe} from '@angular/common';
|
||||
|
||||
@Component({
|
||||
selector: 'app-sidecar-viewer',
|
||||
standalone: true,
|
||||
templateUrl: './sidecar-viewer.component.html',
|
||||
styleUrls: ['./sidecar-viewer.component.scss'],
|
||||
imports: [Button, Tag, Tooltip, JsonPipe, DatePipe]
|
||||
})
|
||||
export class SidecarViewerComponent implements OnInit, OnDestroy {
|
||||
@Input() book$!: Observable<Book>;
|
||||
|
||||
private sidecarService = inject(SidecarService);
|
||||
private messageService = inject(MessageService);
|
||||
private destroy$ = new Subject<void>();
|
||||
|
||||
sidecarContent: SidecarMetadata | null = null;
|
||||
syncStatus: SidecarSyncStatus = 'NOT_APPLICABLE';
|
||||
loading = false;
|
||||
exporting = false;
|
||||
importing = false;
|
||||
currentBookId: number | null = null;
|
||||
error: string | null = null;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.book$.pipe(
|
||||
filter((book): book is Book => !!book),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(book => {
|
||||
this.currentBookId = book.id;
|
||||
this.loadSidecarData(book.id);
|
||||
});
|
||||
}
|
||||
|
||||
loadSidecarData(bookId: number): void {
|
||||
this.loading = true;
|
||||
this.error = null;
|
||||
|
||||
this.sidecarService.getSyncStatus(bookId).pipe(
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe({
|
||||
next: (response) => {
|
||||
this.syncStatus = response.status;
|
||||
|
||||
if (response.status !== 'MISSING' && response.status !== 'NOT_APPLICABLE') {
|
||||
this.loadSidecarContent(bookId);
|
||||
} else {
|
||||
this.sidecarContent = null;
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
error: (err) => {
|
||||
this.syncStatus = 'NOT_APPLICABLE';
|
||||
this.sidecarContent = null;
|
||||
this.loading = false;
|
||||
console.error('Failed to get sync status:', err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private loadSidecarContent(bookId: number): void {
|
||||
this.sidecarService.getSidecarContent(bookId).pipe(
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe({
|
||||
next: (content) => {
|
||||
this.sidecarContent = content;
|
||||
this.loading = false;
|
||||
},
|
||||
error: (err) => {
|
||||
this.sidecarContent = null;
|
||||
this.loading = false;
|
||||
if (err.status !== 404) {
|
||||
console.error('Failed to load sidecar content:', err);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
exportToSidecar(): void {
|
||||
if (!this.currentBookId) return;
|
||||
|
||||
this.exporting = true;
|
||||
this.sidecarService.exportToSidecar(this.currentBookId).pipe(
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Export Successful',
|
||||
detail: 'Sidecar metadata file has been created.'
|
||||
});
|
||||
this.loadSidecarData(this.currentBookId!);
|
||||
this.exporting = false;
|
||||
},
|
||||
error: (err) => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Export Failed',
|
||||
detail: 'Failed to create sidecar metadata file.'
|
||||
});
|
||||
this.exporting = false;
|
||||
console.error('Export failed:', err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
importFromSidecar(): void {
|
||||
if (!this.currentBookId) return;
|
||||
|
||||
this.importing = true;
|
||||
this.sidecarService.importFromSidecar(this.currentBookId).pipe(
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Import Successful',
|
||||
detail: 'Metadata has been imported from sidecar file.'
|
||||
});
|
||||
this.loadSidecarData(this.currentBookId!);
|
||||
this.importing = false;
|
||||
},
|
||||
error: (err) => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Import Failed',
|
||||
detail: 'Failed to import metadata from sidecar file.'
|
||||
});
|
||||
this.importing = false;
|
||||
console.error('Import failed:', err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getSyncStatusSeverity(): 'success' | 'info' | 'warn' | 'danger' | 'secondary' | 'contrast' {
|
||||
switch (this.syncStatus) {
|
||||
case 'IN_SYNC':
|
||||
return 'success';
|
||||
case 'OUTDATED':
|
||||
return 'warn';
|
||||
case 'CONFLICT':
|
||||
return 'danger';
|
||||
case 'MISSING':
|
||||
return 'secondary';
|
||||
default:
|
||||
return 'info';
|
||||
}
|
||||
}
|
||||
|
||||
getSyncStatusLabel(): string {
|
||||
switch (this.syncStatus) {
|
||||
case 'IN_SYNC':
|
||||
return 'In Sync';
|
||||
case 'OUTDATED':
|
||||
return 'Outdated';
|
||||
case 'CONFLICT':
|
||||
return 'Conflict';
|
||||
case 'MISSING':
|
||||
return 'Missing';
|
||||
case 'NOT_APPLICABLE':
|
||||
return 'N/A';
|
||||
default:
|
||||
return 'Unknown';
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
|
||||
export interface SidecarCoverInfo {
|
||||
source: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface SidecarSeries {
|
||||
name?: string;
|
||||
number?: number;
|
||||
total?: number;
|
||||
}
|
||||
|
||||
export interface SidecarIdentifiers {
|
||||
asin?: string;
|
||||
goodreadsId?: string;
|
||||
googleId?: string;
|
||||
hardcoverId?: string;
|
||||
comicvineId?: string;
|
||||
lubimyczytacId?: string;
|
||||
ranobedbId?: string;
|
||||
audibleId?: string;
|
||||
}
|
||||
|
||||
export interface SidecarRating {
|
||||
average?: number;
|
||||
count?: number;
|
||||
}
|
||||
|
||||
export interface SidecarRatings {
|
||||
amazon?: SidecarRating;
|
||||
goodreads?: SidecarRating;
|
||||
hardcover?: SidecarRating;
|
||||
lubimyczytac?: SidecarRating;
|
||||
ranobedb?: SidecarRating;
|
||||
audible?: SidecarRating;
|
||||
}
|
||||
|
||||
export interface SidecarBookMetadata {
|
||||
title?: string;
|
||||
subtitle?: string;
|
||||
authors?: string[];
|
||||
publisher?: string;
|
||||
publishedDate?: string;
|
||||
description?: string;
|
||||
isbn10?: string;
|
||||
isbn13?: string;
|
||||
language?: string;
|
||||
pageCount?: number;
|
||||
categories?: string[];
|
||||
moods?: string[];
|
||||
tags?: string[];
|
||||
series?: SidecarSeries;
|
||||
identifiers?: SidecarIdentifiers;
|
||||
ratings?: SidecarRatings;
|
||||
ageRating?: number;
|
||||
contentRating?: string;
|
||||
narrator?: string;
|
||||
abridged?: boolean;
|
||||
}
|
||||
|
||||
export interface SidecarMetadata {
|
||||
version: string;
|
||||
generatedAt: string;
|
||||
generatedBy: string;
|
||||
metadata: SidecarBookMetadata;
|
||||
cover?: SidecarCoverInfo;
|
||||
}
|
||||
|
||||
export type SidecarSyncStatus = 'IN_SYNC' | 'OUTDATED' | 'MISSING' | 'CONFLICT' | 'NOT_APPLICABLE';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SidecarService {
|
||||
private readonly apiUrl = `${API_CONFIG.BASE_URL}/api/v1`;
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
getSidecarContent(bookId: number): Observable<SidecarMetadata> {
|
||||
return this.http.get<SidecarMetadata>(`${this.apiUrl}/books/${bookId}/sidecar`);
|
||||
}
|
||||
|
||||
getSyncStatus(bookId: number): Observable<{status: SidecarSyncStatus}> {
|
||||
return this.http.get<{status: SidecarSyncStatus}>(`${this.apiUrl}/books/${bookId}/sidecar/status`);
|
||||
}
|
||||
|
||||
exportToSidecar(bookId: number): Observable<{message: string}> {
|
||||
return this.http.post<{message: string}>(`${this.apiUrl}/books/${bookId}/sidecar/export`, {});
|
||||
}
|
||||
|
||||
importFromSidecar(bookId: number): Observable<{message: string}> {
|
||||
return this.http.post<{message: string}>(`${this.apiUrl}/books/${bookId}/sidecar/import`, {});
|
||||
}
|
||||
|
||||
bulkExport(libraryId: number): Observable<{message: string, exported: number}> {
|
||||
return this.http.post<{message: string, exported: number}>(
|
||||
`${this.apiUrl}/libraries/${libraryId}/sidecar/export-all`, {}
|
||||
);
|
||||
}
|
||||
|
||||
bulkImport(libraryId: number): Observable<{message: string, imported: number}> {
|
||||
return this.http.post<{message: string, imported: number}>(
|
||||
`${this.apiUrl}/libraries/${libraryId}/sidecar/import-all`, {}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user