feat(l2s): add book type

This commit is contained in:
matt1432 2025-03-29 00:32:01 -04:00
parent e4acaa355f
commit 4f2ce0091a
2 changed files with 68 additions and 6 deletions
apps/list2series/src

View file

@ -2,8 +2,8 @@ import axios from 'axios';
import { linkSync, mkdirSync, readFileSync, rmSync } from 'fs';
import { basename } from 'path';
// eslint-disable-next-line
type Book = any;
import { type Book } from './types';
const API = JSON.parse(
readFileSync(`${process.env.FLAKE}/apps/list2series/.env`, { encoding: 'utf-8' }),
@ -48,13 +48,17 @@ const getSeriesBooks = async(listName: string, seriesPath: string): Promise<Book
}),
});
const seriesId = (series.data.content as Book[]).find((s) => s.url === seriesPath).id;
const thisSeries = (series.data.content as Book[]).find((s) => s.url === seriesPath);
if (!thisSeries) {
throw new Error('Series could not be found');
}
// Reset Series metadata
axios.request({
method: 'patch',
maxBodyLength: Infinity,
url: `https://komga.nelim.org/api/v1/series/${seriesId}/metadata`,
url: `https://komga.nelim.org/api/v1/series/${thisSeries.id}/metadata`,
headers: {
'Content-Type': 'application/json',
'X-API-Key': API,
@ -102,7 +106,7 @@ const getSeriesBooks = async(listName: string, seriesPath: string): Promise<Book
condition: {
seriesId: {
operator: 'is',
value: seriesId,
value: thisSeries.id,
},
},
}),
@ -137,7 +141,7 @@ const scanLibrary = async() => {
};
const setBookMetadata = async(i: number, source: Book, target: Book) => {
source.metadata.title = `${source.seriesTitle} Issue #${source.number}`;
source.metadata.title = `${source.seriesTitle} Issue #${source.metadata.number}`;
source.metadata.number = i.toString();
source.metadata.numberSort = i;

View file

@ -0,0 +1,58 @@
export interface Media {
status: string
mediaType: string
pagesCount: number
comment: string
epubDivinaCompatible: boolean
epubIsKepub: boolean
mediaProfile: string
}
export interface Author {
name: string
role: string
}
export interface Metadata {
title: string
titleLock: boolean
summary: string
summaryLock: boolean
number: string
numberLock: boolean
numberSort: number
numberSortLock: boolean
releaseDate: string
releaseDateLock: boolean
authors: Author[]
authorsLock: boolean
tags: []
tagsLock: boolean
isbn: string
isbnLock: boolean
links: unknown[]
linksLock: boolean
created: string
lastModified: string
}
export interface Book {
id: string
seriesId: string
seriesTitle: string
libraryId: string
name: string
url: string
number: number
created: string
lastModified: string
fileLastModified: string
sizeBytes: number
size: string
media: Media
metadata: Metadata
readProgress: null | unknown
deleted: boolean
fileHash: string
oneshot: boolean
}