From 4f2ce0091a0d2559fd6cb6cc1e43de5a07761b3f Mon Sep 17 00:00:00 2001
From: matt1432 <matt@nelim.org>
Date: Sat, 29 Mar 2025 00:32:01 -0400
Subject: [PATCH] feat(l2s): add book type

---
 apps/list2series/src/app.ts   | 16 ++++++----
 apps/list2series/src/types.ts | 58 +++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 6 deletions(-)
 create mode 100644 apps/list2series/src/types.ts

diff --git a/apps/list2series/src/app.ts b/apps/list2series/src/app.ts
index f994611a..55f8f1ac 100644
--- a/apps/list2series/src/app.ts
+++ b/apps/list2series/src/app.ts
@@ -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;
 
diff --git a/apps/list2series/src/types.ts b/apps/list2series/src/types.ts
new file mode 100644
index 00000000..419eeb90
--- /dev/null
+++ b/apps/list2series/src/types.ts
@@ -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
+}