Add library push to website from the content editor
This commit is contained in:
1 parent
ec57bd73b3
commit
0f90babb7a
13 files changed
+281
-20
No files matched your search
@@ -4,7 +4,7 @@ import type { MediaDetails, MediaKind } from '#lib/media/types';
|
||||
import type { LibraryMedia } from '#lib/library/types';
|
||||
import { timestamp, type SqlDatabase } from './database';
|
||||
import { hasImage, imageUrl, removeImage, syncImage } from './images';
|
||||
import { readChoice, readHistory, readRating, readText, type RequestBody } from './input';
|
||||
import { readChoice, readHistory, readRating, readText, type ExportedEntry, type RequestBody } from './input';
|
||||
|
||||
interface MediaRow {
|
||||
imdb_id: string;
|
||||
@@ -83,6 +83,28 @@ export function listMedia(database: SqlDatabase, imageIds: Set<string>): Library
|
||||
};
|
||||
}
|
||||
|
||||
export function exportMedia(database: SqlDatabase): ExportedEntry[] {
|
||||
const rows = database.prepare('SELECT * FROM media ORDER BY imdb_id').all() as MediaRow[];
|
||||
return rows.map((row) => ({
|
||||
id: row.imdb_id,
|
||||
fields: {
|
||||
kind: row.kind,
|
||||
name: row.name,
|
||||
status: row.status,
|
||||
rating: row.rating,
|
||||
collection: row.collection,
|
||||
year: row.year,
|
||||
genre: row.genre,
|
||||
runtime: row.runtime,
|
||||
plot: row.plot,
|
||||
posterSource: row.poster_source,
|
||||
added: row.added,
|
||||
started: row.started,
|
||||
finished: row.finished
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
function mergeRow(imdbId: string, existing: MediaRow | null, body: RequestBody): MediaRow {
|
||||
const name = readText(body, 'name', existing?.name ?? null);
|
||||
if (!name) error(400, 'name is required');
|
||||
|
||||
Reference in new issue
Block a user