@acanthis-dec/storage 1.1.4 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { BinaryResponse, Cookie, CookieOptions, CookiesInit, CookiesStore, cookieStoreSign } from "@acanthis-dec/browser-fetch";
2
- import { BookshelfItem, Chapter, Novel, NovelInfo, NovelSearchResult, ReadingProgress, Volume } from "@acanthis-dec/core";
2
+ import { BookshelfCategory, BookshelfItem, CachedGenreItem, Chapter, Novel, NovelInfo, NovelSearchResult, NovelStatus, ReadingProgress, Volume } from "@acanthis-dec/core";
3
3
  import { Client } from "@libsql/client";
4
4
  import z, { z as z$1 } from "zod";
5
5
  interface DataWithUpdatedAt<T> {
@@ -23,6 +23,9 @@ interface VolumeCoverMetadata {
23
23
  interface ListNovelsOptions {
24
24
  page: number;
25
25
  pageSize: number;
26
+ genres?: string[] | undefined;
27
+ status?: NovelStatus | undefined;
28
+ q?: string | undefined;
26
29
  }
27
30
  interface PaginatedNovels {
28
31
  items: NovelInfo[];
@@ -33,15 +36,18 @@ interface PaginatedNovels {
33
36
  interface SyncStateResult {
34
37
  bookshelf: BookshelfItem[];
35
38
  progress: ReadingProgress[];
39
+ categories: BookshelfCategory[];
36
40
  cursor: number;
37
41
  }
38
42
  interface MergeSyncStateInput {
39
- bookshelf?: BookshelfItem[];
40
- progress?: ReadingProgress[];
43
+ bookshelf?: BookshelfItem[] | undefined;
44
+ progress?: ReadingProgress[] | undefined;
45
+ categories?: BookshelfCategory[] | undefined;
41
46
  }
42
47
  interface MergeSyncStateResult {
43
48
  bookshelf: BookshelfItem[];
44
49
  progress: ReadingProgress[];
50
+ categories: BookshelfCategory[];
45
51
  serverTime: number;
46
52
  }
47
53
  type MigrationOptions = {
@@ -1184,6 +1190,126 @@ declare function getDrizzle(client: Client): import("drizzle-orm/libsql").LibSQL
1184
1190
  dialect: 'sqlite';
1185
1191
  isAlias: false;
1186
1192
  }>;
1193
+ bookshelfCategories: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
1194
+ name: "bookshelf_categories";
1195
+ schema: undefined;
1196
+ columns: {
1197
+ id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
1198
+ name: string;
1199
+ tableName: "bookshelf_categories";
1200
+ dataType: "string";
1201
+ data: string;
1202
+ driverParam: string;
1203
+ notNull: true;
1204
+ hasDefault: false;
1205
+ isPrimaryKey: true;
1206
+ isAutoincrement: false;
1207
+ hasRuntimeDefault: false;
1208
+ enumValues: [string, ...string[]];
1209
+ baseColumn: never;
1210
+ identity: undefined;
1211
+ generated: undefined;
1212
+ }, {}>;
1213
+ name: import("drizzle-orm/sqlite-core").SQLiteColumn<{
1214
+ name: string;
1215
+ tableName: "bookshelf_categories";
1216
+ dataType: "string";
1217
+ data: string;
1218
+ driverParam: string;
1219
+ notNull: true;
1220
+ hasDefault: false;
1221
+ isPrimaryKey: false;
1222
+ isAutoincrement: false;
1223
+ hasRuntimeDefault: false;
1224
+ enumValues: [string, ...string[]];
1225
+ baseColumn: never;
1226
+ identity: undefined;
1227
+ generated: undefined;
1228
+ }, {}>;
1229
+ sortOrder: import("drizzle-orm/sqlite-core").SQLiteColumn<{
1230
+ name: string;
1231
+ tableName: "bookshelf_categories";
1232
+ dataType: "number int53";
1233
+ data: number;
1234
+ driverParam: number;
1235
+ notNull: true;
1236
+ hasDefault: true;
1237
+ isPrimaryKey: false;
1238
+ isAutoincrement: false;
1239
+ hasRuntimeDefault: false;
1240
+ enumValues: undefined;
1241
+ baseColumn: never;
1242
+ identity: undefined;
1243
+ generated: undefined;
1244
+ }, {}>;
1245
+ createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
1246
+ name: string;
1247
+ tableName: "bookshelf_categories";
1248
+ dataType: "number int53";
1249
+ data: number;
1250
+ driverParam: number;
1251
+ notNull: true;
1252
+ hasDefault: false;
1253
+ isPrimaryKey: false;
1254
+ isAutoincrement: false;
1255
+ hasRuntimeDefault: false;
1256
+ enumValues: undefined;
1257
+ baseColumn: never;
1258
+ identity: undefined;
1259
+ generated: undefined;
1260
+ }, {}>;
1261
+ updatedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
1262
+ name: string;
1263
+ tableName: "bookshelf_categories";
1264
+ dataType: "number int53";
1265
+ data: number;
1266
+ driverParam: number;
1267
+ notNull: true;
1268
+ hasDefault: false;
1269
+ isPrimaryKey: false;
1270
+ isAutoincrement: false;
1271
+ hasRuntimeDefault: false;
1272
+ enumValues: undefined;
1273
+ baseColumn: never;
1274
+ identity: undefined;
1275
+ generated: undefined;
1276
+ }, {}>;
1277
+ serverUpdatedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
1278
+ name: string;
1279
+ tableName: "bookshelf_categories";
1280
+ dataType: "number int53";
1281
+ data: number;
1282
+ driverParam: number;
1283
+ notNull: true;
1284
+ hasDefault: false;
1285
+ isPrimaryKey: false;
1286
+ isAutoincrement: false;
1287
+ hasRuntimeDefault: false;
1288
+ enumValues: undefined;
1289
+ baseColumn: never;
1290
+ identity: undefined;
1291
+ generated: undefined;
1292
+ }, {}>;
1293
+ deletedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
1294
+ name: string;
1295
+ tableName: "bookshelf_categories";
1296
+ dataType: "number int53";
1297
+ data: number;
1298
+ driverParam: number;
1299
+ notNull: false;
1300
+ hasDefault: false;
1301
+ isPrimaryKey: false;
1302
+ isAutoincrement: false;
1303
+ hasRuntimeDefault: false;
1304
+ enumValues: undefined;
1305
+ baseColumn: never;
1306
+ identity: undefined;
1307
+ generated: undefined;
1308
+ }, {}>;
1309
+ };
1310
+ dialect: 'sqlite';
1311
+ isAlias: false;
1312
+ }>;
1187
1313
  bookshelfItems: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
1188
1314
  name: "bookshelf_items";
1189
1315
  schema: undefined;
@@ -1348,6 +1474,54 @@ declare function getDrizzle(client: Client): import("drizzle-orm/libsql").LibSQL
1348
1474
  identity: undefined;
1349
1475
  generated: undefined;
1350
1476
  }, {}>;
1477
+ categoryIds: import("drizzle-orm/sqlite-core").SQLiteColumn<{
1478
+ name: string;
1479
+ tableName: "bookshelf_items";
1480
+ dataType: "string";
1481
+ data: string;
1482
+ driverParam: string;
1483
+ notNull: true;
1484
+ hasDefault: true;
1485
+ isPrimaryKey: false;
1486
+ isAutoincrement: false;
1487
+ hasRuntimeDefault: false;
1488
+ enumValues: [string, ...string[]];
1489
+ baseColumn: never;
1490
+ identity: undefined;
1491
+ generated: undefined;
1492
+ }, {}>;
1493
+ genresJson: import("drizzle-orm/sqlite-core").SQLiteColumn<{
1494
+ name: string;
1495
+ tableName: "bookshelf_items";
1496
+ dataType: "string";
1497
+ data: string;
1498
+ driverParam: string;
1499
+ notNull: true;
1500
+ hasDefault: true;
1501
+ isPrimaryKey: false;
1502
+ isAutoincrement: false;
1503
+ hasRuntimeDefault: false;
1504
+ enumValues: [string, ...string[]];
1505
+ baseColumn: never;
1506
+ identity: undefined;
1507
+ generated: undefined;
1508
+ }, {}>;
1509
+ status: import("drizzle-orm/sqlite-core").SQLiteColumn<{
1510
+ name: string;
1511
+ tableName: "bookshelf_items";
1512
+ dataType: "string enum";
1513
+ data: "completed" | "ongoing" | "unknown";
1514
+ driverParam: string;
1515
+ notNull: true;
1516
+ hasDefault: true;
1517
+ isPrimaryKey: false;
1518
+ isAutoincrement: false;
1519
+ hasRuntimeDefault: false;
1520
+ enumValues: ["ongoing", "completed", "unknown"];
1521
+ baseColumn: never;
1522
+ identity: undefined;
1523
+ generated: undefined;
1524
+ }, {}>;
1351
1525
  };
1352
1526
  dialect: 'sqlite';
1353
1527
  isAlias: false;
@@ -1580,6 +1754,22 @@ declare function getDrizzle(client: Client): import("drizzle-orm/libsql").LibSQL
1580
1754
  identity: undefined;
1581
1755
  generated: undefined;
1582
1756
  }, {}>;
1757
+ historyHiddenAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
1758
+ name: string;
1759
+ tableName: "reading_progress";
1760
+ dataType: "number int53";
1761
+ data: number;
1762
+ driverParam: number;
1763
+ notNull: false;
1764
+ hasDefault: false;
1765
+ isPrimaryKey: false;
1766
+ isAutoincrement: false;
1767
+ hasRuntimeDefault: false;
1768
+ enumValues: undefined;
1769
+ baseColumn: never;
1770
+ identity: undefined;
1771
+ generated: undefined;
1772
+ }, {}>;
1583
1773
  };
1584
1774
  dialect: 'sqlite';
1585
1775
  isAlias: false;
@@ -1622,7 +1812,9 @@ export declare class DatabaseService {
1622
1812
  } | undefined>;
1623
1813
  updateIllustrationFileInfo(platform: string, urlHash: string, fileHash: string, contentType: string): Promise<void>;
1624
1814
  listCachedNovels(platform: string, options: ListNovelsOptions): Promise<PaginatedNovels>;
1815
+ listCachedGenres(platform: string): Promise<CachedGenreItem[]>;
1625
1816
  private getMaxSyncCursor;
1817
+ private enrichBookshelfItemsWithNovelMetadata;
1626
1818
  getSyncState(since?: number): Promise<SyncStateResult>;
1627
1819
  mergeSyncState(input: MergeSyncStateInput): Promise<MergeSyncStateResult>;
1628
1820
  close(logger?: (message: string) => void): Promise<void>;
@@ -1682,6 +1874,7 @@ export declare class StorageService {
1682
1874
  getIllustrationData(platform: string, urlHash: string): Promise<BinaryResponse | undefined>;
1683
1875
  setIllustrationData(platform: string, urlHash: string, data: Buffer, contentType: string): Promise<void>;
1684
1876
  listCachedNovels(platform: string, options: ListNovelsOptions): Promise<PaginatedNovels>;
1877
+ listCachedGenres(platform: string): Promise<CachedGenreItem[]>;
1685
1878
  getSyncState(since?: number): Promise<SyncStateResult>;
1686
1879
  mergeSyncState(input: MergeSyncStateInput): Promise<MergeSyncStateResult>;
1687
1880
  close(logger?: (message: string) => void): Promise<void>;
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { cookieStoreSign, isCookiesStore, matchesDomain, matchesPath } from "@acanthis-dec/browser-fetch";
2
- import { and, count, defineRelations, desc, eq, gt, inArray, isNull, max, ne, notInArray } from "drizzle-orm";
2
+ import { and, asc, count, defineRelations, desc, eq, gt, inArray, isNull, max, ne, notInArray, or, sql } from "drizzle-orm";
3
3
  import { integer, primaryKey, sqliteTable, text, unique, uniqueIndex } from "drizzle-orm/sqlite-core";
4
4
  import { existsSync, mkdirSync, rmSync, statSync } from "node:fs";
5
5
  import { dirname, resolve } from "node:path";
@@ -105,6 +105,15 @@ const illustrationMetadata = sqliteTable("illustration_metadata", {
105
105
  contentType: text("content_type"),
106
106
  createdAt: integer("created_at").notNull()
107
107
  }, (table) => [uniqueIndex("illustration_platform_url_hash_idx").on(table.platform, table.urlHash)]);
108
+ const bookshelfCategories = sqliteTable("bookshelf_categories", {
109
+ id: text("id").primaryKey(),
110
+ name: text("name").notNull(),
111
+ sortOrder: integer("sort_order").notNull().default(0),
112
+ createdAt: integer("created_at").notNull(),
113
+ updatedAt: integer("updated_at").notNull(),
114
+ serverUpdatedAt: integer("server_updated_at").notNull(),
115
+ deletedAt: integer("deleted_at")
116
+ });
108
117
  const bookshelfItems = sqliteTable("bookshelf_items", {
109
118
  id: integer("id").primaryKey({ autoIncrement: true }),
110
119
  platform: text("platform").notNull(),
@@ -115,7 +124,14 @@ const bookshelfItems = sqliteTable("bookshelf_items", {
115
124
  addedAt: integer("added_at").notNull(),
116
125
  updatedAt: integer("updated_at").notNull(),
117
126
  serverUpdatedAt: integer("server_updated_at").notNull(),
118
- deletedAt: integer("deleted_at")
127
+ deletedAt: integer("deleted_at"),
128
+ categoryIds: text("category_ids").notNull().default("[]"),
129
+ genresJson: text("genres_json").notNull().default("[]"),
130
+ status: text("status", { enum: [
131
+ "ongoing",
132
+ "completed",
133
+ "unknown"
134
+ ] }).notNull().default("unknown")
119
135
  }, (table) => [uniqueIndex("bookshelf_platform_novel_idx").on(table.platform, table.novelId)]);
120
136
  const readingProgress = sqliteTable("reading_progress", {
121
137
  id: integer("id").primaryKey({ autoIncrement: true }),
@@ -131,7 +147,8 @@ const readingProgress = sqliteTable("reading_progress", {
131
147
  totalParagraphs: integer("total_paragraphs").notNull(),
132
148
  deviceLabel: text("device_label").notNull(),
133
149
  updatedAt: integer("updated_at").notNull(),
134
- serverUpdatedAt: integer("server_updated_at").notNull()
150
+ serverUpdatedAt: integer("server_updated_at").notNull(),
151
+ historyHiddenAt: integer("history_hidden_at")
135
152
  }, (table) => [uniqueIndex("reading_progress_platform_novel_idx").on(table.platform, table.novelId)]);
136
153
  const relations = defineRelations({
137
154
  novels,
@@ -146,6 +163,7 @@ const relations = defineRelations({
146
163
  cookies,
147
164
  generalCache,
148
165
  illustrationMetadata,
166
+ bookshelfCategories,
149
167
  bookshelfItems,
150
168
  readingProgress
151
169
  }, (r) => ({
@@ -447,6 +465,41 @@ function getDrizzle(client) {
447
465
  });
448
466
  }
449
467
  const CLOCK_SKEW_TOLERANCE_MS = 6e4;
468
+ function normalizeStringList(values) {
469
+ if (!values || values.length === 0) return [];
470
+ const seen = /* @__PURE__ */ new Set();
471
+ const result = [];
472
+ for (const raw of values) {
473
+ const trimmed = raw.trim();
474
+ if (!trimmed || seen.has(trimmed)) continue;
475
+ seen.add(trimmed);
476
+ result.push(trimmed);
477
+ }
478
+ return result;
479
+ }
480
+ function parseJsonStringArray(raw) {
481
+ if (!raw) return [];
482
+ try {
483
+ const parsed = JSON.parse(raw);
484
+ if (!Array.isArray(parsed)) return [];
485
+ return normalizeStringList(parsed.filter((entry) => typeof entry === "string"));
486
+ } catch {
487
+ return [];
488
+ }
489
+ }
490
+ function escapeLikePattern(value) {
491
+ return value.replaceAll("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_");
492
+ }
493
+ function toBookshelfCategory(row) {
494
+ return {
495
+ id: row.id,
496
+ name: row.name,
497
+ sortOrder: row.sortOrder,
498
+ createdAt: row.createdAt,
499
+ updatedAt: row.updatedAt,
500
+ deletedAt: row.deletedAt
501
+ };
502
+ }
450
503
  function toBookshelfItem(row) {
451
504
  return {
452
505
  platform: row.platform,
@@ -456,7 +509,10 @@ function toBookshelfItem(row) {
456
509
  coverUrl: row.coverUrl,
457
510
  addedAt: row.addedAt,
458
511
  updatedAt: row.updatedAt,
459
- deletedAt: row.deletedAt
512
+ deletedAt: row.deletedAt,
513
+ categoryIds: parseJsonStringArray(row.categoryIds),
514
+ genres: parseJsonStringArray(row.genresJson),
515
+ status: row.status
460
516
  };
461
517
  }
462
518
  function toReadingProgress(row) {
@@ -472,7 +528,8 @@ function toReadingProgress(row) {
472
528
  paragraphIndex: row.paragraphIndex,
473
529
  totalParagraphs: row.totalParagraphs,
474
530
  deviceLabel: row.deviceLabel,
475
- updatedAt: row.updatedAt
531
+ updatedAt: row.updatedAt,
532
+ historyHiddenAt: row.historyHiddenAt ?? null
476
533
  };
477
534
  }
478
535
  var DatabaseService = class {
@@ -893,7 +950,25 @@ var DatabaseService = class {
893
950
  const page = Math.max(1, Math.trunc(options.page));
894
951
  const pageSize = Math.max(1, Math.trunc(options.pageSize));
895
952
  const offset = (page - 1) * pageSize;
896
- const whereClause = and(eq(novels.platform, platform), ne(novels.status, "unknown"), ne(novels.author, ""), ne(novels.name, ""));
953
+ const conditions = [
954
+ eq(novels.platform, platform),
955
+ ne(novels.author, ""),
956
+ ne(novels.name, "")
957
+ ];
958
+ if (options.status !== void 0) conditions.push(eq(novels.status, options.status));
959
+ else conditions.push(ne(novels.status, "unknown"));
960
+ const trimmedQuery = options.q?.trim();
961
+ if (trimmedQuery) {
962
+ const pattern = `%${escapeLikePattern(trimmedQuery.toLowerCase())}%`;
963
+ const keywordCondition = or(sql`LOWER(${novels.name}) LIKE ${pattern} ESCAPE '\\'`, sql`LOWER(${novels.author}) LIKE ${pattern} ESCAPE '\\'`);
964
+ if (keywordCondition) conditions.push(keywordCondition);
965
+ }
966
+ const normalizedGenres = normalizeStringList(options.genres);
967
+ if (normalizedGenres.length > 0) {
968
+ const matchingNovelIdsSubquery = this.db.select({ novelId: novelGenres.novelId }).from(novelGenres).innerJoin(genres, eq(novelGenres.genreId, genres.id)).where(inArray(genres.name, normalizedGenres)).groupBy(novelGenres.novelId).having(sql`COUNT(DISTINCT ${genres.name}) = ${normalizedGenres.length}`);
969
+ conditions.push(inArray(novels.id, matchingNovelIdsSubquery));
970
+ }
971
+ const whereClause = and(...conditions);
897
972
  const total = (await this.db.select({ value: count() }).from(novels).where(whereClause).get())?.value ?? 0;
898
973
  if (total === 0) return {
899
974
  items: [],
@@ -944,12 +1019,90 @@ var DatabaseService = class {
944
1019
  pageSize
945
1020
  };
946
1021
  }
1022
+ async listCachedGenres(platform) {
1023
+ await this.ensureReady();
1024
+ const countExpr = sql`COUNT(DISTINCT ${novels.id})`;
1025
+ return (await this.db.select({
1026
+ name: genres.name,
1027
+ count: countExpr
1028
+ }).from(novelGenres).innerJoin(genres, eq(novelGenres.genreId, genres.id)).innerJoin(novels, eq(novelGenres.novelId, novels.id)).where(and(eq(novels.platform, platform), ne(novels.status, "unknown"), ne(novels.author, ""), ne(novels.name, ""))).groupBy(genres.id, genres.name).orderBy(desc(countExpr), asc(genres.name)).all()).map((row) => ({
1029
+ name: row.name,
1030
+ count: Number(row.count)
1031
+ }));
1032
+ }
947
1033
  async getMaxSyncCursor(executor) {
948
1034
  const bookshelfMaxRow = await executor.select({ value: max(bookshelfItems.serverUpdatedAt) }).from(bookshelfItems).get();
949
1035
  const progressMaxRow = await executor.select({ value: max(readingProgress.serverUpdatedAt) }).from(readingProgress).get();
1036
+ const categoryMaxRow = await executor.select({ value: max(bookshelfCategories.serverUpdatedAt) }).from(bookshelfCategories).get();
950
1037
  const bookshelfMax = Number(bookshelfMaxRow?.value ?? 0);
951
1038
  const progressMax = Number(progressMaxRow?.value ?? 0);
952
- return Math.max(bookshelfMax, progressMax);
1039
+ const categoryMax = Number(categoryMaxRow?.value ?? 0);
1040
+ return Math.max(bookshelfMax, progressMax, categoryMax);
1041
+ }
1042
+ async enrichBookshelfItemsWithNovelMetadata(executor, items) {
1043
+ if (items.length === 0) return items;
1044
+ const idsByPlatform = /* @__PURE__ */ new Map();
1045
+ for (const item of items) {
1046
+ let idSet = idsByPlatform.get(item.platform);
1047
+ if (!idSet) {
1048
+ idSet = /* @__PURE__ */ new Set();
1049
+ idsByPlatform.set(item.platform, idSet);
1050
+ }
1051
+ idSet.add(item.novelId);
1052
+ }
1053
+ const matchedNovels = [];
1054
+ const chunkSize = 500;
1055
+ for (const [platform, idSet] of idsByPlatform) {
1056
+ const allIds = Array.from(idSet);
1057
+ for (let i = 0; i < allIds.length; i += chunkSize) {
1058
+ const chunk = allIds.slice(i, i + chunkSize);
1059
+ const rows = await executor.select({
1060
+ id: novels.id,
1061
+ platform: novels.platform,
1062
+ platformId: novels.platformId,
1063
+ status: novels.status
1064
+ }).from(novels).where(and(eq(novels.platform, platform), inArray(novels.platformId, chunk))).all();
1065
+ matchedNovels.push(...rows);
1066
+ }
1067
+ }
1068
+ const genresByNovelDbId = /* @__PURE__ */ new Map();
1069
+ if (matchedNovels.length > 0) {
1070
+ const dbIds = matchedNovels.map((row) => row.id);
1071
+ for (let i = 0; i < dbIds.length; i += chunkSize) {
1072
+ const chunk = dbIds.slice(i, i + chunkSize);
1073
+ const genreRows = await executor.select({
1074
+ novelId: novelGenres.novelId,
1075
+ genreName: genres.name
1076
+ }).from(novelGenres).innerJoin(genres, eq(novelGenres.genreId, genres.id)).where(inArray(novelGenres.novelId, chunk)).all();
1077
+ for (const row of genreRows) {
1078
+ const list = genresByNovelDbId.get(row.novelId);
1079
+ if (list) list.push(row.genreName);
1080
+ else genresByNovelDbId.set(row.novelId, [row.genreName]);
1081
+ }
1082
+ }
1083
+ }
1084
+ const metaByKey = /* @__PURE__ */ new Map();
1085
+ for (const novelRow of matchedNovels) {
1086
+ const key = `${novelRow.platform}\0${novelRow.platformId}`;
1087
+ metaByKey.set(key, {
1088
+ status: novelRow.status,
1089
+ genres: normalizeStringList(genresByNovelDbId.get(novelRow.id))
1090
+ });
1091
+ }
1092
+ return items.map((item) => {
1093
+ const key = `${item.platform}\0${item.novelId}`;
1094
+ const novelMeta = metaByKey.get(key);
1095
+ const fallbackGenres = normalizeStringList(item.genres);
1096
+ const fallbackStatus = item.status ?? "unknown";
1097
+ const resolvedGenres = novelMeta && novelMeta.genres.length > 0 ? novelMeta.genres : fallbackGenres;
1098
+ const resolvedStatus = novelMeta && novelMeta.status !== "unknown" ? novelMeta.status : fallbackStatus;
1099
+ return {
1100
+ ...item,
1101
+ categoryIds: normalizeStringList(item.categoryIds),
1102
+ genres: resolvedGenres,
1103
+ status: resolvedStatus
1104
+ };
1105
+ });
953
1106
  }
954
1107
  async getSyncState(since) {
955
1108
  await this.ensureReady();
@@ -958,17 +1111,21 @@ var DatabaseService = class {
958
1111
  if (since === void 0 || since <= 0) {
959
1112
  const bookshelfRows = await tx.select().from(bookshelfItems).where(isNull(bookshelfItems.deletedAt)).all();
960
1113
  const progressRows = await tx.select().from(readingProgress).all();
1114
+ const categoryRows = await tx.select().from(bookshelfCategories).where(isNull(bookshelfCategories.deletedAt)).orderBy(asc(bookshelfCategories.sortOrder), asc(bookshelfCategories.createdAt), asc(bookshelfCategories.id)).all();
961
1115
  return {
962
- bookshelf: bookshelfRows.map(toBookshelfItem),
1116
+ bookshelf: await this.enrichBookshelfItemsWithNovelMetadata(tx, bookshelfRows.map(toBookshelfItem)),
963
1117
  progress: progressRows.map(toReadingProgress),
1118
+ categories: categoryRows.map(toBookshelfCategory),
964
1119
  cursor: maxCursor
965
1120
  };
966
1121
  }
967
1122
  const bookshelfRows = await tx.select().from(bookshelfItems).where(gt(bookshelfItems.serverUpdatedAt, since)).all();
968
1123
  const progressRows = await tx.select().from(readingProgress).where(gt(readingProgress.serverUpdatedAt, since)).all();
1124
+ const categoryRows = await tx.select().from(bookshelfCategories).where(gt(bookshelfCategories.serverUpdatedAt, since)).orderBy(asc(bookshelfCategories.sortOrder), asc(bookshelfCategories.createdAt), asc(bookshelfCategories.id)).all();
969
1125
  return {
970
- bookshelf: bookshelfRows.map(toBookshelfItem),
1126
+ bookshelf: await this.enrichBookshelfItemsWithNovelMetadata(tx, bookshelfRows.map(toBookshelfItem)),
971
1127
  progress: progressRows.map(toReadingProgress),
1128
+ categories: categoryRows.map(toBookshelfCategory),
972
1129
  cursor: Math.max(since, maxCursor)
973
1130
  };
974
1131
  });
@@ -981,8 +1138,41 @@ var DatabaseService = class {
981
1138
  lastCursor = Math.max(Date.now(), lastCursor + 1);
982
1139
  return lastCursor;
983
1140
  };
1141
+ const categoryMap = /* @__PURE__ */ new Map();
984
1142
  const bookshelfMap = /* @__PURE__ */ new Map();
985
1143
  const progressMap = /* @__PURE__ */ new Map();
1144
+ for (const cat of input.categories ?? []) {
1145
+ const maxAllowedTime = Date.now() + CLOCK_SKEW_TOLERANCE_MS;
1146
+ const effectiveUpdatedAt = Math.min(cat.updatedAt, maxAllowedTime);
1147
+ const effectiveCreatedAt = Math.min(cat.createdAt, maxAllowedTime);
1148
+ const trimmedName = cat.name.trim();
1149
+ const normalizedSortOrder = Math.trunc(cat.sortOrder);
1150
+ const existing = await tx.select().from(bookshelfCategories).where(eq(bookshelfCategories.id, cat.id)).get();
1151
+ if (!existing) {
1152
+ const serverUpdatedAt = nextCursor();
1153
+ const inserted = await tx.insert(bookshelfCategories).values({
1154
+ id: cat.id,
1155
+ name: trimmedName,
1156
+ sortOrder: normalizedSortOrder,
1157
+ createdAt: effectiveCreatedAt,
1158
+ updatedAt: effectiveUpdatedAt,
1159
+ serverUpdatedAt,
1160
+ deletedAt: cat.deletedAt
1161
+ }).returning().get();
1162
+ categoryMap.set(cat.id, toBookshelfCategory(inserted));
1163
+ } else if (effectiveUpdatedAt >= existing.updatedAt) {
1164
+ const serverUpdatedAt = nextCursor();
1165
+ const updated = await tx.update(bookshelfCategories).set({
1166
+ name: trimmedName,
1167
+ sortOrder: normalizedSortOrder,
1168
+ updatedAt: effectiveUpdatedAt,
1169
+ serverUpdatedAt,
1170
+ deletedAt: cat.deletedAt
1171
+ }).where(eq(bookshelfCategories.id, existing.id)).returning().get();
1172
+ if (!updated) throw new Error(`Failed to update bookshelf category: ${cat.id}`);
1173
+ categoryMap.set(cat.id, toBookshelfCategory(updated));
1174
+ } else categoryMap.set(cat.id, toBookshelfCategory(existing));
1175
+ }
986
1176
  for (const item of input.bookshelf ?? []) {
987
1177
  const key = `${item.platform}\0${item.novelId}`;
988
1178
  const effectiveUpdatedAt = Math.min(item.updatedAt, Date.now() + CLOCK_SKEW_TOLERANCE_MS);
@@ -998,11 +1188,17 @@ var DatabaseService = class {
998
1188
  addedAt: item.addedAt,
999
1189
  updatedAt: effectiveUpdatedAt,
1000
1190
  serverUpdatedAt,
1001
- deletedAt: item.deletedAt
1191
+ deletedAt: item.deletedAt,
1192
+ categoryIds: JSON.stringify(normalizeStringList(item.categoryIds)),
1193
+ genresJson: JSON.stringify(normalizeStringList(item.genres)),
1194
+ status: item.status ?? "unknown"
1002
1195
  }).returning().get();
1003
1196
  bookshelfMap.set(key, toBookshelfItem(inserted));
1004
1197
  } else if (effectiveUpdatedAt >= existing.updatedAt) {
1005
1198
  const serverUpdatedAt = nextCursor();
1199
+ const nextCategoryIds = item.categoryIds !== void 0 ? JSON.stringify(normalizeStringList(item.categoryIds)) : existing.categoryIds;
1200
+ const nextGenresJson = item.genres !== void 0 ? JSON.stringify(normalizeStringList(item.genres)) : existing.genresJson;
1201
+ const nextStatus = item.status !== void 0 ? item.status : existing.status;
1006
1202
  const updated = await tx.update(bookshelfItems).set({
1007
1203
  title: item.title,
1008
1204
  author: item.author,
@@ -1010,7 +1206,10 @@ var DatabaseService = class {
1010
1206
  addedAt: item.addedAt,
1011
1207
  updatedAt: effectiveUpdatedAt,
1012
1208
  serverUpdatedAt,
1013
- deletedAt: item.deletedAt
1209
+ deletedAt: item.deletedAt,
1210
+ categoryIds: nextCategoryIds,
1211
+ genresJson: nextGenresJson,
1212
+ status: nextStatus
1014
1213
  }).where(eq(bookshelfItems.id, existing.id)).returning().get();
1015
1214
  if (!updated) throw new Error(`Failed to update bookshelf item: ${item.platform}/${item.novelId}`);
1016
1215
  bookshelfMap.set(key, toBookshelfItem(updated));
@@ -1018,7 +1217,9 @@ var DatabaseService = class {
1018
1217
  }
1019
1218
  for (const item of input.progress ?? []) {
1020
1219
  const key = `${item.platform}\0${item.novelId}`;
1021
- const effectiveUpdatedAt = Math.min(item.updatedAt, Date.now() + CLOCK_SKEW_TOLERANCE_MS);
1220
+ const maxAllowedTime = Date.now() + CLOCK_SKEW_TOLERANCE_MS;
1221
+ const effectiveUpdatedAt = Math.min(item.updatedAt, maxAllowedTime);
1222
+ const incomingHiddenAt = typeof item.historyHiddenAt === "number" ? Math.min(item.historyHiddenAt, maxAllowedTime) : null;
1022
1223
  const existing = await tx.select().from(readingProgress).where(and(eq(readingProgress.platform, item.platform), eq(readingProgress.novelId, item.novelId))).get();
1023
1224
  if (!existing) {
1024
1225
  const serverUpdatedAt = nextCursor();
@@ -1035,32 +1236,44 @@ var DatabaseService = class {
1035
1236
  totalParagraphs: item.totalParagraphs,
1036
1237
  deviceLabel: item.deviceLabel,
1037
1238
  updatedAt: effectiveUpdatedAt,
1038
- serverUpdatedAt
1239
+ serverUpdatedAt,
1240
+ historyHiddenAt: incomingHiddenAt
1039
1241
  }).returning().get();
1040
1242
  progressMap.set(key, toReadingProgress(inserted));
1041
- } else if (effectiveUpdatedAt >= existing.updatedAt) {
1042
- const serverUpdatedAt = nextCursor();
1043
- const updated = await tx.update(readingProgress).set({
1044
- novelTitle: item.novelTitle,
1045
- coverUrl: item.coverUrl,
1046
- volumeId: item.volumeId,
1047
- volumeTitle: item.volumeTitle,
1048
- chapterId: item.chapterId,
1049
- chapterTitle: item.chapterTitle,
1050
- paragraphIndex: item.paragraphIndex,
1051
- totalParagraphs: item.totalParagraphs,
1052
- deviceLabel: item.deviceLabel,
1053
- updatedAt: effectiveUpdatedAt,
1054
- serverUpdatedAt
1055
- }).where(eq(readingProgress.id, existing.id)).returning().get();
1056
- if (!updated) throw new Error(`Failed to update reading progress: ${item.platform}/${item.novelId}`);
1057
- progressMap.set(key, toReadingProgress(updated));
1058
- } else progressMap.set(key, toReadingProgress(existing));
1243
+ } else {
1244
+ const existingHiddenAt = existing.historyHiddenAt ?? null;
1245
+ const mergedHiddenAt = incomingHiddenAt === null ? existingHiddenAt : existingHiddenAt === null ? incomingHiddenAt : Math.max(existingHiddenAt, incomingHiddenAt);
1246
+ const progressWins = effectiveUpdatedAt >= existing.updatedAt;
1247
+ if (progressWins || mergedHiddenAt !== existingHiddenAt) {
1248
+ const serverUpdatedAt = nextCursor();
1249
+ const updated = await tx.update(readingProgress).set(progressWins ? {
1250
+ novelTitle: item.novelTitle,
1251
+ coverUrl: item.coverUrl,
1252
+ volumeId: item.volumeId,
1253
+ volumeTitle: item.volumeTitle,
1254
+ chapterId: item.chapterId,
1255
+ chapterTitle: item.chapterTitle,
1256
+ paragraphIndex: item.paragraphIndex,
1257
+ totalParagraphs: item.totalParagraphs,
1258
+ deviceLabel: item.deviceLabel,
1259
+ updatedAt: effectiveUpdatedAt,
1260
+ serverUpdatedAt,
1261
+ historyHiddenAt: mergedHiddenAt
1262
+ } : {
1263
+ serverUpdatedAt,
1264
+ historyHiddenAt: mergedHiddenAt
1265
+ }).where(eq(readingProgress.id, existing.id)).returning().get();
1266
+ if (!updated) throw new Error(`Failed to update reading progress: ${item.platform}/${item.novelId}`);
1267
+ progressMap.set(key, toReadingProgress(updated));
1268
+ } else progressMap.set(key, toReadingProgress(existing));
1269
+ }
1059
1270
  }
1271
+ const enrichedBookshelf = await this.enrichBookshelfItemsWithNovelMetadata(tx, Array.from(bookshelfMap.values()));
1060
1272
  const serverTime = Math.max(Date.now(), lastCursor);
1061
1273
  return {
1062
- bookshelf: Array.from(bookshelfMap.values()),
1274
+ bookshelf: enrichedBookshelf,
1063
1275
  progress: Array.from(progressMap.values()),
1276
+ categories: Array.from(categoryMap.values()),
1064
1277
  serverTime
1065
1278
  };
1066
1279
  });
@@ -1236,6 +1449,9 @@ var StorageService = class {
1236
1449
  async listCachedNovels(platform, options) {
1237
1450
  return await this.db.listCachedNovels(platform, options);
1238
1451
  }
1452
+ async listCachedGenres(platform) {
1453
+ return await this.db.listCachedGenres(platform);
1454
+ }
1239
1455
  async getSyncState(since) {
1240
1456
  return await this.db.getSyncState(since);
1241
1457
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["zc","zd"],"sources":["../src/table.ts","../src/cookies.ts","../src/utils.ts","../src/db.ts","../src/files.ts","../src/service.ts"],"sourcesContent":["import { defineRelations } from \"drizzle-orm\";\nimport {\n\tinteger,\n\tprimaryKey,\n\tsqliteTable,\n\ttext,\n\tunique,\n\tuniqueIndex,\n} from \"drizzle-orm/sqlite-core\";\n\nexport const novels = sqliteTable(\n\t\"novels\",\n\t{\n\t\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\t\tplatform: text(\"platform\").notNull(),\n\t\tplatformId: text(\"platform_id\").notNull(),\n\t\tname: text(\"name\").notNull(),\n\t\tauthor: text(\"author\").notNull(),\n\t\tsummary: text(\"summary\").notNull(),\n\t\tcoverUrl: text(\"cover_url\").notNull(),\n\t\tstatus: text(\"status\", {\n\t\t\tenum: [\"ongoing\", \"completed\", \"unknown\"],\n\t\t}).notNull(),\n\t\tupdateAt: integer(\"update_at\").notNull(),\n\t},\n\t(table) => [\n\t\tunique(\"platform_and_pid_idx\").on(table.platform, table.platformId),\n\t],\n);\n\nexport const genres = sqliteTable(\"genres\", {\n\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\tname: text(\"name\").notNull().unique(),\n});\n\nexport const novelGenres = sqliteTable(\n\t\"novel_genres\",\n\t{\n\t\tnovelId: integer(\"novel_id\")\n\t\t\t.notNull()\n\t\t\t.references(() => novels.id, { onDelete: \"cascade\" }),\n\t\tgenreId: integer(\"genre_id\")\n\t\t\t.notNull()\n\t\t\t.references(() => genres.id, { onDelete: \"cascade\" }),\n\t},\n\t(table) => [primaryKey({ columns: [table.novelId, table.genreId] })],\n);\n\nexport const volumes = sqliteTable(\n\t\"volumes\",\n\t{\n\t\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\t\tnovelId: integer(\"novel_id\")\n\t\t\t.notNull()\n\t\t\t.references(() => novels.id, { onDelete: \"cascade\" }),\n\t\tname: text(\"name\").notNull(),\n\t\tplatform: text(\"platform\").notNull(),\n\t\tplatformId: text(\"platform_id\").notNull(),\n\t\tcoverUrl: text(\"cover_url\"),\n\t},\n\t(table) => [unique(\"novel_and_pid_idx\").on(table.novelId, table.platformId)],\n);\n\nexport const chapters = sqliteTable(\n\t\"chapters\",\n\t{\n\t\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\t\tnovelId: integer(\"novel_id\")\n\t\t\t.notNull()\n\t\t\t.references(() => novels.id, { onDelete: \"cascade\" }),\n\t\tvolumeId: integer(\"volume_id\")\n\t\t\t.notNull()\n\t\t\t.references(() => volumes.id, { onDelete: \"cascade\" }),\n\t\tplatform: text(\"platform\").notNull(),\n\t\tplatformId: text(\"platform_id\").notNull(),\n\t\tcontentHash: text(\"content_hash\"),\n\t\tname: text(\"name\").notNull(),\n\t},\n\t(table) => [unique(\"novel_and_pid_idx\").on(table.novelId, table.platformId)],\n);\n\nexport const keywordSearches = sqliteTable(\"keyword_searches\", {\n\tkeyword: text(\"keyword\").primaryKey(),\n\tplatform: text(\"platform\").notNull(),\n\tqueryTime: integer(\"query_time\").notNull(),\n\ttotal: integer(\"total\").notNull(),\n});\n\nexport const keywordNovels = sqliteTable(\n\t\"keyword_novels\",\n\t{\n\t\tkeyword: text(\"keyword\")\n\t\t\t.notNull()\n\t\t\t.references(() => keywordSearches.keyword, { onDelete: \"cascade\" }),\n\t\tnovelId: integer(\"novel_id\")\n\t\t\t.notNull()\n\t\t\t.references(() => novels.id, { onDelete: \"cascade\" }),\n\t},\n\t(table) => [primaryKey({ columns: [table.keyword, table.novelId] })],\n);\n\nexport const novelCoverMetadata = sqliteTable(\"novel_cover_metadata\", {\n\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\thash: text(\"hash\").notNull(),\n\tcontentType: text(\"content_type\").notNull(),\n\toriginalUrl: text(\"original_url\").notNull().unique(),\n\tnovelId: integer(\"novel_id\").references(() => novels.id, {\n\t\tonDelete: \"set null\",\n\t}),\n});\n\nexport const volumeCoverMetadata = sqliteTable(\"volume_cover_metadata\", {\n\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\thash: text(\"hash\").notNull(),\n\tcontentType: text(\"content_type\").notNull(),\n\toriginalUrl: text(\"original_url\").notNull().unique(),\n\tvolumeId: integer(\"volume_id\").references(() => volumes.id, {\n\t\tonDelete: \"set null\",\n\t}),\n});\n\nexport const cookies = sqliteTable(\n\t\"cookies\",\n\t{\n\t\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\t\tdomain: text(\"domain\").notNull(),\n\t\tpath: text(\"path\").notNull(),\n\t\tname: text(\"name\").notNull(),\n\t\tvalue: text(\"value\").notNull(),\n\t\texpires: integer(\"expires\"),\n\t\tmaxAge: integer(\"max_age\"),\n\t\tsecure: integer(\"secure\", { mode: \"boolean\" }),\n\t\thttpOnly: integer(\"http_only\", { mode: \"boolean\" }),\n\t\tsameSite: text(\"same_site\", { enum: [\"Strict\", \"Lax\", \"None\"] }),\n\t\tcreatedAt: integer(\"created_at\").notNull(),\n\t\tlastAccessedAt: integer(\"last_accessed_at\").notNull(),\n\t},\n\t(table) => [\n\t\tunique(\"cookie_unique_idx\").on(table.domain, table.path, table.name),\n\t],\n);\n\nexport type CookieRow = typeof cookies.$inferSelect;\n\nexport const generalCache = sqliteTable(\"general_cache\", {\n\tkey: text(\"key\").primaryKey(),\n\tvalue: text(\"value\", { mode: \"json\" }).notNull(),\n});\n\nexport const illustrationMetadata = sqliteTable(\n\t\"illustration_metadata\",\n\t{\n\t\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\t\tplatform: text(\"platform\").notNull(),\n\t\turlHash: text(\"url_hash\").notNull(),\n\t\toriginalUrl: text(\"original_url\").notNull(),\n\t\tfileHash: text(\"file_hash\"),\n\t\tcontentType: text(\"content_type\"),\n\t\tcreatedAt: integer(\"created_at\").notNull(),\n\t},\n\t(table) => [\n\t\tuniqueIndex(\"illustration_platform_url_hash_idx\").on(\n\t\t\ttable.platform,\n\t\t\ttable.urlHash,\n\t\t),\n\t],\n);\n\nexport const bookshelfItems = sqliteTable(\n\t\"bookshelf_items\",\n\t{\n\t\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\t\tplatform: text(\"platform\").notNull(),\n\t\tnovelId: text(\"novel_id\").notNull(),\n\t\ttitle: text(\"title\").notNull(),\n\t\tauthor: text(\"author\").notNull(),\n\t\tcoverUrl: text(\"cover_url\").notNull(),\n\t\taddedAt: integer(\"added_at\").notNull(),\n\t\tupdatedAt: integer(\"updated_at\").notNull(),\n\t\tserverUpdatedAt: integer(\"server_updated_at\").notNull(),\n\t\tdeletedAt: integer(\"deleted_at\"),\n\t},\n\t(table) => [\n\t\tuniqueIndex(\"bookshelf_platform_novel_idx\").on(\n\t\t\ttable.platform,\n\t\t\ttable.novelId,\n\t\t),\n\t],\n);\n\nexport const readingProgress = sqliteTable(\n\t\"reading_progress\",\n\t{\n\t\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\t\tplatform: text(\"platform\").notNull(),\n\t\tnovelId: text(\"novel_id\").notNull(),\n\t\tnovelTitle: text(\"novel_title\").notNull(),\n\t\tcoverUrl: text(\"cover_url\").notNull(),\n\t\tvolumeId: text(\"volume_id\").notNull(),\n\t\tvolumeTitle: text(\"volume_title\").notNull(),\n\t\tchapterId: text(\"chapter_id\").notNull(),\n\t\tchapterTitle: text(\"chapter_title\").notNull(),\n\t\tparagraphIndex: integer(\"paragraph_index\").notNull(),\n\t\ttotalParagraphs: integer(\"total_paragraphs\").notNull(),\n\t\tdeviceLabel: text(\"device_label\").notNull(),\n\t\tupdatedAt: integer(\"updated_at\").notNull(),\n\t\tserverUpdatedAt: integer(\"server_updated_at\").notNull(),\n\t},\n\t(table) => [\n\t\tuniqueIndex(\"reading_progress_platform_novel_idx\").on(\n\t\t\ttable.platform,\n\t\t\ttable.novelId,\n\t\t),\n\t],\n);\n\nexport const relations = defineRelations(\n\t{\n\t\tnovels,\n\t\tgenres,\n\t\tnovelGenres,\n\t\tvolumes,\n\t\tchapters,\n\t\tkeywordSearches,\n\t\tkeywordNovels,\n\t\tnovelCoverMetadata,\n\t\tvolumeCoverMetadata,\n\t\tcookies,\n\t\tgeneralCache,\n\t\tillustrationMetadata,\n\t\tbookshelfItems,\n\t\treadingProgress,\n\t},\n\t(r) => ({\n\t\tnovels: {\n\t\t\tgenres: r.many.genres({\n\t\t\t\tfrom: r.novels.id.through(r.novelGenres.novelId),\n\t\t\t\tto: r.genres.id.through(r.novelGenres.genreId),\n\t\t\t}),\n\t\t\tvolumes: r.many.volumes({\n\t\t\t\tfrom: r.novels.id,\n\t\t\t\tto: r.volumes.novelId,\n\t\t\t}),\n\t\t\tcover: r.one.novelCoverMetadata({\n\t\t\t\tfrom: r.novels.id,\n\t\t\t\tto: r.novelCoverMetadata.novelId,\n\t\t\t}),\n\t\t},\n\t\tgenres: {\n\t\t\tnovels: r.many.novels(),\n\t\t},\n\t\tvolumes: {\n\t\t\tnovel: r.one.novels(),\n\t\t\tchapters: r.many.chapters({\n\t\t\t\tfrom: r.volumes.id,\n\t\t\t\tto: r.chapters.volumeId,\n\t\t\t}),\n\t\t\tcover: r.one.volumeCoverMetadata({\n\t\t\t\tfrom: r.volumes.id,\n\t\t\t\tto: r.volumeCoverMetadata.volumeId,\n\t\t\t}),\n\t\t},\n\t\tnovelCoverMetadata: {\n\t\t\tnovel: r.one.novels({\n\t\t\t\tfrom: r.novelCoverMetadata.novelId,\n\t\t\t\tto: r.novels.id,\n\t\t\t}),\n\t\t},\n\t\tvolumeCoverMetadata: {\n\t\t\tvolume: r.one.volumes({\n\t\t\t\tfrom: r.volumeCoverMetadata.volumeId,\n\t\t\t\tto: r.volumes.id,\n\t\t\t}),\n\t\t},\n\t\tchapters: {\n\t\t\tnovel: r.one.novels({\n\t\t\t\tfrom: r.chapters.novelId,\n\t\t\t\tto: r.novels.id,\n\t\t\t}),\n\t\t\tvolume: r.one.volumes(),\n\t\t},\n\t\tkeywordSearches: {\n\t\t\tnovels: r.many.novels({\n\t\t\t\tfrom: r.keywordSearches.keyword.through(r.keywordNovels.keyword),\n\t\t\t\tto: r.novels.id.through(r.keywordNovels.novelId),\n\t\t\t}),\n\t\t},\n\t}),\n);\n","import {\n\ttype Cookie,\n\ttype CookieOptions,\n\ttype CookiesInit,\n\ttype CookiesStore,\n\tcookieStoreSign,\n\tisCookiesStore,\n\tmatchesDomain,\n\tmatchesPath,\n} from \"@acanthis-dec/browser-fetch\";\nimport { eq } from \"drizzle-orm\";\nimport type { DatabaseService, DrizzleInstance } from \"./db\";\nimport { type CookieRow, cookies } from \"./table\";\n\nexport class DatabaseCookieStore implements CookiesStore {\n\tprivate db: DrizzleInstance;\n\t[cookieStoreSign] = true as const;\n\n\tconstructor(dbService: DatabaseService) {\n\t\tthis.db = dbService.db;\n\t}\n\n\tasync set(\n\t\tname: string,\n\t\tvalue: string,\n\t\toptions?: CookieOptions,\n\t): Promise<void> {\n\t\tconst cookie: Omit<CookieRow, \"id\"> = {\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tdomain: options?.domain ?? \"\",\n\t\t\tpath: options?.path ?? \"/\",\n\t\t\texpires: options?.expires?.getTime() ?? null,\n\t\t\tmaxAge: options?.maxAge ?? null,\n\t\t\tsecure: options?.secure ?? false,\n\t\t\thttpOnly: options?.httpOnly ?? false,\n\t\t\tsameSite: options?.sameSite ?? \"Lax\",\n\t\t\tcreatedAt: Date.now(),\n\t\t\tlastAccessedAt: Date.now(),\n\t\t};\n\t\tawait this.db\n\t\t\t.insert(cookies)\n\t\t\t.values(cookie)\n\t\t\t.onConflictDoUpdate({\n\t\t\t\ttarget: [cookies.domain, cookies.path, cookies.name],\n\t\t\t\tset: {\n\t\t\t\t\tvalue: cookie.value,\n\t\t\t\t\texpires: cookie.expires,\n\t\t\t\t\tmaxAge: cookie.maxAge,\n\t\t\t\t\tsecure: cookie.secure,\n\t\t\t\t\thttpOnly: cookie.httpOnly,\n\t\t\t\t\tsameSite: cookie.sameSite,\n\t\t\t\t\tcreatedAt: cookie.createdAt,\n\t\t\t\t\tlastAccessedAt: Date.now(),\n\t\t\t\t},\n\t\t\t})\n\t\t\t.run();\n\t}\n\tasync get(\n\t\tname: string,\n\t\tdomain?: string,\n\t\tpath?: string,\n\t): Promise<string | null> {\n\t\tconst result = await this.db.query.cookies.findFirst({\n\t\t\twhere: {\n\t\t\t\tname,\n\t\t\t\tdomain: domain ?? \"\",\n\t\t\t\tpath: path ?? \"/\",\n\t\t\t},\n\t\t});\n\t\tif (result) {\n\t\t\tawait this.db\n\t\t\t\t.update(cookies)\n\t\t\t\t.set({ lastAccessedAt: Date.now() })\n\t\t\t\t.where(eq(cookies.id, result.id))\n\t\t\t\t.run();\n\t\t\treturn result.value;\n\t\t}\n\t\tconst candidates = await this.db.query.cookies.findMany({\n\t\t\twhere: {\n\t\t\t\tname,\n\t\t\t},\n\t\t});\n\t\tconst hit = candidates.find((cookie) => {\n\t\t\tif (domain && cookie.domain && !matchesDomain(cookie.domain, domain))\n\t\t\t\treturn false;\n\t\t\tif (path && cookie.path && !matchesPath(cookie.path, path)) return false;\n\t\t\treturn true;\n\t\t});\n\n\t\tif (!hit) return null;\n\n\t\tawait this.db\n\t\t\t.update(cookies)\n\t\t\t.set({ lastAccessedAt: Date.now() })\n\t\t\t.where(eq(cookies.id, hit.id))\n\t\t\t.run();\n\n\t\treturn hit.value;\n\t}\n\tasync getCookie(\n\t\tname: string,\n\t\tdomain?: string,\n\t\tpath?: string,\n\t): Promise<Cookie | null> {\n\t\tconst result = await this.db.query.cookies.findFirst({\n\t\t\twhere: {\n\t\t\t\tname,\n\t\t\t\tdomain: domain ?? \"\",\n\t\t\t\tpath: path ?? \"/\",\n\t\t\t},\n\t\t});\n\t\tif (result) {\n\t\t\tawait this.db\n\t\t\t\t.update(cookies)\n\t\t\t\t.set({ lastAccessedAt: Date.now() })\n\t\t\t\t.where(eq(cookies.id, result.id))\n\t\t\t\t.run();\n\t\t\treturn {\n\t\t\t\tname: result.name,\n\t\t\t\tvalue: result.value,\n\t\t\t\tdomain: result.domain,\n\t\t\t\tpath: result.path,\n\t\t\t\texpires: result.expires ? new Date(result.expires) : undefined,\n\t\t\t\tmaxAge: result.maxAge ?? undefined,\n\t\t\t\tsecure: result.secure ?? undefined,\n\t\t\t\thttpOnly: result.httpOnly ?? undefined,\n\t\t\t\tsameSite: result.sameSite ?? \"Lax\",\n\t\t\t};\n\t\t}\n\t\tconst candidates = await this.db.query.cookies.findMany({\n\t\t\twhere: {\n\t\t\t\tname,\n\t\t\t},\n\t\t});\n\t\tconst hit = candidates.find((cookie) => {\n\t\t\tif (domain && cookie.domain && !matchesDomain(cookie.domain, domain))\n\t\t\t\treturn false;\n\t\t\tif (path && cookie.path && !matchesPath(cookie.path, path)) return false;\n\t\t\treturn true;\n\t\t});\n\n\t\tif (!hit) return null;\n\n\t\tawait this.db\n\t\t\t.update(cookies)\n\t\t\t.set({ lastAccessedAt: Date.now() })\n\t\t\t.where(eq(cookies.id, hit.id))\n\t\t\t.run();\n\n\t\treturn {\n\t\t\tname: hit.name,\n\t\t\tvalue: hit.value,\n\t\t\tdomain: hit.domain,\n\t\t\tpath: hit.path,\n\t\t\texpires: hit.expires ? new Date(hit.expires) : undefined,\n\t\t\tmaxAge: hit.maxAge ?? undefined,\n\t\t\tsecure: hit.secure ?? undefined,\n\t\t\thttpOnly: hit.httpOnly ?? undefined,\n\t\t\tsameSite: hit.sameSite ?? \"Lax\",\n\t\t};\n\t}\n\tasync delete(name: string, domain?: string, path?: string): Promise<boolean> {\n\t\tconst result = await this.db.query.cookies.findFirst({\n\t\t\twhere: {\n\t\t\t\tname,\n\t\t\t\tdomain: domain ?? \"\",\n\t\t\t\tpath: path ?? \"/\",\n\t\t\t},\n\t\t});\n\t\tif (result) {\n\t\t\tawait this.db.delete(cookies).where(eq(cookies.id, result.id)).run();\n\t\t\treturn true;\n\t\t}\n\t\tconst candidates = await this.db.query.cookies.findMany({\n\t\t\twhere: {\n\t\t\t\tname,\n\t\t\t},\n\t\t});\n\t\tconst hit = candidates.find((cookie) => {\n\t\t\tif (domain && cookie.domain && !matchesDomain(cookie.domain, domain))\n\t\t\t\treturn false;\n\t\t\tif (path && cookie.path && !matchesPath(cookie.path, path)) return false;\n\t\t\treturn true;\n\t\t});\n\n\t\tif (!hit) return false;\n\n\t\tawait this.db.delete(cookies).where(eq(cookies.id, hit.id)).run();\n\t\treturn true;\n\t}\n\tasync clear(domain?: string, path?: string): Promise<void> {\n\t\tif (!domain && !path) {\n\t\t\tawait this.db.delete(cookies).run();\n\t\t\treturn;\n\t\t}\n\t\tawait this.db.transaction(async (tx) => {\n\t\t\tconst candidates = await tx.query.cookies.findMany();\n\t\t\tconst toDelete = candidates.filter((cookie) => {\n\t\t\t\tif (domain && cookie.domain && !matchesDomain(cookie.domain, domain))\n\t\t\t\t\treturn false;\n\t\t\t\tif (path && cookie.path && !matchesPath(cookie.path, path))\n\t\t\t\t\treturn false;\n\t\t\t\treturn true;\n\t\t\t});\n\t\t\tfor (const cookie of toDelete) {\n\t\t\t\tawait tx.delete(cookies).where(eq(cookies.id, cookie.id)).run();\n\t\t\t}\n\t\t});\n\t}\n\tasync has(name: string, domain?: string, path?: string): Promise<boolean> {\n\t\treturn (await this.get(name, domain, path)) !== null;\n\t}\n\tasync getForUrl(url: string | URL): Promise<Cookie[]> {\n\t\tconst parsedUrl = typeof url === \"string\" ? new URL(url) : url;\n\t\tconst hostname = parsedUrl.hostname;\n\t\tconst pathname = parsedUrl.pathname;\n\t\tconst secure = parsedUrl.protocol === \"https:\";\n\t\tconst candidates = await this.db.query.cookies.findMany();\n\t\treturn candidates\n\t\t\t.filter((cookie) => {\n\t\t\t\tconst now = Date.now();\n\t\t\t\tif (cookie.secure && !secure) return false;\n\t\t\t\tif (cookie.domain && !matchesDomain(cookie.domain, hostname))\n\t\t\t\t\treturn false;\n\t\t\t\tif (cookie.path && !matchesPath(cookie.path, pathname)) return false;\n\t\t\t\tif (cookie.expires && cookie.expires < now) return false;\n\t\t\t\tif (cookie.maxAge) {\n\t\t\t\t\tconst age = (now - cookie.createdAt) / 1000;\n\t\t\t\t\tif (age > cookie.maxAge) return false;\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t})\n\t\t\t.map((cookie) => ({\n\t\t\t\tname: cookie.name,\n\t\t\t\tvalue: cookie.value,\n\t\t\t\tdomain: cookie.domain,\n\t\t\t\tpath: cookie.path,\n\t\t\t\texpires: cookie.expires ? new Date(cookie.expires) : undefined,\n\t\t\t\tmaxAge: cookie.maxAge ?? undefined,\n\t\t\t\tsecure: cookie.secure ?? undefined,\n\t\t\t\thttpOnly: cookie.httpOnly ?? undefined,\n\t\t\t\tsameSite: cookie.sameSite ?? \"Lax\",\n\t\t\t}));\n\t}\n\tasync update(init: CookiesInit): Promise<void> {\n\t\tif (isCookiesStore(init)) {\n\t\t\tfor await (const cookie of init) {\n\t\t\t\tawait this.set(cookie.name, cookie.value, {\n\t\t\t\t\tdomain: cookie.domain,\n\t\t\t\t\tpath: cookie.path,\n\t\t\t\t\texpires: cookie.expires,\n\t\t\t\t\tmaxAge: cookie.maxAge,\n\t\t\t\t\tsecure: cookie.secure,\n\t\t\t\t\thttpOnly: cookie.httpOnly,\n\t\t\t\t\tsameSite: cookie.sameSite ?? \"Lax\",\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (Array.isArray(init)) {\n\t\t\tfor (const cookie of init) {\n\t\t\t\tawait this.set(cookie.name, cookie.value, {\n\t\t\t\t\tdomain: cookie.domain,\n\t\t\t\t\tpath: cookie.path,\n\t\t\t\t\texpires: cookie.expires,\n\t\t\t\t\tmaxAge: cookie.maxAge,\n\t\t\t\t\tsecure: cookie.secure,\n\t\t\t\t\thttpOnly: cookie.httpOnly,\n\t\t\t\t\tsameSite: cookie.sameSite ?? \"Lax\",\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (typeof init === \"object\") {\n\t\t\tif (Symbol.iterator in init) {\n\t\t\t\tfor (const [name, value] of init as Iterable<[string, string]>) {\n\t\t\t\t\tawait this.set(name, value);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (const [name, value] of Object.entries(init)) {\n\t\t\t\t\tawait this.set(name, value);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t[Symbol.asyncIterator](): AsyncIterator<Cookie> {\n\t\tconst allCookies = this.db.query.cookies.findMany();\n\t\tlet index = 0;\n\t\treturn {\n\t\t\tnext: async () => {\n\t\t\t\tconst cookies = await allCookies;\n\t\t\t\tif (index < cookies.length) {\n\t\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: We check index against cookies.length, so this is safe\n\t\t\t\t\tconst cookie = cookies[index++]!;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\tname: cookie.name,\n\t\t\t\t\t\t\tvalue: cookie.value,\n\t\t\t\t\t\t\tdomain: cookie.domain,\n\t\t\t\t\t\t\tpath: cookie.path,\n\t\t\t\t\t\t\texpires: cookie.expires ? new Date(cookie.expires) : undefined,\n\t\t\t\t\t\t\tmaxAge: cookie.maxAge ?? undefined,\n\t\t\t\t\t\t\tsecure: cookie.secure ?? undefined,\n\t\t\t\t\t\t\thttpOnly: cookie.httpOnly ?? undefined,\n\t\t\t\t\t\t\tsameSite: cookie.sameSite ?? \"Lax\",\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn { done: true, value: undefined };\n\t\t\t},\n\t\t};\n\t}\n}\n","import { createHash } from \"node:crypto\";\nimport { zstdCompress as zc, zstdDecompress as zd } from \"node:zlib\";\n\nexport const zstdCompress = (data: Buffer): Promise<Buffer> => {\n\treturn new Promise((resolve, reject) => {\n\t\tzc(data, (err, compressedData) => {\n\t\t\tif (err) {\n\t\t\t\treject(err);\n\t\t\t} else {\n\t\t\t\tresolve(compressedData);\n\t\t\t}\n\t\t});\n\t});\n};\n\nexport const zstdDecompress = (data: Buffer): Promise<Buffer> => {\n\treturn new Promise((resolve, reject) => {\n\t\tzd(data, (err, decompressedData) => {\n\t\t\tif (err) {\n\t\t\t\treject(err);\n\t\t\t} else {\n\t\t\t\tresolve(decompressedData);\n\t\t\t}\n\t\t});\n\t});\n};\n\nexport function getCoverHash(data: Buffer): string {\n\treturn createHash(\"md5\").update(data).digest(\"hex\");\n}\n\nexport function getContentHash(content: string): string {\n\treturn createHash(\"md5\").update(content).digest(\"hex\");\n}\n\nexport function getUrlHash(url: string): string {\n\treturn createHash(\"md5\").update(url).digest(\"hex\");\n}\n\nexport function getExtFromContentType(contentType: string): string {\n\tif (contentType.includes(\"jpeg\") || contentType.includes(\"jpg\")) return \"jpg\";\n\tif (contentType.includes(\"png\")) return \"png\";\n\tif (contentType.includes(\"gif\")) return \"gif\";\n\tif (contentType.includes(\"webp\")) return \"webp\";\n\tif (contentType.includes(\"avif\")) return \"avif\";\n\treturn \"bin\";\n}\n","import { existsSync, mkdirSync, rmSync, statSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport type {\n\tBookshelfItem,\n\tChapter,\n\tNovel,\n\tNovelInfo,\n\tNovelSearchResult,\n\tReadingProgress,\n\tVolume,\n} from \"@acanthis-dec/core\";\nimport { type Client, createClient } from \"@libsql/client\";\nimport {\n\tand,\n\tcount,\n\tdesc,\n\teq,\n\tgt,\n\tinArray,\n\tisNull,\n\tmax,\n\tne,\n\tnotInArray,\n} from \"drizzle-orm\";\nimport { drizzle } from \"drizzle-orm/libsql\";\nimport { migrate } from \"drizzle-orm/libsql/migrator\";\nimport type { z } from \"zod\";\nimport {\n\tbookshelfItems,\n\tchapters,\n\tgeneralCache,\n\tgenres,\n\tillustrationMetadata,\n\tkeywordNovels,\n\tkeywordSearches,\n\tnovelCoverMetadata,\n\tnovelGenres,\n\tnovels,\n\treadingProgress,\n\trelations,\n\tvolumeCoverMetadata,\n\tvolumes,\n} from \"./table\";\nimport type {\n\tDataWithUpdatedAt,\n\tListNovelsOptions,\n\tMergeSyncStateInput,\n\tMergeSyncStateResult,\n\tNovelCoverMetadata,\n\tPaginatedNovels,\n\tSyncStateResult,\n\tVolumeCoverMetadata,\n} from \"./type\";\nimport { getUrlHash } from \"./utils\";\n\nexport type MigrationOptions = {\n\tenabled?: boolean;\n\tdirectory?: string;\n};\n\nexport type DatabaseOptions = {\n\tpath: string;\n\tmigrations?: MigrationOptions;\n};\n\nfunction getDrizzle(client: Client) {\n\treturn drizzle({\n\t\tclient,\n\t\trelations,\n\t});\n}\n\nexport type DrizzleInstance = ReturnType<typeof getDrizzle>;\n\nconst CLOCK_SKEW_TOLERANCE_MS = 60_000;\n\nfunction toBookshelfItem(\n\trow: typeof bookshelfItems.$inferSelect,\n): BookshelfItem {\n\treturn {\n\t\tplatform: row.platform,\n\t\tnovelId: row.novelId,\n\t\ttitle: row.title,\n\t\tauthor: row.author,\n\t\tcoverUrl: row.coverUrl,\n\t\taddedAt: row.addedAt,\n\t\tupdatedAt: row.updatedAt,\n\t\tdeletedAt: row.deletedAt,\n\t};\n}\n\nfunction toReadingProgress(\n\trow: typeof readingProgress.$inferSelect,\n): ReadingProgress {\n\treturn {\n\t\tplatform: row.platform,\n\t\tnovelId: row.novelId,\n\t\tnovelTitle: row.novelTitle,\n\t\tcoverUrl: row.coverUrl,\n\t\tvolumeId: row.volumeId,\n\t\tvolumeTitle: row.volumeTitle,\n\t\tchapterId: row.chapterId,\n\t\tchapterTitle: row.chapterTitle,\n\t\tparagraphIndex: row.paragraphIndex,\n\t\ttotalParagraphs: row.totalParagraphs,\n\t\tdeviceLabel: row.deviceLabel,\n\t\tupdatedAt: row.updatedAt,\n\t};\n}\n\nexport class DatabaseService {\n\tprivate client: Client;\n\tprivate readyPromise: Promise<void>;\n\tdb: DrizzleInstance;\n\n\tconstructor(options: DatabaseOptions) {\n\t\tconst parentDir = dirname(resolve(options.path));\n\t\tif (!existsSync(parentDir)) {\n\t\t\tmkdirSync(parentDir, { recursive: true });\n\t\t} else if (existsSync(parentDir) && statSync(parentDir).isFile() === true) {\n\t\t\trmSync(parentDir);\n\t\t\tmkdirSync(parentDir, { recursive: true });\n\t\t}\n\t\tthis.client = createClient({\n\t\t\turl: `file:${options.path}`,\n\t\t});\n\t\tthis.db = getDrizzle(this.client);\n\t\tthis.readyPromise = this._init(options);\n\t}\n\n\tprivate async _init(options: DatabaseOptions): Promise<void> {\n\t\tawait this.client.execute(\"PRAGMA journal_mode = WAL;\");\n\t\tif (options.migrations?.enabled ?? true) {\n\t\t\tawait this._migrate(options.migrations?.directory);\n\t\t}\n\t}\n\n\tprivate async _migrate(directory?: string): Promise<void> {\n\t\tif (!this.db) throw new Error(\"Database not initialized\");\n\t\tawait migrate(this.db, {\n\t\t\tmigrationsFolder: directory || \"migrations\",\n\t\t});\n\t}\n\n\tprivate async ensureReady(): Promise<void> {\n\t\tawait this.readyPromise;\n\t}\n\n\tasync addSearchResult(\n\t\tkeyword: string,\n\t\tplatform: string,\n\t\tresults: NovelSearchResult[],\n\t) {\n\t\tawait this.ensureReady();\n\t\tawait this.db.transaction(async (tx) => {\n\t\t\tawait tx\n\t\t\t\t.insert(keywordSearches)\n\t\t\t\t.values({\n\t\t\t\t\tkeyword,\n\t\t\t\t\tplatform,\n\t\t\t\t\tqueryTime: Date.now(),\n\t\t\t\t\ttotal: results.length,\n\t\t\t\t})\n\t\t\t\t.onConflictDoUpdate({\n\t\t\t\t\ttarget: keywordSearches.keyword,\n\t\t\t\t\tset: {\n\t\t\t\t\t\tqueryTime: Date.now(),\n\t\t\t\t\t\ttotal: results.length,\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\t.run();\n\n\t\t\tfor (const novel of results) {\n\t\t\t\tconst inserted = await tx\n\t\t\t\t\t.insert(novels)\n\t\t\t\t\t.values({\n\t\t\t\t\t\tplatform: novel.platform,\n\t\t\t\t\t\tplatformId: novel.id,\n\t\t\t\t\t\tname: novel.title,\n\t\t\t\t\t\tcoverUrl: novel.coverUrl ?? \"\",\n\t\t\t\t\t\tauthor: \"\",\n\t\t\t\t\t\tsummary: \"\",\n\t\t\t\t\t\tstatus: \"unknown\",\n\t\t\t\t\t\tupdateAt: Date.now(),\n\t\t\t\t\t})\n\t\t\t\t\t.onConflictDoUpdate({\n\t\t\t\t\t\ttarget: [novels.platform, novels.platformId],\n\t\t\t\t\t\tset: {\n\t\t\t\t\t\t\tname: novel.title,\n\t\t\t\t\t\t\tcoverUrl: novel.coverUrl ?? \"\",\n\t\t\t\t\t\t\tupdateAt: Date.now(),\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t\t.returning({ id: novels.id })\n\t\t\t\t\t.get();\n\n\t\t\t\tconst novelId = inserted.id;\n\t\t\t\tif (novelId) {\n\t\t\t\t\tawait tx\n\t\t\t\t\t\t.insert(keywordNovels)\n\t\t\t\t\t\t.values({\n\t\t\t\t\t\t\tnovelId,\n\t\t\t\t\t\t\tkeyword,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.onConflictDoNothing()\n\t\t\t\t\t\t.run();\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tasync searchNovels(\n\t\tkeyword: string,\n\t\tplatform: string,\n\t): Promise<DataWithUpdatedAt<NovelSearchResult[] | undefined>> {\n\t\tawait this.ensureReady();\n\t\tconst minQueryTime = Date.now() - 48 * 60 * 60 * 1000; // 48 hours\n\n\t\tconst searchRecord = await this.db.query.keywordSearches\n\t\t\t.findFirst({\n\t\t\t\twhere: {\n\t\t\t\t\tkeyword,\n\t\t\t\t\tplatform,\n\t\t\t\t\tqueryTime: {\n\t\t\t\t\t\tgte: minQueryTime,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\twith: {\n\t\t\t\t\tnovels: {\n\t\t\t\t\t\tcolumns: {\n\t\t\t\t\t\t\tplatform: true,\n\t\t\t\t\t\t\tplatformId: true,\n\t\t\t\t\t\t\tname: true,\n\t\t\t\t\t\t\tcoverUrl: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t})\n\t\t\t.execute();\n\n\t\treturn {\n\t\t\tdata:\n\t\t\t\tsearchRecord?.novels.map((novel) => ({\n\t\t\t\t\tplatform: novel.platform,\n\t\t\t\t\tid: novel.platformId,\n\t\t\t\t\ttitle: novel.name,\n\t\t\t\t\tcoverUrl: novel.coverUrl,\n\t\t\t\t})) || undefined,\n\t\t\tupdatedAt: searchRecord?.queryTime || 0,\n\t\t};\n\t}\n\n\tasync addNovelCache(novel: Novel) {\n\t\tawait this.ensureReady();\n\t\tawait this.db.transaction(async (tx) => {\n\t\t\tconst { id: novelId } = await tx\n\t\t\t\t.insert(novels)\n\t\t\t\t.values({\n\t\t\t\t\tplatform: novel.platform,\n\t\t\t\t\tplatformId: novel.id,\n\t\t\t\t\tname: novel.title,\n\t\t\t\t\tcoverUrl: novel.coverUrl ?? \"\",\n\t\t\t\t\tauthor: novel.author ?? \"\",\n\t\t\t\t\tsummary: novel.summary ?? \"\",\n\t\t\t\t\tstatus: novel.status ?? \"unknown\",\n\t\t\t\t\tupdateAt: Date.now(),\n\t\t\t\t})\n\t\t\t\t.onConflictDoUpdate({\n\t\t\t\t\ttarget: [novels.platform, novels.platformId],\n\t\t\t\t\tset: {\n\t\t\t\t\t\tname: novel.title,\n\t\t\t\t\t\tcoverUrl: novel.coverUrl ?? \"\",\n\t\t\t\t\t\tauthor: novel.author ?? \"\",\n\t\t\t\t\t\tsummary: novel.summary ?? \"\",\n\t\t\t\t\t\tstatus: novel.status ?? \"unknown\",\n\t\t\t\t\t\tupdateAt: Date.now(),\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\t.returning({ id: novels.id })\n\t\t\t\t.get();\n\n\t\t\tfor (const genre of novel.genres) {\n\t\t\t\tconst { id: genreId } = await tx\n\t\t\t\t\t.insert(genres)\n\t\t\t\t\t.values({\n\t\t\t\t\t\tname: genre,\n\t\t\t\t\t})\n\t\t\t\t\t.onConflictDoUpdate({\n\t\t\t\t\t\ttarget: genres.name,\n\t\t\t\t\t\tset: {\n\t\t\t\t\t\t\tname: genre,\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t\t.returning({ id: genres.id })\n\t\t\t\t\t.get();\n\t\t\t\tawait tx\n\t\t\t\t\t.insert(novelGenres)\n\t\t\t\t\t.values({\n\t\t\t\t\t\tnovelId,\n\t\t\t\t\t\tgenreId,\n\t\t\t\t\t})\n\t\t\t\t\t.onConflictDoNothing()\n\t\t\t\t\t.run();\n\t\t\t}\n\n\t\t\tconst volumePlatformIds: string[] = [];\n\t\t\tconst chapterPlatformIds: string[] = [];\n\n\t\t\tfor (const volume of novel.volumes) {\n\t\t\t\tvolumePlatformIds.push(volume.id);\n\t\t\t\tconst { id: volumeId } = await tx\n\t\t\t\t\t.insert(volumes)\n\t\t\t\t\t.values({\n\t\t\t\t\t\tnovelId,\n\t\t\t\t\t\tname: volume.title,\n\t\t\t\t\t\tplatform: novel.platform,\n\t\t\t\t\t\tplatformId: volume.id,\n\t\t\t\t\t\tcoverUrl: volume.coverUrl ?? \"\",\n\t\t\t\t\t})\n\t\t\t\t\t.onConflictDoUpdate({\n\t\t\t\t\t\ttarget: [volumes.novelId, volumes.platformId],\n\t\t\t\t\t\tset: {\n\t\t\t\t\t\t\tname: volume.title,\n\t\t\t\t\t\t\tcoverUrl: volume.coverUrl ?? \"\",\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t\t.returning({ id: volumes.id })\n\t\t\t\t\t.get();\n\t\t\t\tfor (const chapter of volume.chapters) {\n\t\t\t\t\tchapterPlatformIds.push(chapter.id);\n\t\t\t\t\tawait tx\n\t\t\t\t\t\t.insert(chapters)\n\t\t\t\t\t\t.values({\n\t\t\t\t\t\t\tnovelId,\n\t\t\t\t\t\t\tvolumeId,\n\t\t\t\t\t\t\tname: chapter.title,\n\t\t\t\t\t\t\tplatform: novel.platform,\n\t\t\t\t\t\t\tplatformId: chapter.id,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.onConflictDoUpdate({\n\t\t\t\t\t\t\ttarget: [chapters.novelId, chapters.platformId],\n\t\t\t\t\t\t\tset: {\n\t\t\t\t\t\t\t\tvolumeId,\n\t\t\t\t\t\t\t\tname: chapter.title,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.run();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (chapterPlatformIds.length > 0) {\n\t\t\t\tawait tx\n\t\t\t\t\t.delete(chapters)\n\t\t\t\t\t.where(\n\t\t\t\t\t\tand(\n\t\t\t\t\t\t\teq(chapters.novelId, novelId),\n\t\t\t\t\t\t\tnotInArray(chapters.platformId, chapterPlatformIds),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\t.run();\n\t\t\t} else {\n\t\t\t\tawait tx.delete(chapters).where(eq(chapters.novelId, novelId)).run();\n\t\t\t}\n\n\t\t\tif (volumePlatformIds.length > 0) {\n\t\t\t\tawait tx\n\t\t\t\t\t.delete(volumes)\n\t\t\t\t\t.where(\n\t\t\t\t\t\tand(\n\t\t\t\t\t\t\teq(volumes.novelId, novelId),\n\t\t\t\t\t\t\tnotInArray(volumes.platformId, volumePlatformIds),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\t.run();\n\t\t\t} else {\n\t\t\t\tawait tx.delete(volumes).where(eq(volumes.novelId, novelId)).run();\n\t\t\t}\n\t\t});\n\t}\n\n\tasync getNovelCache(\n\t\tplatform: string,\n\t\tplatformId: string,\n\t): Promise<DataWithUpdatedAt<Novel | null>> {\n\t\tawait this.ensureReady();\n\t\tconst novelRecord = await this.db.query.novels\n\t\t\t.findFirst({\n\t\t\t\twhere: {\n\t\t\t\t\tplatform,\n\t\t\t\t\tplatformId,\n\t\t\t\t},\n\t\t\t\twith: {\n\t\t\t\t\tgenres: true,\n\t\t\t\t\tvolumes: {\n\t\t\t\t\t\torderBy: {\n\t\t\t\t\t\t\tid: \"asc\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\twith: {\n\t\t\t\t\t\t\tchapters: {\n\t\t\t\t\t\t\t\torderBy: {\n\t\t\t\t\t\t\t\t\tid: \"asc\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t})\n\t\t\t.execute();\n\n\t\tif (!novelRecord) {\n\t\t\treturn {\n\t\t\t\tdata: null,\n\t\t\t\tupdatedAt: 0,\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tdata: {\n\t\t\t\tplatform: novelRecord.platform,\n\t\t\t\tid: novelRecord.platformId,\n\t\t\t\ttitle: novelRecord.name,\n\t\t\t\tcoverUrl: novelRecord.coverUrl,\n\t\t\t\tauthor: novelRecord.author,\n\t\t\t\tsummary: novelRecord.summary,\n\t\t\t\tstatus: novelRecord.status,\n\t\t\t\tgenres: novelRecord.genres.map((g) => g.name),\n\t\t\t\tvolumes: novelRecord.volumes.map((v) => ({\n\t\t\t\t\tid: v.platformId,\n\t\t\t\t\tplatform: novelRecord.platform,\n\t\t\t\t\ttitle: v.name,\n\t\t\t\t\tcoverUrl: v.coverUrl ?? \"\",\n\t\t\t\t\tnovelId: novelRecord.platformId,\n\t\t\t\t\tchapters: v.chapters.map((c) => ({\n\t\t\t\t\t\tid: c.platformId,\n\t\t\t\t\t\tplatform: novelRecord.platform,\n\t\t\t\t\t\ttitle: c.name,\n\t\t\t\t\t})),\n\t\t\t\t})),\n\t\t\t},\n\t\t\tupdatedAt: novelRecord.updateAt,\n\t\t};\n\t}\n\n\tasync getVolumeMeta(\n\t\tplatform: string,\n\t\tplatformId: string,\n\t): Promise<Volume | undefined> {\n\t\tawait this.ensureReady();\n\t\tconst volumeRecord = await this.db.query.volumes\n\t\t\t.findFirst({\n\t\t\t\twhere: {\n\t\t\t\t\tplatform,\n\t\t\t\t\tplatformId,\n\t\t\t\t},\n\t\t\t\twith: {\n\t\t\t\t\tnovel: true,\n\t\t\t\t\tchapters: {\n\t\t\t\t\t\torderBy: {\n\t\t\t\t\t\t\tid: \"asc\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\torderBy: {\n\t\t\t\t\tid: \"asc\",\n\t\t\t\t},\n\t\t\t})\n\t\t\t.execute();\n\n\t\tif (!volumeRecord) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tid: volumeRecord.platformId,\n\t\t\tplatform: volumeRecord.platform,\n\t\t\ttitle: volumeRecord.name,\n\t\t\tnovelId: volumeRecord.novel?.platformId ?? \"\",\n\t\t\tcoverUrl: volumeRecord.coverUrl ?? \"\",\n\t\t\tchapters: [],\n\t\t};\n\t}\n\n\tasync getChapterFromTitle(\n\t\ttitle: string,\n\t): Promise<Partial<Chapter> | undefined> {\n\t\tawait this.ensureReady();\n\t\tconst chapterRecord = await this.db.query.chapters\n\t\t\t.findFirst({\n\t\t\t\twhere: {\n\t\t\t\t\tname: title,\n\t\t\t\t},\n\t\t\t})\n\t\t\t.execute();\n\n\t\tif (!chapterRecord) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tid: chapterRecord.platformId,\n\t\t\ttitle: chapterRecord.name,\n\t\t};\n\t}\n\n\tasync getChapterFromId(\n\t\tplatform: string,\n\t\tplatformId: string,\n\t): Promise<Chapter | undefined> {\n\t\tawait this.ensureReady();\n\t\tconst chapterRecord = await this.db.query.chapters\n\t\t\t.findFirst({\n\t\t\t\twhere: {\n\t\t\t\t\tplatformId,\n\t\t\t\t\tnovel: {\n\t\t\t\t\t\tplatform,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\twith: {\n\t\t\t\t\tnovel: true,\n\t\t\t\t\tvolume: true,\n\t\t\t\t},\n\t\t\t})\n\t\t\t.execute();\n\n\t\tif (!chapterRecord) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tid: chapterRecord.platformId,\n\t\t\tplatform: chapterRecord.platform,\n\t\t\ttitle: chapterRecord.name,\n\t\t\tnovelId: chapterRecord.novel?.platformId ?? \"\",\n\t\t\tvolumeId: chapterRecord.volume?.platformId ?? \"\",\n\t\t\tcontentHash: chapterRecord.contentHash ?? null,\n\t\t};\n\t}\n\n\tasync addNovelContentHash(\n\t\tplatform: string,\n\t\tchapterId: string,\n\t\tcontentHash: string,\n\t) {\n\t\tawait this.ensureReady();\n\t\tawait this.db\n\t\t\t.update(chapters)\n\t\t\t.set({ contentHash })\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(chapters.platformId, chapterId),\n\t\t\t\t\teq(chapters.platform, platform),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.run();\n\t}\n\n\tasync getNovelCoverMetadata(\n\t\tplatform: string,\n\t\tnovelId: string,\n\t): Promise<NovelCoverMetadata | undefined> {\n\t\tawait this.ensureReady();\n\t\tconst queryResult = await this.db.query.novelCoverMetadata\n\t\t\t.findFirst({\n\t\t\t\twhere: {\n\t\t\t\t\tnovel: {\n\t\t\t\t\t\tplatform: platform,\n\t\t\t\t\t\tplatformId: novelId,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\twith: {\n\t\t\t\t\tnovel: true,\n\t\t\t\t},\n\t\t\t})\n\t\t\t.execute();\n\n\t\tif (!queryResult) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tplatform: queryResult.novel?.platform ?? null,\n\t\t\tnovelId: queryResult.novel?.platformId ?? null,\n\t\t\thash: queryResult.hash ?? \"\",\n\t\t\tcontentType: queryResult.contentType ?? \"\",\n\t\t\toriginalUrl: queryResult.originalUrl ?? \"\",\n\t\t};\n\t}\n\n\tasync addNovelCoverMetadata(metadata: NovelCoverMetadata) {\n\t\tawait this.ensureReady();\n\t\tconst novel =\n\t\t\tmetadata.novelId && metadata.platform\n\t\t\t\t? await this.db.query.novels\n\t\t\t\t\t\t.findFirst({\n\t\t\t\t\t\t\twhere: {\n\t\t\t\t\t\t\t\tplatform: metadata.platform,\n\t\t\t\t\t\t\t\tplatformId: metadata.novelId,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.execute()\n\t\t\t\t: null;\n\n\t\tlet novelId: number | null = null;\n\t\tif (!novel) {\n\t\t\tconst result = await this.db\n\t\t\t\t.insert(novels)\n\t\t\t\t.values({\n\t\t\t\t\tplatform: metadata.platform ?? \"\",\n\t\t\t\t\tplatformId: metadata.novelId ?? \"\",\n\t\t\t\t\tname: \"\",\n\t\t\t\t\tcoverUrl: metadata.originalUrl ?? \"\",\n\t\t\t\t\tauthor: \"\",\n\t\t\t\t\tsummary: \"\",\n\t\t\t\t\tstatus: \"unknown\",\n\t\t\t\t\tupdateAt: Date.now(),\n\t\t\t\t})\n\t\t\t\t.onConflictDoNothing()\n\t\t\t\t.returning({ id: novels.id })\n\t\t\t\t.get();\n\t\t\tnovelId = result?.id ?? null;\n\t\t}\n\n\t\tawait this.db\n\t\t\t.insert(novelCoverMetadata)\n\t\t\t.values({\n\t\t\t\thash: metadata.hash,\n\t\t\t\tcontentType: metadata.contentType,\n\t\t\t\toriginalUrl: metadata.originalUrl,\n\t\t\t\tnovelId: novel?.id ?? novelId ?? null,\n\t\t\t})\n\t\t\t.onConflictDoNothing()\n\t\t\t.run();\n\t}\n\n\tasync getVolumeCoverMetadata(\n\t\tplatform: string,\n\t\tvolumeId: string,\n\t): Promise<VolumeCoverMetadata | undefined> {\n\t\tawait this.ensureReady();\n\t\tconst queryResult = await this.db.query.volumeCoverMetadata\n\t\t\t.findFirst({\n\t\t\t\twhere: {\n\t\t\t\t\tvolume: {\n\t\t\t\t\t\tplatform: platform,\n\t\t\t\t\t\tplatformId: volumeId,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\twith: {\n\t\t\t\t\tvolume: {\n\t\t\t\t\t\twith: {\n\t\t\t\t\t\t\tnovel: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t})\n\t\t\t.execute();\n\n\t\tif (!queryResult) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tplatform: queryResult.volume?.platform ?? null,\n\t\t\tvolumeId: queryResult.volume?.platformId ?? null,\n\t\t\thash: queryResult.hash ?? \"\",\n\t\t\tcontentType: queryResult.contentType ?? \"\",\n\t\t\toriginalUrl: queryResult.originalUrl ?? \"\",\n\t\t};\n\t}\n\n\tasync addVolumeCoverMetadata(metadata: VolumeCoverMetadata) {\n\t\tawait this.ensureReady();\n\t\tconst volume =\n\t\t\tmetadata.volumeId && metadata.platform\n\t\t\t\t? await this.db.query.volumes\n\t\t\t\t\t\t.findFirst({\n\t\t\t\t\t\t\twhere: {\n\t\t\t\t\t\t\t\tplatform: metadata.platform,\n\t\t\t\t\t\t\t\tplatformId: metadata.volumeId,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.execute()\n\t\t\t\t: null;\n\n\t\tawait this.db\n\t\t\t.insert(volumeCoverMetadata)\n\t\t\t.values({\n\t\t\t\thash: metadata.hash,\n\t\t\t\tcontentType: metadata.contentType,\n\t\t\t\toriginalUrl: metadata.originalUrl,\n\t\t\t\tvolumeId: volume?.id ?? null,\n\t\t\t})\n\t\t\t.onConflictDoNothing()\n\t\t\t.run();\n\t}\n\n\tasync getCache<T>(key: string, schema: z.ZodType<T>): Promise<T | null> {\n\t\tawait this.ensureReady();\n\t\tconst record = await this.db.query.generalCache\n\t\t\t.findFirst({\n\t\t\t\twhere: {\n\t\t\t\t\tkey,\n\t\t\t\t},\n\t\t\t})\n\t\t\t.execute();\n\n\t\tif (!record) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst parsed = schema.safeParse(record.value);\n\t\treturn parsed.success ? parsed.data : null;\n\t}\n\n\tasync setCache<T>(key: string, value: T): Promise<void> {\n\t\tawait this.ensureReady();\n\t\tawait this.db\n\t\t\t.insert(generalCache)\n\t\t\t.values({ key, value })\n\t\t\t.onConflictDoUpdate({\n\t\t\t\ttarget: generalCache.key,\n\t\t\t\tset: { value },\n\t\t\t})\n\t\t\t.run();\n\t}\n\n\tasync registerIllustrations(\n\t\tplatform: string,\n\t\titems: string[] | { urlHash: string; originalUrl: string }[],\n\t): Promise<void> {\n\t\tawait this.ensureReady();\n\t\tconst uniqueItems = new Map<\n\t\t\tstring,\n\t\t\t{ urlHash: string; originalUrl: string }\n\t\t>();\n\t\tfor (const item of items) {\n\t\t\tif (typeof item === \"string\") {\n\t\t\t\tconst trimmed = item.trim();\n\t\t\t\tif (!trimmed) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst urlHash = getUrlHash(trimmed);\n\t\t\t\tif (!uniqueItems.has(urlHash)) {\n\t\t\t\t\tuniqueItems.set(urlHash, { urlHash, originalUrl: trimmed });\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst urlHash = item.urlHash.trim();\n\t\t\t\tconst originalUrl = item.originalUrl.trim();\n\t\t\t\tif (!urlHash || !originalUrl) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (!uniqueItems.has(urlHash)) {\n\t\t\t\t\tuniqueItems.set(urlHash, { urlHash, originalUrl });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (uniqueItems.size === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst createdAt = Date.now();\n\t\tconst rows = Array.from(uniqueItems.values()).map((entry) => ({\n\t\t\tplatform,\n\t\t\turlHash: entry.urlHash,\n\t\t\toriginalUrl: entry.originalUrl,\n\t\t\tcreatedAt,\n\t\t}));\n\n\t\tconst chunkSize = 200;\n\t\tawait this.db.transaction(async (tx) => {\n\t\t\tfor (let i = 0; i < rows.length; i += chunkSize) {\n\t\t\t\tconst chunk = rows.slice(i, i + chunkSize);\n\t\t\t\tawait tx\n\t\t\t\t\t.insert(illustrationMetadata)\n\t\t\t\t\t.values(chunk)\n\t\t\t\t\t.onConflictDoNothing({\n\t\t\t\t\t\ttarget: [\n\t\t\t\t\t\t\tillustrationMetadata.platform,\n\t\t\t\t\t\t\tillustrationMetadata.urlHash,\n\t\t\t\t\t\t],\n\t\t\t\t\t})\n\t\t\t\t\t.run();\n\t\t\t}\n\t\t});\n\t}\n\n\tasync getIllustrationSourceUrl(\n\t\tplatform: string,\n\t\turlHash: string,\n\t): Promise<string | undefined> {\n\t\tawait this.ensureReady();\n\t\tconst record = await this.db\n\t\t\t.select({ originalUrl: illustrationMetadata.originalUrl })\n\t\t\t.from(illustrationMetadata)\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(illustrationMetadata.platform, platform),\n\t\t\t\t\teq(illustrationMetadata.urlHash, urlHash),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.get();\n\n\t\treturn record?.originalUrl;\n\t}\n\n\tasync getIllustrationMetadata(\n\t\tplatform: string,\n\t\turlHash: string,\n\t): Promise<\n\t\t| {\n\t\t\t\toriginalUrl: string;\n\t\t\t\tfileHash: string | null;\n\t\t\t\tcontentType: string | null;\n\t\t }\n\t\t| undefined\n\t> {\n\t\tawait this.ensureReady();\n\t\treturn await this.db\n\t\t\t.select({\n\t\t\t\toriginalUrl: illustrationMetadata.originalUrl,\n\t\t\t\tfileHash: illustrationMetadata.fileHash,\n\t\t\t\tcontentType: illustrationMetadata.contentType,\n\t\t\t})\n\t\t\t.from(illustrationMetadata)\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(illustrationMetadata.platform, platform),\n\t\t\t\t\teq(illustrationMetadata.urlHash, urlHash),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.get();\n\t}\n\n\tasync updateIllustrationFileInfo(\n\t\tplatform: string,\n\t\turlHash: string,\n\t\tfileHash: string,\n\t\tcontentType: string,\n\t): Promise<void> {\n\t\tawait this.ensureReady();\n\t\tawait this.db\n\t\t\t.update(illustrationMetadata)\n\t\t\t.set({ fileHash, contentType })\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(illustrationMetadata.platform, platform),\n\t\t\t\t\teq(illustrationMetadata.urlHash, urlHash),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.run();\n\t}\n\n\tasync listCachedNovels(\n\t\tplatform: string,\n\t\toptions: ListNovelsOptions,\n\t): Promise<PaginatedNovels> {\n\t\tawait this.ensureReady();\n\t\tconst page = Math.max(1, Math.trunc(options.page));\n\t\tconst pageSize = Math.max(1, Math.trunc(options.pageSize));\n\t\tconst offset = (page - 1) * pageSize;\n\n\t\tconst whereClause = and(\n\t\t\teq(novels.platform, platform),\n\t\t\tne(novels.status, \"unknown\"),\n\t\t\tne(novels.author, \"\"),\n\t\t\tne(novels.name, \"\"),\n\t\t);\n\n\t\tconst totalResult = await this.db\n\t\t\t.select({ value: count() })\n\t\t\t.from(novels)\n\t\t\t.where(whereClause)\n\t\t\t.get();\n\t\tconst total = totalResult?.value ?? 0;\n\n\t\tif (total === 0) {\n\t\t\treturn {\n\t\t\t\titems: [],\n\t\t\t\ttotal: 0,\n\t\t\t\tpage,\n\t\t\t\tpageSize,\n\t\t\t};\n\t\t}\n\n\t\tconst novelRows = await this.db\n\t\t\t.select({\n\t\t\t\tid: novels.id,\n\t\t\t\tplatform: novels.platform,\n\t\t\t\tplatformId: novels.platformId,\n\t\t\t\tname: novels.name,\n\t\t\t\tcoverUrl: novels.coverUrl,\n\t\t\t\tauthor: novels.author,\n\t\t\t\tsummary: novels.summary,\n\t\t\t\tstatus: novels.status,\n\t\t\t})\n\t\t\t.from(novels)\n\t\t\t.where(whereClause)\n\t\t\t.orderBy(desc(novels.updateAt), desc(novels.id))\n\t\t\t.limit(pageSize)\n\t\t\t.offset(offset)\n\t\t\t.all();\n\n\t\tif (novelRows.length === 0) {\n\t\t\treturn {\n\t\t\t\titems: [],\n\t\t\t\ttotal,\n\t\t\t\tpage,\n\t\t\t\tpageSize,\n\t\t\t};\n\t\t}\n\n\t\tconst novelIds = novelRows.map((row) => row.id);\n\t\tconst genreRows = await this.db\n\t\t\t.select({\n\t\t\t\tnovelId: novelGenres.novelId,\n\t\t\t\tgenreName: genres.name,\n\t\t\t})\n\t\t\t.from(novelGenres)\n\t\t\t.innerJoin(genres, eq(novelGenres.genreId, genres.id))\n\t\t\t.where(inArray(novelGenres.novelId, novelIds))\n\t\t\t.all();\n\n\t\tconst genresByNovelId = new Map<number, string[]>();\n\t\tfor (const row of genreRows) {\n\t\t\tconst existing = genresByNovelId.get(row.novelId);\n\t\t\tif (existing) {\n\t\t\t\texisting.push(row.genreName);\n\t\t\t} else {\n\t\t\t\tgenresByNovelId.set(row.novelId, [row.genreName]);\n\t\t\t}\n\t\t}\n\n\t\tconst items: NovelInfo[] = novelRows.map((row) => ({\n\t\t\tid: row.platformId,\n\t\t\tplatform: row.platform,\n\t\t\ttitle: row.name,\n\t\t\tcoverUrl: row.coverUrl,\n\t\t\tauthor: row.author,\n\t\t\tsummary: row.summary,\n\t\t\tstatus: row.status,\n\t\t\tgenres: genresByNovelId.get(row.id) ?? [],\n\t\t}));\n\n\t\treturn {\n\t\t\titems,\n\t\t\ttotal,\n\t\t\tpage,\n\t\t\tpageSize,\n\t\t};\n\t}\n\n\tprivate async getMaxSyncCursor(\n\t\texecutor: Pick<DrizzleInstance, \"select\">,\n\t): Promise<number> {\n\t\tconst bookshelfMaxRow = await executor\n\t\t\t.select({ value: max(bookshelfItems.serverUpdatedAt) })\n\t\t\t.from(bookshelfItems)\n\t\t\t.get();\n\t\tconst progressMaxRow = await executor\n\t\t\t.select({ value: max(readingProgress.serverUpdatedAt) })\n\t\t\t.from(readingProgress)\n\t\t\t.get();\n\t\tconst bookshelfMax = Number(bookshelfMaxRow?.value ?? 0);\n\t\tconst progressMax = Number(progressMaxRow?.value ?? 0);\n\t\treturn Math.max(bookshelfMax, progressMax);\n\t}\n\n\tasync getSyncState(since?: number): Promise<SyncStateResult> {\n\t\tawait this.ensureReady();\n\t\treturn await this.db.transaction(async (tx) => {\n\t\t\tconst maxCursor = await this.getMaxSyncCursor(tx);\n\n\t\t\tif (since === undefined || since <= 0) {\n\t\t\t\tconst bookshelfRows = await tx\n\t\t\t\t\t.select()\n\t\t\t\t\t.from(bookshelfItems)\n\t\t\t\t\t.where(isNull(bookshelfItems.deletedAt))\n\t\t\t\t\t.all();\n\t\t\t\tconst progressRows = await tx.select().from(readingProgress).all();\n\n\t\t\t\treturn {\n\t\t\t\t\tbookshelf: bookshelfRows.map(toBookshelfItem),\n\t\t\t\t\tprogress: progressRows.map(toReadingProgress),\n\t\t\t\t\tcursor: maxCursor,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst bookshelfRows = await tx\n\t\t\t\t.select()\n\t\t\t\t.from(bookshelfItems)\n\t\t\t\t.where(gt(bookshelfItems.serverUpdatedAt, since))\n\t\t\t\t.all();\n\t\t\tconst progressRows = await tx\n\t\t\t\t.select()\n\t\t\t\t.from(readingProgress)\n\t\t\t\t.where(gt(readingProgress.serverUpdatedAt, since))\n\t\t\t\t.all();\n\n\t\t\treturn {\n\t\t\t\tbookshelf: bookshelfRows.map(toBookshelfItem),\n\t\t\t\tprogress: progressRows.map(toReadingProgress),\n\t\t\t\tcursor: Math.max(since, maxCursor),\n\t\t\t};\n\t\t});\n\t}\n\n\tasync mergeSyncState(\n\t\tinput: MergeSyncStateInput,\n\t): Promise<MergeSyncStateResult> {\n\t\tawait this.ensureReady();\n\t\treturn await this.db.transaction(async (tx) => {\n\t\t\tlet lastCursor = await this.getMaxSyncCursor(tx);\n\t\t\tconst nextCursor = () => {\n\t\t\t\tlastCursor = Math.max(Date.now(), lastCursor + 1);\n\t\t\t\treturn lastCursor;\n\t\t\t};\n\n\t\t\tconst bookshelfMap = new Map<string, BookshelfItem>();\n\t\t\tconst progressMap = new Map<string, ReadingProgress>();\n\n\t\t\tfor (const item of input.bookshelf ?? []) {\n\t\t\t\tconst key = `${item.platform}\\0${item.novelId}`;\n\t\t\t\tconst effectiveUpdatedAt = Math.min(\n\t\t\t\t\titem.updatedAt,\n\t\t\t\t\tDate.now() + CLOCK_SKEW_TOLERANCE_MS,\n\t\t\t\t);\n\t\t\t\tconst existing = await tx\n\t\t\t\t\t.select()\n\t\t\t\t\t.from(bookshelfItems)\n\t\t\t\t\t.where(\n\t\t\t\t\t\tand(\n\t\t\t\t\t\t\teq(bookshelfItems.platform, item.platform),\n\t\t\t\t\t\t\teq(bookshelfItems.novelId, item.novelId),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\t.get();\n\n\t\t\t\tif (!existing) {\n\t\t\t\t\tconst serverUpdatedAt = nextCursor();\n\t\t\t\t\tconst inserted = await tx\n\t\t\t\t\t\t.insert(bookshelfItems)\n\t\t\t\t\t\t.values({\n\t\t\t\t\t\t\tplatform: item.platform,\n\t\t\t\t\t\t\tnovelId: item.novelId,\n\t\t\t\t\t\t\ttitle: item.title,\n\t\t\t\t\t\t\tauthor: item.author,\n\t\t\t\t\t\t\tcoverUrl: item.coverUrl,\n\t\t\t\t\t\t\taddedAt: item.addedAt,\n\t\t\t\t\t\t\tupdatedAt: effectiveUpdatedAt,\n\t\t\t\t\t\t\tserverUpdatedAt,\n\t\t\t\t\t\t\tdeletedAt: item.deletedAt,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.returning()\n\t\t\t\t\t\t.get();\n\t\t\t\t\tbookshelfMap.set(key, toBookshelfItem(inserted));\n\t\t\t\t} else if (effectiveUpdatedAt >= existing.updatedAt) {\n\t\t\t\t\tconst serverUpdatedAt = nextCursor();\n\t\t\t\t\tconst updated = await tx\n\t\t\t\t\t\t.update(bookshelfItems)\n\t\t\t\t\t\t.set({\n\t\t\t\t\t\t\ttitle: item.title,\n\t\t\t\t\t\t\tauthor: item.author,\n\t\t\t\t\t\t\tcoverUrl: item.coverUrl,\n\t\t\t\t\t\t\taddedAt: item.addedAt,\n\t\t\t\t\t\t\tupdatedAt: effectiveUpdatedAt,\n\t\t\t\t\t\t\tserverUpdatedAt,\n\t\t\t\t\t\t\tdeletedAt: item.deletedAt,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.where(eq(bookshelfItems.id, existing.id))\n\t\t\t\t\t\t.returning()\n\t\t\t\t\t\t.get();\n\t\t\t\t\tif (!updated) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Failed to update bookshelf item: ${item.platform}/${item.novelId}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbookshelfMap.set(key, toBookshelfItem(updated));\n\t\t\t\t} else {\n\t\t\t\t\tbookshelfMap.set(key, toBookshelfItem(existing));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const item of input.progress ?? []) {\n\t\t\t\tconst key = `${item.platform}\\0${item.novelId}`;\n\t\t\t\tconst effectiveUpdatedAt = Math.min(\n\t\t\t\t\titem.updatedAt,\n\t\t\t\t\tDate.now() + CLOCK_SKEW_TOLERANCE_MS,\n\t\t\t\t);\n\t\t\t\tconst existing = await tx\n\t\t\t\t\t.select()\n\t\t\t\t\t.from(readingProgress)\n\t\t\t\t\t.where(\n\t\t\t\t\t\tand(\n\t\t\t\t\t\t\teq(readingProgress.platform, item.platform),\n\t\t\t\t\t\t\teq(readingProgress.novelId, item.novelId),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\t.get();\n\n\t\t\t\tif (!existing) {\n\t\t\t\t\tconst serverUpdatedAt = nextCursor();\n\t\t\t\t\tconst inserted = await tx\n\t\t\t\t\t\t.insert(readingProgress)\n\t\t\t\t\t\t.values({\n\t\t\t\t\t\t\tplatform: item.platform,\n\t\t\t\t\t\t\tnovelId: item.novelId,\n\t\t\t\t\t\t\tnovelTitle: item.novelTitle,\n\t\t\t\t\t\t\tcoverUrl: item.coverUrl,\n\t\t\t\t\t\t\tvolumeId: item.volumeId,\n\t\t\t\t\t\t\tvolumeTitle: item.volumeTitle,\n\t\t\t\t\t\t\tchapterId: item.chapterId,\n\t\t\t\t\t\t\tchapterTitle: item.chapterTitle,\n\t\t\t\t\t\t\tparagraphIndex: item.paragraphIndex,\n\t\t\t\t\t\t\ttotalParagraphs: item.totalParagraphs,\n\t\t\t\t\t\t\tdeviceLabel: item.deviceLabel,\n\t\t\t\t\t\t\tupdatedAt: effectiveUpdatedAt,\n\t\t\t\t\t\t\tserverUpdatedAt,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.returning()\n\t\t\t\t\t\t.get();\n\t\t\t\t\tprogressMap.set(key, toReadingProgress(inserted));\n\t\t\t\t} else if (effectiveUpdatedAt >= existing.updatedAt) {\n\t\t\t\t\tconst serverUpdatedAt = nextCursor();\n\t\t\t\t\tconst updated = await tx\n\t\t\t\t\t\t.update(readingProgress)\n\t\t\t\t\t\t.set({\n\t\t\t\t\t\t\tnovelTitle: item.novelTitle,\n\t\t\t\t\t\t\tcoverUrl: item.coverUrl,\n\t\t\t\t\t\t\tvolumeId: item.volumeId,\n\t\t\t\t\t\t\tvolumeTitle: item.volumeTitle,\n\t\t\t\t\t\t\tchapterId: item.chapterId,\n\t\t\t\t\t\t\tchapterTitle: item.chapterTitle,\n\t\t\t\t\t\t\tparagraphIndex: item.paragraphIndex,\n\t\t\t\t\t\t\ttotalParagraphs: item.totalParagraphs,\n\t\t\t\t\t\t\tdeviceLabel: item.deviceLabel,\n\t\t\t\t\t\t\tupdatedAt: effectiveUpdatedAt,\n\t\t\t\t\t\t\tserverUpdatedAt,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.where(eq(readingProgress.id, existing.id))\n\t\t\t\t\t\t.returning()\n\t\t\t\t\t\t.get();\n\t\t\t\t\tif (!updated) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Failed to update reading progress: ${item.platform}/${item.novelId}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tprogressMap.set(key, toReadingProgress(updated));\n\t\t\t\t} else {\n\t\t\t\t\tprogressMap.set(key, toReadingProgress(existing));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst serverTime = Math.max(Date.now(), lastCursor);\n\t\t\treturn {\n\t\t\t\tbookshelf: Array.from(bookshelfMap.values()),\n\t\t\t\tprogress: Array.from(progressMap.values()),\n\t\t\t\tserverTime,\n\t\t\t};\n\t\t});\n\t}\n\n\tasync close(logger?: (message: string) => void) {\n\t\ttry {\n\t\t\tawait this.ensureReady().catch(() => {});\n\t\t\tawait this.client.execute(\"PRAGMA journal_mode = DELETE;\");\n\t\t\tlogger?.(\"WAL写入盘完成,正在关闭数据库连接...\");\n\t\t} catch (error) {\n\t\t\tlogger?.(`执行WAL检查点时发生错误: ${error}`);\n\t\t} finally {\n\t\t\tthis.client.close();\n\t\t\tlogger?.(\"数据库连接已关闭\");\n\t\t}\n\t}\n}\n","import { existsSync } from \"node:fs\";\nimport { mkdir, readFile, rm, stat, writeFile } from \"node:fs/promises\";\nimport type { BinaryResponse } from \"@acanthis-dec/browser-fetch\";\nimport type { DatabaseService } from \"./db\";\nimport type { NovelCoverMetadata, VolumeCoverMetadata } from \"./type\";\nimport {\n\tgetContentHash,\n\tgetCoverHash,\n\tgetExtFromContentType,\n\tzstdCompress,\n\tzstdDecompress,\n} from \"./utils\";\n\nexport class FSStorageService {\n\tprivate basePath: string;\n\tprivate dbService: DatabaseService;\n\n\tconstructor(basePath: string, dbService: DatabaseService) {\n\t\tthis.basePath = basePath;\n\t\tthis.dbService = dbService;\n\t}\n\n\tprivate async _initPath(path: string): Promise<void> {\n\t\tif (!existsSync(path)) {\n\t\t\tawait mkdir(path, { recursive: true });\n\t\t} else if (existsSync(path) && !(await stat(path)).isDirectory()) {\n\t\t\tawait rm(path);\n\t\t\tawait mkdir(path, { recursive: true });\n\t\t}\n\t}\n\n\tasync getNovelContent(hash: string): Promise<string | undefined> {\n\t\tconst novelCacheDir = `${this.basePath}/novels/${hash.slice(0, 2)}`;\n\t\tconst chapterFilePath = `${novelCacheDir}/${hash}.zst`;\n\t\tif (!existsSync(chapterFilePath)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst compressedData = await readFile(chapterFilePath);\n\t\tconst decompressedData = await zstdDecompress(compressedData);\n\t\treturn new TextDecoder().decode(decompressedData);\n\t}\n\n\tasync setNovelContent(content: string): Promise<string> {\n\t\tconst hash = getContentHash(content);\n\t\tconst novelCacheDir = `${this.basePath}/novels/${hash.slice(0, 2)}`;\n\t\tawait this._initPath(novelCacheDir);\n\t\tconst chapterFilePath = `${novelCacheDir}/${hash}.zst`;\n\t\tconst compressedData = await zstdCompress(Buffer.from(content, \"utf-8\"));\n\t\tawait writeFile(chapterFilePath, compressedData);\n\t\treturn hash;\n\t}\n\n\tasync getCoverData(\n\t\ttype: \"novel\" | \"volume\",\n\t\tplatform: string,\n\t\tplatformId: string,\n\t): Promise<BinaryResponse | undefined> {\n\t\tlet meta: NovelCoverMetadata | VolumeCoverMetadata | undefined;\n\t\tif (type === \"novel\") {\n\t\t\tmeta = await this.dbService.getNovelCoverMetadata(platform, platformId);\n\t\t} else if (type === \"volume\") {\n\t\t\tmeta = await this.dbService.getVolumeCoverMetadata(platform, platformId);\n\t\t}\n\t\tif (!meta) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst coverPath = `${this.basePath}/covers/${meta.hash.slice(0, 2)}/${meta.hash}.${getExtFromContentType(meta.contentType)}`;\n\t\tif (!existsSync(coverPath)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst data = await readFile(coverPath);\n\t\treturn { data, mimeType: meta.contentType };\n\t}\n\n\tasync setCoverData(\n\t\ttype: \"novel\" | \"volume\",\n\t\turl: string,\n\t\tplatform: string,\n\t\tplatformId: string,\n\t\tdata: Buffer,\n\t\tcontentType: string,\n\t): Promise<void> {\n\t\tconst coverHash = getCoverHash(data);\n\t\tconst ext = getExtFromContentType(contentType);\n\t\tconst coverDir = `${this.basePath}/covers/${coverHash.slice(0, 2)}`;\n\t\tawait this._initPath(coverDir);\n\t\tconst coverPath = `${coverDir}/${coverHash}.${ext}`;\n\t\tawait writeFile(coverPath, data);\n\t\tif (type === \"novel\") {\n\t\t\tawait this.dbService.addNovelCoverMetadata({\n\t\t\t\tplatform,\n\t\t\t\tnovelId: platformId,\n\t\t\t\thash: coverHash,\n\t\t\t\tcontentType,\n\t\t\t\toriginalUrl: url,\n\t\t\t});\n\t\t} else if (type === \"volume\") {\n\t\t\tawait this.dbService.addVolumeCoverMetadata({\n\t\t\t\tplatform,\n\t\t\t\tvolumeId: platformId,\n\t\t\t\thash: coverHash,\n\t\t\t\tcontentType,\n\t\t\t\toriginalUrl: url,\n\t\t\t});\n\t\t}\n\t}\n\n\tasync getIllustrationData(\n\t\tplatform: string,\n\t\turlHash: string,\n\t): Promise<BinaryResponse | undefined> {\n\t\tconst meta = await this.dbService.getIllustrationMetadata(\n\t\t\tplatform,\n\t\t\turlHash,\n\t\t);\n\t\tif (!meta?.fileHash || !meta?.contentType) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst ext = getExtFromContentType(meta.contentType);\n\t\tconst illustrationPath = `${this.basePath}/illustrations/${meta.fileHash.slice(0, 2)}/${meta.fileHash}.${ext}`;\n\t\tif (!existsSync(illustrationPath)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst data = await readFile(illustrationPath);\n\t\treturn { data, mimeType: meta.contentType };\n\t}\n\n\tasync setIllustrationData(\n\t\tplatform: string,\n\t\turlHash: string,\n\t\tdata: Buffer,\n\t\tcontentType: string,\n\t): Promise<void> {\n\t\tconst fileHash = getCoverHash(data);\n\t\tconst ext = getExtFromContentType(contentType);\n\t\tconst illustrationDir = `${this.basePath}/illustrations/${fileHash.slice(0, 2)}`;\n\t\tawait this._initPath(illustrationDir);\n\t\tconst illustrationPath = `${illustrationDir}/${fileHash}.${ext}`;\n\t\tawait writeFile(illustrationPath, data);\n\t\tawait this.dbService.updateIllustrationFileInfo(\n\t\t\tplatform,\n\t\t\turlHash,\n\t\t\tfileHash,\n\t\t\tcontentType,\n\t\t);\n\t}\n}\n","import type { BinaryResponse } from \"@acanthis-dec/browser-fetch\";\nimport type { Chapter, Novel, NovelSearchResult } from \"@acanthis-dec/core\";\nimport type z from \"zod\";\nimport { DatabaseCookieStore } from \"./cookies\";\nimport { type DatabaseOptions, DatabaseService } from \"./db\";\nimport { FSStorageService } from \"./files\";\nimport type {\n\tListNovelsOptions,\n\tMergeSyncStateInput,\n\tMergeSyncStateResult,\n\tPaginatedNovels,\n\tSyncStateResult,\n} from \"./type\";\n\nexport interface StorageServiceOptions {\n\tdataDir?: string;\n\tdb: DatabaseOptions;\n}\n\nexport class StorageService {\n\tprivate db: DatabaseService;\n\tprivate files: FSStorageService;\n\tprivate cookieStore: DatabaseCookieStore;\n\n\tconstructor(options: StorageServiceOptions) {\n\t\tthis.db = new DatabaseService(options.db);\n\t\tthis.files = new FSStorageService(options.dataDir ?? \"\", this.db);\n\t\tthis.cookieStore = new DatabaseCookieStore(this.db);\n\t}\n\n\tasync getNovelContent(hash: string): Promise<string | undefined> {\n\t\treturn await this.files.getNovelContent(hash);\n\t}\n\n\tasync setNovelContent(content: string): Promise<string> {\n\t\treturn await this.files.setNovelContent(content);\n\t}\n\n\tasync getCoverData(\n\t\ttype: \"novel\" | \"volume\",\n\t\tplatform: string,\n\t\tplatformId: string,\n\t): Promise<BinaryResponse | undefined> {\n\t\treturn await this.files.getCoverData(type, platform, platformId);\n\t}\n\n\tasync setCoverData(\n\t\ttype: \"novel\" | \"volume\",\n\t\turl: string,\n\t\tdata: Buffer,\n\t\tcontentType: string,\n\t\tplatform: string,\n\t\tplatformId: string,\n\t): Promise<void> {\n\t\tawait this.files.setCoverData(\n\t\t\ttype,\n\t\t\turl,\n\t\t\tplatform,\n\t\t\tplatformId,\n\t\t\tdata,\n\t\t\tcontentType,\n\t\t);\n\t}\n\n\tasync addSearchResult(\n\t\tkeyword: string,\n\t\tplatform: string,\n\t\tresults: NovelSearchResult[],\n\t): Promise<void> {\n\t\tawait this.db.addSearchResult(keyword, platform, results);\n\t}\n\n\tasync searchNovels(\n\t\tkeyword: string,\n\t\tplatform: string,\n\t): Promise<NovelSearchResult[] | undefined> {\n\t\tconst data = await this.db.searchNovels(keyword, platform);\n\t\treturn data ? data.data : undefined;\n\t}\n\n\tasync getNovelCache(platform: string, platformId: string) {\n\t\tconst data = await this.db.getNovelCache(platform, platformId);\n\t\treturn data ? data.data : undefined;\n\t}\n\n\tasync addNovelCache(novel: Novel) {\n\t\tawait this.db.addNovelCache(novel);\n\t}\n\n\tasync getVolumeMeta(platform: string, platformId: string) {\n\t\treturn await this.db.getVolumeMeta(platform, platformId);\n\t}\n\n\tasync getChapterFromTitle(\n\t\ttitle: string,\n\t): Promise<Partial<Chapter> | undefined> {\n\t\treturn await this.db.getChapterFromTitle(title);\n\t}\n\n\tasync getChapterFromId(\n\t\tplatform: string,\n\t\tplatformId: string,\n\t): Promise<Chapter | undefined> {\n\t\treturn await this.db.getChapterFromId(platform, platformId);\n\t}\n\n\tasync addNovelContentHash(\n\t\tplatform: string,\n\t\tchapterId: string,\n\t\tcontentHash: string,\n\t) {\n\t\tawait this.db.addNovelContentHash(platform, chapterId, contentHash);\n\t}\n\n\tgetCookieStore() {\n\t\treturn this.cookieStore;\n\t}\n\n\tasync getCache<T>(key: string, schema: z.ZodType<T>): Promise<T | null> {\n\t\treturn await this.db.getCache(key, schema);\n\t}\n\n\tasync setCache<T>(key: string, value: T): Promise<void> {\n\t\tawait this.db.setCache(key, value);\n\t}\n\n\tasync registerIllustrations(platform: string, urls: string[]): Promise<void> {\n\t\tawait this.db.registerIllustrations(platform, urls);\n\t}\n\n\tasync getIllustrationSourceUrl(\n\t\tplatform: string,\n\t\turlHash: string,\n\t): Promise<string | undefined> {\n\t\treturn await this.db.getIllustrationSourceUrl(platform, urlHash);\n\t}\n\n\tasync getIllustrationData(\n\t\tplatform: string,\n\t\turlHash: string,\n\t): Promise<BinaryResponse | undefined> {\n\t\treturn await this.files.getIllustrationData(platform, urlHash);\n\t}\n\n\tasync setIllustrationData(\n\t\tplatform: string,\n\t\turlHash: string,\n\t\tdata: Buffer,\n\t\tcontentType: string,\n\t): Promise<void> {\n\t\tawait this.files.setIllustrationData(platform, urlHash, data, contentType);\n\t}\n\n\tasync listCachedNovels(\n\t\tplatform: string,\n\t\toptions: ListNovelsOptions,\n\t): Promise<PaginatedNovels> {\n\t\treturn await this.db.listCachedNovels(platform, options);\n\t}\n\n\tasync getSyncState(since?: number): Promise<SyncStateResult> {\n\t\treturn await this.db.getSyncState(since);\n\t}\n\n\tasync mergeSyncState(\n\t\tinput: MergeSyncStateInput,\n\t): Promise<MergeSyncStateResult> {\n\t\treturn await this.db.mergeSyncState(input);\n\t}\n\n\tasync close(logger?: (message: string) => void) {\n\t\tawait this.db.close(logger);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAUA,MAAa,SAAS,YACrB,UACA;CACC,IAAI,QAAQ,IAAI,CAAC,CAAC,WAAW,EAAE,eAAe,KAAK,CAAC;CACpD,UAAU,KAAK,UAAU,CAAC,CAAC,QAAQ;CACnC,YAAY,KAAK,aAAa,CAAC,CAAC,QAAQ;CACxC,MAAM,KAAK,MAAM,CAAC,CAAC,QAAQ;CAC3B,QAAQ,KAAK,QAAQ,CAAC,CAAC,QAAQ;CAC/B,SAAS,KAAK,SAAS,CAAC,CAAC,QAAQ;CACjC,UAAU,KAAK,WAAW,CAAC,CAAC,QAAQ;CACpC,QAAQ,KAAK,UAAU,EACtB,MAAM;EAAC;EAAW;EAAa;CAAS,EACzC,CAAC,CAAC,CAAC,QAAQ;CACX,UAAU,QAAQ,WAAW,CAAC,CAAC,QAAQ;AACxC,IACC,UAAU,CACV,OAAO,sBAAsB,CAAC,CAAC,GAAG,MAAM,UAAU,MAAM,UAAU,CACnE,CACD;AAEA,MAAa,SAAS,YAAY,UAAU;CAC3C,IAAI,QAAQ,IAAI,CAAC,CAAC,WAAW,EAAE,eAAe,KAAK,CAAC;CACpD,MAAM,KAAK,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,OAAO;AACrC,CAAC;AAED,MAAa,cAAc,YAC1B,gBACA;CACC,SAAS,QAAQ,UAAU,CAAC,CAC1B,QAA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names":["zc","zd"],"sources":["../src/table.ts","../src/cookies.ts","../src/utils.ts","../src/db.ts","../src/files.ts","../src/service.ts"],"sourcesContent":["import { defineRelations } from \"drizzle-orm\";\nimport {\n\tinteger,\n\tprimaryKey,\n\tsqliteTable,\n\ttext,\n\tunique,\n\tuniqueIndex,\n} from \"drizzle-orm/sqlite-core\";\n\nexport const novels = sqliteTable(\n\t\"novels\",\n\t{\n\t\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\t\tplatform: text(\"platform\").notNull(),\n\t\tplatformId: text(\"platform_id\").notNull(),\n\t\tname: text(\"name\").notNull(),\n\t\tauthor: text(\"author\").notNull(),\n\t\tsummary: text(\"summary\").notNull(),\n\t\tcoverUrl: text(\"cover_url\").notNull(),\n\t\tstatus: text(\"status\", {\n\t\t\tenum: [\"ongoing\", \"completed\", \"unknown\"],\n\t\t}).notNull(),\n\t\tupdateAt: integer(\"update_at\").notNull(),\n\t},\n\t(table) => [\n\t\tunique(\"platform_and_pid_idx\").on(table.platform, table.platformId),\n\t],\n);\n\nexport const genres = sqliteTable(\"genres\", {\n\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\tname: text(\"name\").notNull().unique(),\n});\n\nexport const novelGenres = sqliteTable(\n\t\"novel_genres\",\n\t{\n\t\tnovelId: integer(\"novel_id\")\n\t\t\t.notNull()\n\t\t\t.references(() => novels.id, { onDelete: \"cascade\" }),\n\t\tgenreId: integer(\"genre_id\")\n\t\t\t.notNull()\n\t\t\t.references(() => genres.id, { onDelete: \"cascade\" }),\n\t},\n\t(table) => [primaryKey({ columns: [table.novelId, table.genreId] })],\n);\n\nexport const volumes = sqliteTable(\n\t\"volumes\",\n\t{\n\t\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\t\tnovelId: integer(\"novel_id\")\n\t\t\t.notNull()\n\t\t\t.references(() => novels.id, { onDelete: \"cascade\" }),\n\t\tname: text(\"name\").notNull(),\n\t\tplatform: text(\"platform\").notNull(),\n\t\tplatformId: text(\"platform_id\").notNull(),\n\t\tcoverUrl: text(\"cover_url\"),\n\t},\n\t(table) => [unique(\"novel_and_pid_idx\").on(table.novelId, table.platformId)],\n);\n\nexport const chapters = sqliteTable(\n\t\"chapters\",\n\t{\n\t\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\t\tnovelId: integer(\"novel_id\")\n\t\t\t.notNull()\n\t\t\t.references(() => novels.id, { onDelete: \"cascade\" }),\n\t\tvolumeId: integer(\"volume_id\")\n\t\t\t.notNull()\n\t\t\t.references(() => volumes.id, { onDelete: \"cascade\" }),\n\t\tplatform: text(\"platform\").notNull(),\n\t\tplatformId: text(\"platform_id\").notNull(),\n\t\tcontentHash: text(\"content_hash\"),\n\t\tname: text(\"name\").notNull(),\n\t},\n\t(table) => [unique(\"novel_and_pid_idx\").on(table.novelId, table.platformId)],\n);\n\nexport const keywordSearches = sqliteTable(\"keyword_searches\", {\n\tkeyword: text(\"keyword\").primaryKey(),\n\tplatform: text(\"platform\").notNull(),\n\tqueryTime: integer(\"query_time\").notNull(),\n\ttotal: integer(\"total\").notNull(),\n});\n\nexport const keywordNovels = sqliteTable(\n\t\"keyword_novels\",\n\t{\n\t\tkeyword: text(\"keyword\")\n\t\t\t.notNull()\n\t\t\t.references(() => keywordSearches.keyword, { onDelete: \"cascade\" }),\n\t\tnovelId: integer(\"novel_id\")\n\t\t\t.notNull()\n\t\t\t.references(() => novels.id, { onDelete: \"cascade\" }),\n\t},\n\t(table) => [primaryKey({ columns: [table.keyword, table.novelId] })],\n);\n\nexport const novelCoverMetadata = sqliteTable(\"novel_cover_metadata\", {\n\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\thash: text(\"hash\").notNull(),\n\tcontentType: text(\"content_type\").notNull(),\n\toriginalUrl: text(\"original_url\").notNull().unique(),\n\tnovelId: integer(\"novel_id\").references(() => novels.id, {\n\t\tonDelete: \"set null\",\n\t}),\n});\n\nexport const volumeCoverMetadata = sqliteTable(\"volume_cover_metadata\", {\n\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\thash: text(\"hash\").notNull(),\n\tcontentType: text(\"content_type\").notNull(),\n\toriginalUrl: text(\"original_url\").notNull().unique(),\n\tvolumeId: integer(\"volume_id\").references(() => volumes.id, {\n\t\tonDelete: \"set null\",\n\t}),\n});\n\nexport const cookies = sqliteTable(\n\t\"cookies\",\n\t{\n\t\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\t\tdomain: text(\"domain\").notNull(),\n\t\tpath: text(\"path\").notNull(),\n\t\tname: text(\"name\").notNull(),\n\t\tvalue: text(\"value\").notNull(),\n\t\texpires: integer(\"expires\"),\n\t\tmaxAge: integer(\"max_age\"),\n\t\tsecure: integer(\"secure\", { mode: \"boolean\" }),\n\t\thttpOnly: integer(\"http_only\", { mode: \"boolean\" }),\n\t\tsameSite: text(\"same_site\", { enum: [\"Strict\", \"Lax\", \"None\"] }),\n\t\tcreatedAt: integer(\"created_at\").notNull(),\n\t\tlastAccessedAt: integer(\"last_accessed_at\").notNull(),\n\t},\n\t(table) => [\n\t\tunique(\"cookie_unique_idx\").on(table.domain, table.path, table.name),\n\t],\n);\n\nexport type CookieRow = typeof cookies.$inferSelect;\n\nexport const generalCache = sqliteTable(\"general_cache\", {\n\tkey: text(\"key\").primaryKey(),\n\tvalue: text(\"value\", { mode: \"json\" }).notNull(),\n});\n\nexport const illustrationMetadata = sqliteTable(\n\t\"illustration_metadata\",\n\t{\n\t\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\t\tplatform: text(\"platform\").notNull(),\n\t\turlHash: text(\"url_hash\").notNull(),\n\t\toriginalUrl: text(\"original_url\").notNull(),\n\t\tfileHash: text(\"file_hash\"),\n\t\tcontentType: text(\"content_type\"),\n\t\tcreatedAt: integer(\"created_at\").notNull(),\n\t},\n\t(table) => [\n\t\tuniqueIndex(\"illustration_platform_url_hash_idx\").on(\n\t\t\ttable.platform,\n\t\t\ttable.urlHash,\n\t\t),\n\t],\n);\n\nexport const bookshelfCategories = sqliteTable(\"bookshelf_categories\", {\n\tid: text(\"id\").primaryKey(),\n\tname: text(\"name\").notNull(),\n\tsortOrder: integer(\"sort_order\").notNull().default(0),\n\tcreatedAt: integer(\"created_at\").notNull(),\n\tupdatedAt: integer(\"updated_at\").notNull(),\n\tserverUpdatedAt: integer(\"server_updated_at\").notNull(),\n\tdeletedAt: integer(\"deleted_at\"),\n});\n\nexport const bookshelfItems = sqliteTable(\n\t\"bookshelf_items\",\n\t{\n\t\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\t\tplatform: text(\"platform\").notNull(),\n\t\tnovelId: text(\"novel_id\").notNull(),\n\t\ttitle: text(\"title\").notNull(),\n\t\tauthor: text(\"author\").notNull(),\n\t\tcoverUrl: text(\"cover_url\").notNull(),\n\t\taddedAt: integer(\"added_at\").notNull(),\n\t\tupdatedAt: integer(\"updated_at\").notNull(),\n\t\tserverUpdatedAt: integer(\"server_updated_at\").notNull(),\n\t\tdeletedAt: integer(\"deleted_at\"),\n\t\tcategoryIds: text(\"category_ids\").notNull().default(\"[]\"),\n\t\tgenresJson: text(\"genres_json\").notNull().default(\"[]\"),\n\t\tstatus: text(\"status\", {\n\t\t\tenum: [\"ongoing\", \"completed\", \"unknown\"],\n\t\t})\n\t\t\t.notNull()\n\t\t\t.default(\"unknown\"),\n\t},\n\t(table) => [\n\t\tuniqueIndex(\"bookshelf_platform_novel_idx\").on(\n\t\t\ttable.platform,\n\t\t\ttable.novelId,\n\t\t),\n\t],\n);\n\nexport const readingProgress = sqliteTable(\n\t\"reading_progress\",\n\t{\n\t\tid: integer(\"id\").primaryKey({ autoIncrement: true }),\n\t\tplatform: text(\"platform\").notNull(),\n\t\tnovelId: text(\"novel_id\").notNull(),\n\t\tnovelTitle: text(\"novel_title\").notNull(),\n\t\tcoverUrl: text(\"cover_url\").notNull(),\n\t\tvolumeId: text(\"volume_id\").notNull(),\n\t\tvolumeTitle: text(\"volume_title\").notNull(),\n\t\tchapterId: text(\"chapter_id\").notNull(),\n\t\tchapterTitle: text(\"chapter_title\").notNull(),\n\t\tparagraphIndex: integer(\"paragraph_index\").notNull(),\n\t\ttotalParagraphs: integer(\"total_paragraphs\").notNull(),\n\t\tdeviceLabel: text(\"device_label\").notNull(),\n\t\tupdatedAt: integer(\"updated_at\").notNull(),\n\t\tserverUpdatedAt: integer(\"server_updated_at\").notNull(),\n\t\thistoryHiddenAt: integer(\"history_hidden_at\"),\n\t},\n\t(table) => [\n\t\tuniqueIndex(\"reading_progress_platform_novel_idx\").on(\n\t\t\ttable.platform,\n\t\t\ttable.novelId,\n\t\t),\n\t],\n);\n\nexport const relations = defineRelations(\n\t{\n\t\tnovels,\n\t\tgenres,\n\t\tnovelGenres,\n\t\tvolumes,\n\t\tchapters,\n\t\tkeywordSearches,\n\t\tkeywordNovels,\n\t\tnovelCoverMetadata,\n\t\tvolumeCoverMetadata,\n\t\tcookies,\n\t\tgeneralCache,\n\t\tillustrationMetadata,\n\t\tbookshelfCategories,\n\t\tbookshelfItems,\n\t\treadingProgress,\n\t},\n\t(r) => ({\n\t\tnovels: {\n\t\t\tgenres: r.many.genres({\n\t\t\t\tfrom: r.novels.id.through(r.novelGenres.novelId),\n\t\t\t\tto: r.genres.id.through(r.novelGenres.genreId),\n\t\t\t}),\n\t\t\tvolumes: r.many.volumes({\n\t\t\t\tfrom: r.novels.id,\n\t\t\t\tto: r.volumes.novelId,\n\t\t\t}),\n\t\t\tcover: r.one.novelCoverMetadata({\n\t\t\t\tfrom: r.novels.id,\n\t\t\t\tto: r.novelCoverMetadata.novelId,\n\t\t\t}),\n\t\t},\n\t\tgenres: {\n\t\t\tnovels: r.many.novels(),\n\t\t},\n\t\tvolumes: {\n\t\t\tnovel: r.one.novels(),\n\t\t\tchapters: r.many.chapters({\n\t\t\t\tfrom: r.volumes.id,\n\t\t\t\tto: r.chapters.volumeId,\n\t\t\t}),\n\t\t\tcover: r.one.volumeCoverMetadata({\n\t\t\t\tfrom: r.volumes.id,\n\t\t\t\tto: r.volumeCoverMetadata.volumeId,\n\t\t\t}),\n\t\t},\n\t\tnovelCoverMetadata: {\n\t\t\tnovel: r.one.novels({\n\t\t\t\tfrom: r.novelCoverMetadata.novelId,\n\t\t\t\tto: r.novels.id,\n\t\t\t}),\n\t\t},\n\t\tvolumeCoverMetadata: {\n\t\t\tvolume: r.one.volumes({\n\t\t\t\tfrom: r.volumeCoverMetadata.volumeId,\n\t\t\t\tto: r.volumes.id,\n\t\t\t}),\n\t\t},\n\t\tchapters: {\n\t\t\tnovel: r.one.novels({\n\t\t\t\tfrom: r.chapters.novelId,\n\t\t\t\tto: r.novels.id,\n\t\t\t}),\n\t\t\tvolume: r.one.volumes(),\n\t\t},\n\t\tkeywordSearches: {\n\t\t\tnovels: r.many.novels({\n\t\t\t\tfrom: r.keywordSearches.keyword.through(r.keywordNovels.keyword),\n\t\t\t\tto: r.novels.id.through(r.keywordNovels.novelId),\n\t\t\t}),\n\t\t},\n\t}),\n);\n","import {\n\ttype Cookie,\n\ttype CookieOptions,\n\ttype CookiesInit,\n\ttype CookiesStore,\n\tcookieStoreSign,\n\tisCookiesStore,\n\tmatchesDomain,\n\tmatchesPath,\n} from \"@acanthis-dec/browser-fetch\";\nimport { eq } from \"drizzle-orm\";\nimport type { DatabaseService, DrizzleInstance } from \"./db\";\nimport { type CookieRow, cookies } from \"./table\";\n\nexport class DatabaseCookieStore implements CookiesStore {\n\tprivate db: DrizzleInstance;\n\t[cookieStoreSign] = true as const;\n\n\tconstructor(dbService: DatabaseService) {\n\t\tthis.db = dbService.db;\n\t}\n\n\tasync set(\n\t\tname: string,\n\t\tvalue: string,\n\t\toptions?: CookieOptions,\n\t): Promise<void> {\n\t\tconst cookie: Omit<CookieRow, \"id\"> = {\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tdomain: options?.domain ?? \"\",\n\t\t\tpath: options?.path ?? \"/\",\n\t\t\texpires: options?.expires?.getTime() ?? null,\n\t\t\tmaxAge: options?.maxAge ?? null,\n\t\t\tsecure: options?.secure ?? false,\n\t\t\thttpOnly: options?.httpOnly ?? false,\n\t\t\tsameSite: options?.sameSite ?? \"Lax\",\n\t\t\tcreatedAt: Date.now(),\n\t\t\tlastAccessedAt: Date.now(),\n\t\t};\n\t\tawait this.db\n\t\t\t.insert(cookies)\n\t\t\t.values(cookie)\n\t\t\t.onConflictDoUpdate({\n\t\t\t\ttarget: [cookies.domain, cookies.path, cookies.name],\n\t\t\t\tset: {\n\t\t\t\t\tvalue: cookie.value,\n\t\t\t\t\texpires: cookie.expires,\n\t\t\t\t\tmaxAge: cookie.maxAge,\n\t\t\t\t\tsecure: cookie.secure,\n\t\t\t\t\thttpOnly: cookie.httpOnly,\n\t\t\t\t\tsameSite: cookie.sameSite,\n\t\t\t\t\tcreatedAt: cookie.createdAt,\n\t\t\t\t\tlastAccessedAt: Date.now(),\n\t\t\t\t},\n\t\t\t})\n\t\t\t.run();\n\t}\n\tasync get(\n\t\tname: string,\n\t\tdomain?: string,\n\t\tpath?: string,\n\t): Promise<string | null> {\n\t\tconst result = await this.db.query.cookies.findFirst({\n\t\t\twhere: {\n\t\t\t\tname,\n\t\t\t\tdomain: domain ?? \"\",\n\t\t\t\tpath: path ?? \"/\",\n\t\t\t},\n\t\t});\n\t\tif (result) {\n\t\t\tawait this.db\n\t\t\t\t.update(cookies)\n\t\t\t\t.set({ lastAccessedAt: Date.now() })\n\t\t\t\t.where(eq(cookies.id, result.id))\n\t\t\t\t.run();\n\t\t\treturn result.value;\n\t\t}\n\t\tconst candidates = await this.db.query.cookies.findMany({\n\t\t\twhere: {\n\t\t\t\tname,\n\t\t\t},\n\t\t});\n\t\tconst hit = candidates.find((cookie) => {\n\t\t\tif (domain && cookie.domain && !matchesDomain(cookie.domain, domain))\n\t\t\t\treturn false;\n\t\t\tif (path && cookie.path && !matchesPath(cookie.path, path)) return false;\n\t\t\treturn true;\n\t\t});\n\n\t\tif (!hit) return null;\n\n\t\tawait this.db\n\t\t\t.update(cookies)\n\t\t\t.set({ lastAccessedAt: Date.now() })\n\t\t\t.where(eq(cookies.id, hit.id))\n\t\t\t.run();\n\n\t\treturn hit.value;\n\t}\n\tasync getCookie(\n\t\tname: string,\n\t\tdomain?: string,\n\t\tpath?: string,\n\t): Promise<Cookie | null> {\n\t\tconst result = await this.db.query.cookies.findFirst({\n\t\t\twhere: {\n\t\t\t\tname,\n\t\t\t\tdomain: domain ?? \"\",\n\t\t\t\tpath: path ?? \"/\",\n\t\t\t},\n\t\t});\n\t\tif (result) {\n\t\t\tawait this.db\n\t\t\t\t.update(cookies)\n\t\t\t\t.set({ lastAccessedAt: Date.now() })\n\t\t\t\t.where(eq(cookies.id, result.id))\n\t\t\t\t.run();\n\t\t\treturn {\n\t\t\t\tname: result.name,\n\t\t\t\tvalue: result.value,\n\t\t\t\tdomain: result.domain,\n\t\t\t\tpath: result.path,\n\t\t\t\texpires: result.expires ? new Date(result.expires) : undefined,\n\t\t\t\tmaxAge: result.maxAge ?? undefined,\n\t\t\t\tsecure: result.secure ?? undefined,\n\t\t\t\thttpOnly: result.httpOnly ?? undefined,\n\t\t\t\tsameSite: result.sameSite ?? \"Lax\",\n\t\t\t};\n\t\t}\n\t\tconst candidates = await this.db.query.cookies.findMany({\n\t\t\twhere: {\n\t\t\t\tname,\n\t\t\t},\n\t\t});\n\t\tconst hit = candidates.find((cookie) => {\n\t\t\tif (domain && cookie.domain && !matchesDomain(cookie.domain, domain))\n\t\t\t\treturn false;\n\t\t\tif (path && cookie.path && !matchesPath(cookie.path, path)) return false;\n\t\t\treturn true;\n\t\t});\n\n\t\tif (!hit) return null;\n\n\t\tawait this.db\n\t\t\t.update(cookies)\n\t\t\t.set({ lastAccessedAt: Date.now() })\n\t\t\t.where(eq(cookies.id, hit.id))\n\t\t\t.run();\n\n\t\treturn {\n\t\t\tname: hit.name,\n\t\t\tvalue: hit.value,\n\t\t\tdomain: hit.domain,\n\t\t\tpath: hit.path,\n\t\t\texpires: hit.expires ? new Date(hit.expires) : undefined,\n\t\t\tmaxAge: hit.maxAge ?? undefined,\n\t\t\tsecure: hit.secure ?? undefined,\n\t\t\thttpOnly: hit.httpOnly ?? undefined,\n\t\t\tsameSite: hit.sameSite ?? \"Lax\",\n\t\t};\n\t}\n\tasync delete(name: string, domain?: string, path?: string): Promise<boolean> {\n\t\tconst result = await this.db.query.cookies.findFirst({\n\t\t\twhere: {\n\t\t\t\tname,\n\t\t\t\tdomain: domain ?? \"\",\n\t\t\t\tpath: path ?? \"/\",\n\t\t\t},\n\t\t});\n\t\tif (result) {\n\t\t\tawait this.db.delete(cookies).where(eq(cookies.id, result.id)).run();\n\t\t\treturn true;\n\t\t}\n\t\tconst candidates = await this.db.query.cookies.findMany({\n\t\t\twhere: {\n\t\t\t\tname,\n\t\t\t},\n\t\t});\n\t\tconst hit = candidates.find((cookie) => {\n\t\t\tif (domain && cookie.domain && !matchesDomain(cookie.domain, domain))\n\t\t\t\treturn false;\n\t\t\tif (path && cookie.path && !matchesPath(cookie.path, path)) return false;\n\t\t\treturn true;\n\t\t});\n\n\t\tif (!hit) return false;\n\n\t\tawait this.db.delete(cookies).where(eq(cookies.id, hit.id)).run();\n\t\treturn true;\n\t}\n\tasync clear(domain?: string, path?: string): Promise<void> {\n\t\tif (!domain && !path) {\n\t\t\tawait this.db.delete(cookies).run();\n\t\t\treturn;\n\t\t}\n\t\tawait this.db.transaction(async (tx) => {\n\t\t\tconst candidates = await tx.query.cookies.findMany();\n\t\t\tconst toDelete = candidates.filter((cookie) => {\n\t\t\t\tif (domain && cookie.domain && !matchesDomain(cookie.domain, domain))\n\t\t\t\t\treturn false;\n\t\t\t\tif (path && cookie.path && !matchesPath(cookie.path, path))\n\t\t\t\t\treturn false;\n\t\t\t\treturn true;\n\t\t\t});\n\t\t\tfor (const cookie of toDelete) {\n\t\t\t\tawait tx.delete(cookies).where(eq(cookies.id, cookie.id)).run();\n\t\t\t}\n\t\t});\n\t}\n\tasync has(name: string, domain?: string, path?: string): Promise<boolean> {\n\t\treturn (await this.get(name, domain, path)) !== null;\n\t}\n\tasync getForUrl(url: string | URL): Promise<Cookie[]> {\n\t\tconst parsedUrl = typeof url === \"string\" ? new URL(url) : url;\n\t\tconst hostname = parsedUrl.hostname;\n\t\tconst pathname = parsedUrl.pathname;\n\t\tconst secure = parsedUrl.protocol === \"https:\";\n\t\tconst candidates = await this.db.query.cookies.findMany();\n\t\treturn candidates\n\t\t\t.filter((cookie) => {\n\t\t\t\tconst now = Date.now();\n\t\t\t\tif (cookie.secure && !secure) return false;\n\t\t\t\tif (cookie.domain && !matchesDomain(cookie.domain, hostname))\n\t\t\t\t\treturn false;\n\t\t\t\tif (cookie.path && !matchesPath(cookie.path, pathname)) return false;\n\t\t\t\tif (cookie.expires && cookie.expires < now) return false;\n\t\t\t\tif (cookie.maxAge) {\n\t\t\t\t\tconst age = (now - cookie.createdAt) / 1000;\n\t\t\t\t\tif (age > cookie.maxAge) return false;\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t})\n\t\t\t.map((cookie) => ({\n\t\t\t\tname: cookie.name,\n\t\t\t\tvalue: cookie.value,\n\t\t\t\tdomain: cookie.domain,\n\t\t\t\tpath: cookie.path,\n\t\t\t\texpires: cookie.expires ? new Date(cookie.expires) : undefined,\n\t\t\t\tmaxAge: cookie.maxAge ?? undefined,\n\t\t\t\tsecure: cookie.secure ?? undefined,\n\t\t\t\thttpOnly: cookie.httpOnly ?? undefined,\n\t\t\t\tsameSite: cookie.sameSite ?? \"Lax\",\n\t\t\t}));\n\t}\n\tasync update(init: CookiesInit): Promise<void> {\n\t\tif (isCookiesStore(init)) {\n\t\t\tfor await (const cookie of init) {\n\t\t\t\tawait this.set(cookie.name, cookie.value, {\n\t\t\t\t\tdomain: cookie.domain,\n\t\t\t\t\tpath: cookie.path,\n\t\t\t\t\texpires: cookie.expires,\n\t\t\t\t\tmaxAge: cookie.maxAge,\n\t\t\t\t\tsecure: cookie.secure,\n\t\t\t\t\thttpOnly: cookie.httpOnly,\n\t\t\t\t\tsameSite: cookie.sameSite ?? \"Lax\",\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (Array.isArray(init)) {\n\t\t\tfor (const cookie of init) {\n\t\t\t\tawait this.set(cookie.name, cookie.value, {\n\t\t\t\t\tdomain: cookie.domain,\n\t\t\t\t\tpath: cookie.path,\n\t\t\t\t\texpires: cookie.expires,\n\t\t\t\t\tmaxAge: cookie.maxAge,\n\t\t\t\t\tsecure: cookie.secure,\n\t\t\t\t\thttpOnly: cookie.httpOnly,\n\t\t\t\t\tsameSite: cookie.sameSite ?? \"Lax\",\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (typeof init === \"object\") {\n\t\t\tif (Symbol.iterator in init) {\n\t\t\t\tfor (const [name, value] of init as Iterable<[string, string]>) {\n\t\t\t\t\tawait this.set(name, value);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (const [name, value] of Object.entries(init)) {\n\t\t\t\t\tawait this.set(name, value);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t[Symbol.asyncIterator](): AsyncIterator<Cookie> {\n\t\tconst allCookies = this.db.query.cookies.findMany();\n\t\tlet index = 0;\n\t\treturn {\n\t\t\tnext: async () => {\n\t\t\t\tconst cookies = await allCookies;\n\t\t\t\tif (index < cookies.length) {\n\t\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: We check index against cookies.length, so this is safe\n\t\t\t\t\tconst cookie = cookies[index++]!;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\tname: cookie.name,\n\t\t\t\t\t\t\tvalue: cookie.value,\n\t\t\t\t\t\t\tdomain: cookie.domain,\n\t\t\t\t\t\t\tpath: cookie.path,\n\t\t\t\t\t\t\texpires: cookie.expires ? new Date(cookie.expires) : undefined,\n\t\t\t\t\t\t\tmaxAge: cookie.maxAge ?? undefined,\n\t\t\t\t\t\t\tsecure: cookie.secure ?? undefined,\n\t\t\t\t\t\t\thttpOnly: cookie.httpOnly ?? undefined,\n\t\t\t\t\t\t\tsameSite: cookie.sameSite ?? \"Lax\",\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn { done: true, value: undefined };\n\t\t\t},\n\t\t};\n\t}\n}\n","import { createHash } from \"node:crypto\";\nimport { zstdCompress as zc, zstdDecompress as zd } from \"node:zlib\";\n\nexport const zstdCompress = (data: Buffer): Promise<Buffer> => {\n\treturn new Promise((resolve, reject) => {\n\t\tzc(data, (err, compressedData) => {\n\t\t\tif (err) {\n\t\t\t\treject(err);\n\t\t\t} else {\n\t\t\t\tresolve(compressedData);\n\t\t\t}\n\t\t});\n\t});\n};\n\nexport const zstdDecompress = (data: Buffer): Promise<Buffer> => {\n\treturn new Promise((resolve, reject) => {\n\t\tzd(data, (err, decompressedData) => {\n\t\t\tif (err) {\n\t\t\t\treject(err);\n\t\t\t} else {\n\t\t\t\tresolve(decompressedData);\n\t\t\t}\n\t\t});\n\t});\n};\n\nexport function getCoverHash(data: Buffer): string {\n\treturn createHash(\"md5\").update(data).digest(\"hex\");\n}\n\nexport function getContentHash(content: string): string {\n\treturn createHash(\"md5\").update(content).digest(\"hex\");\n}\n\nexport function getUrlHash(url: string): string {\n\treturn createHash(\"md5\").update(url).digest(\"hex\");\n}\n\nexport function getExtFromContentType(contentType: string): string {\n\tif (contentType.includes(\"jpeg\") || contentType.includes(\"jpg\")) return \"jpg\";\n\tif (contentType.includes(\"png\")) return \"png\";\n\tif (contentType.includes(\"gif\")) return \"gif\";\n\tif (contentType.includes(\"webp\")) return \"webp\";\n\tif (contentType.includes(\"avif\")) return \"avif\";\n\treturn \"bin\";\n}\n","import { existsSync, mkdirSync, rmSync, statSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport type {\n\tBookshelfCategory,\n\tBookshelfItem,\n\tCachedGenreItem,\n\tChapter,\n\tNovel,\n\tNovelInfo,\n\tNovelSearchResult,\n\tNovelStatus,\n\tReadingProgress,\n\tVolume,\n} from \"@acanthis-dec/core\";\nimport { type Client, createClient } from \"@libsql/client\";\nimport {\n\tand,\n\tasc,\n\tcount,\n\tdesc,\n\teq,\n\tgt,\n\tinArray,\n\tisNull,\n\tmax,\n\tne,\n\tnotInArray,\n\tor,\n\ttype SQL,\n\tsql,\n} from \"drizzle-orm\";\nimport { drizzle } from \"drizzle-orm/libsql\";\nimport { migrate } from \"drizzle-orm/libsql/migrator\";\nimport type { z } from \"zod\";\nimport {\n\tbookshelfCategories,\n\tbookshelfItems,\n\tchapters,\n\tgeneralCache,\n\tgenres,\n\tillustrationMetadata,\n\tkeywordNovels,\n\tkeywordSearches,\n\tnovelCoverMetadata,\n\tnovelGenres,\n\tnovels,\n\treadingProgress,\n\trelations,\n\tvolumeCoverMetadata,\n\tvolumes,\n} from \"./table\";\nimport type {\n\tDataWithUpdatedAt,\n\tListNovelsOptions,\n\tMergeSyncStateInput,\n\tMergeSyncStateResult,\n\tNovelCoverMetadata,\n\tPaginatedNovels,\n\tSyncStateResult,\n\tVolumeCoverMetadata,\n} from \"./type\";\nimport { getUrlHash } from \"./utils\";\n\nexport type MigrationOptions = {\n\tenabled?: boolean;\n\tdirectory?: string;\n};\n\nexport type DatabaseOptions = {\n\tpath: string;\n\tmigrations?: MigrationOptions;\n};\n\nfunction getDrizzle(client: Client) {\n\treturn drizzle({\n\t\tclient,\n\t\trelations,\n\t});\n}\n\nexport type DrizzleInstance = ReturnType<typeof getDrizzle>;\n\nconst CLOCK_SKEW_TOLERANCE_MS = 60_000;\n\nfunction normalizeStringList(values: readonly string[] | undefined): string[] {\n\tif (!values || values.length === 0) {\n\t\treturn [];\n\t}\n\tconst seen = new Set<string>();\n\tconst result: string[] = [];\n\tfor (const raw of values) {\n\t\tconst trimmed = raw.trim();\n\t\tif (!trimmed || seen.has(trimmed)) {\n\t\t\tcontinue;\n\t\t}\n\t\tseen.add(trimmed);\n\t\tresult.push(trimmed);\n\t}\n\treturn result;\n}\n\nfunction parseJsonStringArray(raw: string | null | undefined): string[] {\n\tif (!raw) {\n\t\treturn [];\n\t}\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(raw);\n\t\tif (!Array.isArray(parsed)) {\n\t\t\treturn [];\n\t\t}\n\t\treturn normalizeStringList(\n\t\t\tparsed.filter((entry): entry is string => typeof entry === \"string\"),\n\t\t);\n\t} catch {\n\t\treturn [];\n\t}\n}\n\nfunction escapeLikePattern(value: string): string {\n\treturn value\n\t\t.replaceAll(\"\\\\\", \"\\\\\\\\\")\n\t\t.replaceAll(\"%\", \"\\\\%\")\n\t\t.replaceAll(\"_\", \"\\\\_\");\n}\n\nfunction toBookshelfCategory(\n\trow: typeof bookshelfCategories.$inferSelect,\n): BookshelfCategory {\n\treturn {\n\t\tid: row.id,\n\t\tname: row.name,\n\t\tsortOrder: row.sortOrder,\n\t\tcreatedAt: row.createdAt,\n\t\tupdatedAt: row.updatedAt,\n\t\tdeletedAt: row.deletedAt,\n\t};\n}\n\nfunction toBookshelfItem(\n\trow: typeof bookshelfItems.$inferSelect,\n): BookshelfItem {\n\treturn {\n\t\tplatform: row.platform,\n\t\tnovelId: row.novelId,\n\t\ttitle: row.title,\n\t\tauthor: row.author,\n\t\tcoverUrl: row.coverUrl,\n\t\taddedAt: row.addedAt,\n\t\tupdatedAt: row.updatedAt,\n\t\tdeletedAt: row.deletedAt,\n\t\tcategoryIds: parseJsonStringArray(row.categoryIds),\n\t\tgenres: parseJsonStringArray(row.genresJson),\n\t\tstatus: row.status,\n\t};\n}\n\nfunction toReadingProgress(\n\trow: typeof readingProgress.$inferSelect,\n): ReadingProgress {\n\treturn {\n\t\tplatform: row.platform,\n\t\tnovelId: row.novelId,\n\t\tnovelTitle: row.novelTitle,\n\t\tcoverUrl: row.coverUrl,\n\t\tvolumeId: row.volumeId,\n\t\tvolumeTitle: row.volumeTitle,\n\t\tchapterId: row.chapterId,\n\t\tchapterTitle: row.chapterTitle,\n\t\tparagraphIndex: row.paragraphIndex,\n\t\ttotalParagraphs: row.totalParagraphs,\n\t\tdeviceLabel: row.deviceLabel,\n\t\tupdatedAt: row.updatedAt,\n\t\thistoryHiddenAt: row.historyHiddenAt ?? null,\n\t};\n}\n\nexport class DatabaseService {\n\tprivate client: Client;\n\tprivate readyPromise: Promise<void>;\n\tdb: DrizzleInstance;\n\n\tconstructor(options: DatabaseOptions) {\n\t\tconst parentDir = dirname(resolve(options.path));\n\t\tif (!existsSync(parentDir)) {\n\t\t\tmkdirSync(parentDir, { recursive: true });\n\t\t} else if (existsSync(parentDir) && statSync(parentDir).isFile() === true) {\n\t\t\trmSync(parentDir);\n\t\t\tmkdirSync(parentDir, { recursive: true });\n\t\t}\n\t\tthis.client = createClient({\n\t\t\turl: `file:${options.path}`,\n\t\t});\n\t\tthis.db = getDrizzle(this.client);\n\t\tthis.readyPromise = this._init(options);\n\t}\n\n\tprivate async _init(options: DatabaseOptions): Promise<void> {\n\t\tawait this.client.execute(\"PRAGMA journal_mode = WAL;\");\n\t\tif (options.migrations?.enabled ?? true) {\n\t\t\tawait this._migrate(options.migrations?.directory);\n\t\t}\n\t}\n\n\tprivate async _migrate(directory?: string): Promise<void> {\n\t\tif (!this.db) throw new Error(\"Database not initialized\");\n\t\tawait migrate(this.db, {\n\t\t\tmigrationsFolder: directory || \"migrations\",\n\t\t});\n\t}\n\n\tprivate async ensureReady(): Promise<void> {\n\t\tawait this.readyPromise;\n\t}\n\n\tasync addSearchResult(\n\t\tkeyword: string,\n\t\tplatform: string,\n\t\tresults: NovelSearchResult[],\n\t) {\n\t\tawait this.ensureReady();\n\t\tawait this.db.transaction(async (tx) => {\n\t\t\tawait tx\n\t\t\t\t.insert(keywordSearches)\n\t\t\t\t.values({\n\t\t\t\t\tkeyword,\n\t\t\t\t\tplatform,\n\t\t\t\t\tqueryTime: Date.now(),\n\t\t\t\t\ttotal: results.length,\n\t\t\t\t})\n\t\t\t\t.onConflictDoUpdate({\n\t\t\t\t\ttarget: keywordSearches.keyword,\n\t\t\t\t\tset: {\n\t\t\t\t\t\tqueryTime: Date.now(),\n\t\t\t\t\t\ttotal: results.length,\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\t.run();\n\n\t\t\tfor (const novel of results) {\n\t\t\t\tconst inserted = await tx\n\t\t\t\t\t.insert(novels)\n\t\t\t\t\t.values({\n\t\t\t\t\t\tplatform: novel.platform,\n\t\t\t\t\t\tplatformId: novel.id,\n\t\t\t\t\t\tname: novel.title,\n\t\t\t\t\t\tcoverUrl: novel.coverUrl ?? \"\",\n\t\t\t\t\t\tauthor: \"\",\n\t\t\t\t\t\tsummary: \"\",\n\t\t\t\t\t\tstatus: \"unknown\",\n\t\t\t\t\t\tupdateAt: Date.now(),\n\t\t\t\t\t})\n\t\t\t\t\t.onConflictDoUpdate({\n\t\t\t\t\t\ttarget: [novels.platform, novels.platformId],\n\t\t\t\t\t\tset: {\n\t\t\t\t\t\t\tname: novel.title,\n\t\t\t\t\t\t\tcoverUrl: novel.coverUrl ?? \"\",\n\t\t\t\t\t\t\tupdateAt: Date.now(),\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t\t.returning({ id: novels.id })\n\t\t\t\t\t.get();\n\n\t\t\t\tconst novelId = inserted.id;\n\t\t\t\tif (novelId) {\n\t\t\t\t\tawait tx\n\t\t\t\t\t\t.insert(keywordNovels)\n\t\t\t\t\t\t.values({\n\t\t\t\t\t\t\tnovelId,\n\t\t\t\t\t\t\tkeyword,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.onConflictDoNothing()\n\t\t\t\t\t\t.run();\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tasync searchNovels(\n\t\tkeyword: string,\n\t\tplatform: string,\n\t): Promise<DataWithUpdatedAt<NovelSearchResult[] | undefined>> {\n\t\tawait this.ensureReady();\n\t\tconst minQueryTime = Date.now() - 48 * 60 * 60 * 1000; // 48 hours\n\n\t\tconst searchRecord = await this.db.query.keywordSearches\n\t\t\t.findFirst({\n\t\t\t\twhere: {\n\t\t\t\t\tkeyword,\n\t\t\t\t\tplatform,\n\t\t\t\t\tqueryTime: {\n\t\t\t\t\t\tgte: minQueryTime,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\twith: {\n\t\t\t\t\tnovels: {\n\t\t\t\t\t\tcolumns: {\n\t\t\t\t\t\t\tplatform: true,\n\t\t\t\t\t\t\tplatformId: true,\n\t\t\t\t\t\t\tname: true,\n\t\t\t\t\t\t\tcoverUrl: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t})\n\t\t\t.execute();\n\n\t\treturn {\n\t\t\tdata:\n\t\t\t\tsearchRecord?.novels.map((novel) => ({\n\t\t\t\t\tplatform: novel.platform,\n\t\t\t\t\tid: novel.platformId,\n\t\t\t\t\ttitle: novel.name,\n\t\t\t\t\tcoverUrl: novel.coverUrl,\n\t\t\t\t})) || undefined,\n\t\t\tupdatedAt: searchRecord?.queryTime || 0,\n\t\t};\n\t}\n\n\tasync addNovelCache(novel: Novel) {\n\t\tawait this.ensureReady();\n\t\tawait this.db.transaction(async (tx) => {\n\t\t\tconst { id: novelId } = await tx\n\t\t\t\t.insert(novels)\n\t\t\t\t.values({\n\t\t\t\t\tplatform: novel.platform,\n\t\t\t\t\tplatformId: novel.id,\n\t\t\t\t\tname: novel.title,\n\t\t\t\t\tcoverUrl: novel.coverUrl ?? \"\",\n\t\t\t\t\tauthor: novel.author ?? \"\",\n\t\t\t\t\tsummary: novel.summary ?? \"\",\n\t\t\t\t\tstatus: novel.status ?? \"unknown\",\n\t\t\t\t\tupdateAt: Date.now(),\n\t\t\t\t})\n\t\t\t\t.onConflictDoUpdate({\n\t\t\t\t\ttarget: [novels.platform, novels.platformId],\n\t\t\t\t\tset: {\n\t\t\t\t\t\tname: novel.title,\n\t\t\t\t\t\tcoverUrl: novel.coverUrl ?? \"\",\n\t\t\t\t\t\tauthor: novel.author ?? \"\",\n\t\t\t\t\t\tsummary: novel.summary ?? \"\",\n\t\t\t\t\t\tstatus: novel.status ?? \"unknown\",\n\t\t\t\t\t\tupdateAt: Date.now(),\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\t.returning({ id: novels.id })\n\t\t\t\t.get();\n\n\t\t\tfor (const genre of novel.genres) {\n\t\t\t\tconst { id: genreId } = await tx\n\t\t\t\t\t.insert(genres)\n\t\t\t\t\t.values({\n\t\t\t\t\t\tname: genre,\n\t\t\t\t\t})\n\t\t\t\t\t.onConflictDoUpdate({\n\t\t\t\t\t\ttarget: genres.name,\n\t\t\t\t\t\tset: {\n\t\t\t\t\t\t\tname: genre,\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t\t.returning({ id: genres.id })\n\t\t\t\t\t.get();\n\t\t\t\tawait tx\n\t\t\t\t\t.insert(novelGenres)\n\t\t\t\t\t.values({\n\t\t\t\t\t\tnovelId,\n\t\t\t\t\t\tgenreId,\n\t\t\t\t\t})\n\t\t\t\t\t.onConflictDoNothing()\n\t\t\t\t\t.run();\n\t\t\t}\n\n\t\t\tconst volumePlatformIds: string[] = [];\n\t\t\tconst chapterPlatformIds: string[] = [];\n\n\t\t\tfor (const volume of novel.volumes) {\n\t\t\t\tvolumePlatformIds.push(volume.id);\n\t\t\t\tconst { id: volumeId } = await tx\n\t\t\t\t\t.insert(volumes)\n\t\t\t\t\t.values({\n\t\t\t\t\t\tnovelId,\n\t\t\t\t\t\tname: volume.title,\n\t\t\t\t\t\tplatform: novel.platform,\n\t\t\t\t\t\tplatformId: volume.id,\n\t\t\t\t\t\tcoverUrl: volume.coverUrl ?? \"\",\n\t\t\t\t\t})\n\t\t\t\t\t.onConflictDoUpdate({\n\t\t\t\t\t\ttarget: [volumes.novelId, volumes.platformId],\n\t\t\t\t\t\tset: {\n\t\t\t\t\t\t\tname: volume.title,\n\t\t\t\t\t\t\tcoverUrl: volume.coverUrl ?? \"\",\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t\t.returning({ id: volumes.id })\n\t\t\t\t\t.get();\n\t\t\t\tfor (const chapter of volume.chapters) {\n\t\t\t\t\tchapterPlatformIds.push(chapter.id);\n\t\t\t\t\tawait tx\n\t\t\t\t\t\t.insert(chapters)\n\t\t\t\t\t\t.values({\n\t\t\t\t\t\t\tnovelId,\n\t\t\t\t\t\t\tvolumeId,\n\t\t\t\t\t\t\tname: chapter.title,\n\t\t\t\t\t\t\tplatform: novel.platform,\n\t\t\t\t\t\t\tplatformId: chapter.id,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.onConflictDoUpdate({\n\t\t\t\t\t\t\ttarget: [chapters.novelId, chapters.platformId],\n\t\t\t\t\t\t\tset: {\n\t\t\t\t\t\t\t\tvolumeId,\n\t\t\t\t\t\t\t\tname: chapter.title,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.run();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (chapterPlatformIds.length > 0) {\n\t\t\t\tawait tx\n\t\t\t\t\t.delete(chapters)\n\t\t\t\t\t.where(\n\t\t\t\t\t\tand(\n\t\t\t\t\t\t\teq(chapters.novelId, novelId),\n\t\t\t\t\t\t\tnotInArray(chapters.platformId, chapterPlatformIds),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\t.run();\n\t\t\t} else {\n\t\t\t\tawait tx.delete(chapters).where(eq(chapters.novelId, novelId)).run();\n\t\t\t}\n\n\t\t\tif (volumePlatformIds.length > 0) {\n\t\t\t\tawait tx\n\t\t\t\t\t.delete(volumes)\n\t\t\t\t\t.where(\n\t\t\t\t\t\tand(\n\t\t\t\t\t\t\teq(volumes.novelId, novelId),\n\t\t\t\t\t\t\tnotInArray(volumes.platformId, volumePlatformIds),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\t.run();\n\t\t\t} else {\n\t\t\t\tawait tx.delete(volumes).where(eq(volumes.novelId, novelId)).run();\n\t\t\t}\n\t\t});\n\t}\n\n\tasync getNovelCache(\n\t\tplatform: string,\n\t\tplatformId: string,\n\t): Promise<DataWithUpdatedAt<Novel | null>> {\n\t\tawait this.ensureReady();\n\t\tconst novelRecord = await this.db.query.novels\n\t\t\t.findFirst({\n\t\t\t\twhere: {\n\t\t\t\t\tplatform,\n\t\t\t\t\tplatformId,\n\t\t\t\t},\n\t\t\t\twith: {\n\t\t\t\t\tgenres: true,\n\t\t\t\t\tvolumes: {\n\t\t\t\t\t\torderBy: {\n\t\t\t\t\t\t\tid: \"asc\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\twith: {\n\t\t\t\t\t\t\tchapters: {\n\t\t\t\t\t\t\t\torderBy: {\n\t\t\t\t\t\t\t\t\tid: \"asc\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t})\n\t\t\t.execute();\n\n\t\tif (!novelRecord) {\n\t\t\treturn {\n\t\t\t\tdata: null,\n\t\t\t\tupdatedAt: 0,\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tdata: {\n\t\t\t\tplatform: novelRecord.platform,\n\t\t\t\tid: novelRecord.platformId,\n\t\t\t\ttitle: novelRecord.name,\n\t\t\t\tcoverUrl: novelRecord.coverUrl,\n\t\t\t\tauthor: novelRecord.author,\n\t\t\t\tsummary: novelRecord.summary,\n\t\t\t\tstatus: novelRecord.status,\n\t\t\t\tgenres: novelRecord.genres.map((g) => g.name),\n\t\t\t\tvolumes: novelRecord.volumes.map((v) => ({\n\t\t\t\t\tid: v.platformId,\n\t\t\t\t\tplatform: novelRecord.platform,\n\t\t\t\t\ttitle: v.name,\n\t\t\t\t\tcoverUrl: v.coverUrl ?? \"\",\n\t\t\t\t\tnovelId: novelRecord.platformId,\n\t\t\t\t\tchapters: v.chapters.map((c) => ({\n\t\t\t\t\t\tid: c.platformId,\n\t\t\t\t\t\tplatform: novelRecord.platform,\n\t\t\t\t\t\ttitle: c.name,\n\t\t\t\t\t})),\n\t\t\t\t})),\n\t\t\t},\n\t\t\tupdatedAt: novelRecord.updateAt,\n\t\t};\n\t}\n\n\tasync getVolumeMeta(\n\t\tplatform: string,\n\t\tplatformId: string,\n\t): Promise<Volume | undefined> {\n\t\tawait this.ensureReady();\n\t\tconst volumeRecord = await this.db.query.volumes\n\t\t\t.findFirst({\n\t\t\t\twhere: {\n\t\t\t\t\tplatform,\n\t\t\t\t\tplatformId,\n\t\t\t\t},\n\t\t\t\twith: {\n\t\t\t\t\tnovel: true,\n\t\t\t\t\tchapters: {\n\t\t\t\t\t\torderBy: {\n\t\t\t\t\t\t\tid: \"asc\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\torderBy: {\n\t\t\t\t\tid: \"asc\",\n\t\t\t\t},\n\t\t\t})\n\t\t\t.execute();\n\n\t\tif (!volumeRecord) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tid: volumeRecord.platformId,\n\t\t\tplatform: volumeRecord.platform,\n\t\t\ttitle: volumeRecord.name,\n\t\t\tnovelId: volumeRecord.novel?.platformId ?? \"\",\n\t\t\tcoverUrl: volumeRecord.coverUrl ?? \"\",\n\t\t\tchapters: [],\n\t\t};\n\t}\n\n\tasync getChapterFromTitle(\n\t\ttitle: string,\n\t): Promise<Partial<Chapter> | undefined> {\n\t\tawait this.ensureReady();\n\t\tconst chapterRecord = await this.db.query.chapters\n\t\t\t.findFirst({\n\t\t\t\twhere: {\n\t\t\t\t\tname: title,\n\t\t\t\t},\n\t\t\t})\n\t\t\t.execute();\n\n\t\tif (!chapterRecord) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tid: chapterRecord.platformId,\n\t\t\ttitle: chapterRecord.name,\n\t\t};\n\t}\n\n\tasync getChapterFromId(\n\t\tplatform: string,\n\t\tplatformId: string,\n\t): Promise<Chapter | undefined> {\n\t\tawait this.ensureReady();\n\t\tconst chapterRecord = await this.db.query.chapters\n\t\t\t.findFirst({\n\t\t\t\twhere: {\n\t\t\t\t\tplatformId,\n\t\t\t\t\tnovel: {\n\t\t\t\t\t\tplatform,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\twith: {\n\t\t\t\t\tnovel: true,\n\t\t\t\t\tvolume: true,\n\t\t\t\t},\n\t\t\t})\n\t\t\t.execute();\n\n\t\tif (!chapterRecord) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tid: chapterRecord.platformId,\n\t\t\tplatform: chapterRecord.platform,\n\t\t\ttitle: chapterRecord.name,\n\t\t\tnovelId: chapterRecord.novel?.platformId ?? \"\",\n\t\t\tvolumeId: chapterRecord.volume?.platformId ?? \"\",\n\t\t\tcontentHash: chapterRecord.contentHash ?? null,\n\t\t};\n\t}\n\n\tasync addNovelContentHash(\n\t\tplatform: string,\n\t\tchapterId: string,\n\t\tcontentHash: string,\n\t) {\n\t\tawait this.ensureReady();\n\t\tawait this.db\n\t\t\t.update(chapters)\n\t\t\t.set({ contentHash })\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(chapters.platformId, chapterId),\n\t\t\t\t\teq(chapters.platform, platform),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.run();\n\t}\n\n\tasync getNovelCoverMetadata(\n\t\tplatform: string,\n\t\tnovelId: string,\n\t): Promise<NovelCoverMetadata | undefined> {\n\t\tawait this.ensureReady();\n\t\tconst queryResult = await this.db.query.novelCoverMetadata\n\t\t\t.findFirst({\n\t\t\t\twhere: {\n\t\t\t\t\tnovel: {\n\t\t\t\t\t\tplatform: platform,\n\t\t\t\t\t\tplatformId: novelId,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\twith: {\n\t\t\t\t\tnovel: true,\n\t\t\t\t},\n\t\t\t})\n\t\t\t.execute();\n\n\t\tif (!queryResult) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tplatform: queryResult.novel?.platform ?? null,\n\t\t\tnovelId: queryResult.novel?.platformId ?? null,\n\t\t\thash: queryResult.hash ?? \"\",\n\t\t\tcontentType: queryResult.contentType ?? \"\",\n\t\t\toriginalUrl: queryResult.originalUrl ?? \"\",\n\t\t};\n\t}\n\n\tasync addNovelCoverMetadata(metadata: NovelCoverMetadata) {\n\t\tawait this.ensureReady();\n\t\tconst novel =\n\t\t\tmetadata.novelId && metadata.platform\n\t\t\t\t? await this.db.query.novels\n\t\t\t\t\t\t.findFirst({\n\t\t\t\t\t\t\twhere: {\n\t\t\t\t\t\t\t\tplatform: metadata.platform,\n\t\t\t\t\t\t\t\tplatformId: metadata.novelId,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.execute()\n\t\t\t\t: null;\n\n\t\tlet novelId: number | null = null;\n\t\tif (!novel) {\n\t\t\tconst result = await this.db\n\t\t\t\t.insert(novels)\n\t\t\t\t.values({\n\t\t\t\t\tplatform: metadata.platform ?? \"\",\n\t\t\t\t\tplatformId: metadata.novelId ?? \"\",\n\t\t\t\t\tname: \"\",\n\t\t\t\t\tcoverUrl: metadata.originalUrl ?? \"\",\n\t\t\t\t\tauthor: \"\",\n\t\t\t\t\tsummary: \"\",\n\t\t\t\t\tstatus: \"unknown\",\n\t\t\t\t\tupdateAt: Date.now(),\n\t\t\t\t})\n\t\t\t\t.onConflictDoNothing()\n\t\t\t\t.returning({ id: novels.id })\n\t\t\t\t.get();\n\t\t\tnovelId = result?.id ?? null;\n\t\t}\n\n\t\tawait this.db\n\t\t\t.insert(novelCoverMetadata)\n\t\t\t.values({\n\t\t\t\thash: metadata.hash,\n\t\t\t\tcontentType: metadata.contentType,\n\t\t\t\toriginalUrl: metadata.originalUrl,\n\t\t\t\tnovelId: novel?.id ?? novelId ?? null,\n\t\t\t})\n\t\t\t.onConflictDoNothing()\n\t\t\t.run();\n\t}\n\n\tasync getVolumeCoverMetadata(\n\t\tplatform: string,\n\t\tvolumeId: string,\n\t): Promise<VolumeCoverMetadata | undefined> {\n\t\tawait this.ensureReady();\n\t\tconst queryResult = await this.db.query.volumeCoverMetadata\n\t\t\t.findFirst({\n\t\t\t\twhere: {\n\t\t\t\t\tvolume: {\n\t\t\t\t\t\tplatform: platform,\n\t\t\t\t\t\tplatformId: volumeId,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\twith: {\n\t\t\t\t\tvolume: {\n\t\t\t\t\t\twith: {\n\t\t\t\t\t\t\tnovel: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t})\n\t\t\t.execute();\n\n\t\tif (!queryResult) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tplatform: queryResult.volume?.platform ?? null,\n\t\t\tvolumeId: queryResult.volume?.platformId ?? null,\n\t\t\thash: queryResult.hash ?? \"\",\n\t\t\tcontentType: queryResult.contentType ?? \"\",\n\t\t\toriginalUrl: queryResult.originalUrl ?? \"\",\n\t\t};\n\t}\n\n\tasync addVolumeCoverMetadata(metadata: VolumeCoverMetadata) {\n\t\tawait this.ensureReady();\n\t\tconst volume =\n\t\t\tmetadata.volumeId && metadata.platform\n\t\t\t\t? await this.db.query.volumes\n\t\t\t\t\t\t.findFirst({\n\t\t\t\t\t\t\twhere: {\n\t\t\t\t\t\t\t\tplatform: metadata.platform,\n\t\t\t\t\t\t\t\tplatformId: metadata.volumeId,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.execute()\n\t\t\t\t: null;\n\n\t\tawait this.db\n\t\t\t.insert(volumeCoverMetadata)\n\t\t\t.values({\n\t\t\t\thash: metadata.hash,\n\t\t\t\tcontentType: metadata.contentType,\n\t\t\t\toriginalUrl: metadata.originalUrl,\n\t\t\t\tvolumeId: volume?.id ?? null,\n\t\t\t})\n\t\t\t.onConflictDoNothing()\n\t\t\t.run();\n\t}\n\n\tasync getCache<T>(key: string, schema: z.ZodType<T>): Promise<T | null> {\n\t\tawait this.ensureReady();\n\t\tconst record = await this.db.query.generalCache\n\t\t\t.findFirst({\n\t\t\t\twhere: {\n\t\t\t\t\tkey,\n\t\t\t\t},\n\t\t\t})\n\t\t\t.execute();\n\n\t\tif (!record) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst parsed = schema.safeParse(record.value);\n\t\treturn parsed.success ? parsed.data : null;\n\t}\n\n\tasync setCache<T>(key: string, value: T): Promise<void> {\n\t\tawait this.ensureReady();\n\t\tawait this.db\n\t\t\t.insert(generalCache)\n\t\t\t.values({ key, value })\n\t\t\t.onConflictDoUpdate({\n\t\t\t\ttarget: generalCache.key,\n\t\t\t\tset: { value },\n\t\t\t})\n\t\t\t.run();\n\t}\n\n\tasync registerIllustrations(\n\t\tplatform: string,\n\t\titems: string[] | { urlHash: string; originalUrl: string }[],\n\t): Promise<void> {\n\t\tawait this.ensureReady();\n\t\tconst uniqueItems = new Map<\n\t\t\tstring,\n\t\t\t{ urlHash: string; originalUrl: string }\n\t\t>();\n\t\tfor (const item of items) {\n\t\t\tif (typeof item === \"string\") {\n\t\t\t\tconst trimmed = item.trim();\n\t\t\t\tif (!trimmed) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst urlHash = getUrlHash(trimmed);\n\t\t\t\tif (!uniqueItems.has(urlHash)) {\n\t\t\t\t\tuniqueItems.set(urlHash, { urlHash, originalUrl: trimmed });\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst urlHash = item.urlHash.trim();\n\t\t\t\tconst originalUrl = item.originalUrl.trim();\n\t\t\t\tif (!urlHash || !originalUrl) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (!uniqueItems.has(urlHash)) {\n\t\t\t\t\tuniqueItems.set(urlHash, { urlHash, originalUrl });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (uniqueItems.size === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst createdAt = Date.now();\n\t\tconst rows = Array.from(uniqueItems.values()).map((entry) => ({\n\t\t\tplatform,\n\t\t\turlHash: entry.urlHash,\n\t\t\toriginalUrl: entry.originalUrl,\n\t\t\tcreatedAt,\n\t\t}));\n\n\t\tconst chunkSize = 200;\n\t\tawait this.db.transaction(async (tx) => {\n\t\t\tfor (let i = 0; i < rows.length; i += chunkSize) {\n\t\t\t\tconst chunk = rows.slice(i, i + chunkSize);\n\t\t\t\tawait tx\n\t\t\t\t\t.insert(illustrationMetadata)\n\t\t\t\t\t.values(chunk)\n\t\t\t\t\t.onConflictDoNothing({\n\t\t\t\t\t\ttarget: [\n\t\t\t\t\t\t\tillustrationMetadata.platform,\n\t\t\t\t\t\t\tillustrationMetadata.urlHash,\n\t\t\t\t\t\t],\n\t\t\t\t\t})\n\t\t\t\t\t.run();\n\t\t\t}\n\t\t});\n\t}\n\n\tasync getIllustrationSourceUrl(\n\t\tplatform: string,\n\t\turlHash: string,\n\t): Promise<string | undefined> {\n\t\tawait this.ensureReady();\n\t\tconst record = await this.db\n\t\t\t.select({ originalUrl: illustrationMetadata.originalUrl })\n\t\t\t.from(illustrationMetadata)\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(illustrationMetadata.platform, platform),\n\t\t\t\t\teq(illustrationMetadata.urlHash, urlHash),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.get();\n\n\t\treturn record?.originalUrl;\n\t}\n\n\tasync getIllustrationMetadata(\n\t\tplatform: string,\n\t\turlHash: string,\n\t): Promise<\n\t\t| {\n\t\t\t\toriginalUrl: string;\n\t\t\t\tfileHash: string | null;\n\t\t\t\tcontentType: string | null;\n\t\t }\n\t\t| undefined\n\t> {\n\t\tawait this.ensureReady();\n\t\treturn await this.db\n\t\t\t.select({\n\t\t\t\toriginalUrl: illustrationMetadata.originalUrl,\n\t\t\t\tfileHash: illustrationMetadata.fileHash,\n\t\t\t\tcontentType: illustrationMetadata.contentType,\n\t\t\t})\n\t\t\t.from(illustrationMetadata)\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(illustrationMetadata.platform, platform),\n\t\t\t\t\teq(illustrationMetadata.urlHash, urlHash),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.get();\n\t}\n\n\tasync updateIllustrationFileInfo(\n\t\tplatform: string,\n\t\turlHash: string,\n\t\tfileHash: string,\n\t\tcontentType: string,\n\t): Promise<void> {\n\t\tawait this.ensureReady();\n\t\tawait this.db\n\t\t\t.update(illustrationMetadata)\n\t\t\t.set({ fileHash, contentType })\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(illustrationMetadata.platform, platform),\n\t\t\t\t\teq(illustrationMetadata.urlHash, urlHash),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.run();\n\t}\n\n\tasync listCachedNovels(\n\t\tplatform: string,\n\t\toptions: ListNovelsOptions,\n\t): Promise<PaginatedNovels> {\n\t\tawait this.ensureReady();\n\t\tconst page = Math.max(1, Math.trunc(options.page));\n\t\tconst pageSize = Math.max(1, Math.trunc(options.pageSize));\n\t\tconst offset = (page - 1) * pageSize;\n\n\t\tconst conditions: SQL[] = [\n\t\t\teq(novels.platform, platform),\n\t\t\tne(novels.author, \"\"),\n\t\t\tne(novels.name, \"\"),\n\t\t];\n\n\t\tif (options.status !== undefined) {\n\t\t\tconditions.push(eq(novels.status, options.status));\n\t\t} else {\n\t\t\tconditions.push(ne(novels.status, \"unknown\"));\n\t\t}\n\n\t\tconst trimmedQuery = options.q?.trim();\n\t\tif (trimmedQuery) {\n\t\t\tconst escaped = escapeLikePattern(trimmedQuery.toLowerCase());\n\t\t\tconst pattern = `%${escaped}%`;\n\t\t\tconst keywordCondition = or(\n\t\t\t\tsql`LOWER(${novels.name}) LIKE ${pattern} ESCAPE '\\\\'`,\n\t\t\t\tsql`LOWER(${novels.author}) LIKE ${pattern} ESCAPE '\\\\'`,\n\t\t\t);\n\t\t\tif (keywordCondition) {\n\t\t\t\tconditions.push(keywordCondition);\n\t\t\t}\n\t\t}\n\n\t\tconst normalizedGenres = normalizeStringList(options.genres);\n\t\tif (normalizedGenres.length > 0) {\n\t\t\tconst matchingNovelIdsSubquery = this.db\n\t\t\t\t.select({ novelId: novelGenres.novelId })\n\t\t\t\t.from(novelGenres)\n\t\t\t\t.innerJoin(genres, eq(novelGenres.genreId, genres.id))\n\t\t\t\t.where(inArray(genres.name, normalizedGenres))\n\t\t\t\t.groupBy(novelGenres.novelId)\n\t\t\t\t.having(\n\t\t\t\t\tsql`COUNT(DISTINCT ${genres.name}) = ${normalizedGenres.length}`,\n\t\t\t\t);\n\t\t\tconditions.push(inArray(novels.id, matchingNovelIdsSubquery));\n\t\t}\n\n\t\tconst whereClause = and(...conditions);\n\n\t\tconst totalResult = await this.db\n\t\t\t.select({ value: count() })\n\t\t\t.from(novels)\n\t\t\t.where(whereClause)\n\t\t\t.get();\n\t\tconst total = totalResult?.value ?? 0;\n\n\t\tif (total === 0) {\n\t\t\treturn {\n\t\t\t\titems: [],\n\t\t\t\ttotal: 0,\n\t\t\t\tpage,\n\t\t\t\tpageSize,\n\t\t\t};\n\t\t}\n\n\t\tconst novelRows = await this.db\n\t\t\t.select({\n\t\t\t\tid: novels.id,\n\t\t\t\tplatform: novels.platform,\n\t\t\t\tplatformId: novels.platformId,\n\t\t\t\tname: novels.name,\n\t\t\t\tcoverUrl: novels.coverUrl,\n\t\t\t\tauthor: novels.author,\n\t\t\t\tsummary: novels.summary,\n\t\t\t\tstatus: novels.status,\n\t\t\t})\n\t\t\t.from(novels)\n\t\t\t.where(whereClause)\n\t\t\t.orderBy(desc(novels.updateAt), desc(novels.id))\n\t\t\t.limit(pageSize)\n\t\t\t.offset(offset)\n\t\t\t.all();\n\n\t\tif (novelRows.length === 0) {\n\t\t\treturn {\n\t\t\t\titems: [],\n\t\t\t\ttotal,\n\t\t\t\tpage,\n\t\t\t\tpageSize,\n\t\t\t};\n\t\t}\n\n\t\tconst novelIds = novelRows.map((row) => row.id);\n\t\tconst genreRows = await this.db\n\t\t\t.select({\n\t\t\t\tnovelId: novelGenres.novelId,\n\t\t\t\tgenreName: genres.name,\n\t\t\t})\n\t\t\t.from(novelGenres)\n\t\t\t.innerJoin(genres, eq(novelGenres.genreId, genres.id))\n\t\t\t.where(inArray(novelGenres.novelId, novelIds))\n\t\t\t.all();\n\n\t\tconst genresByNovelId = new Map<number, string[]>();\n\t\tfor (const row of genreRows) {\n\t\t\tconst existing = genresByNovelId.get(row.novelId);\n\t\t\tif (existing) {\n\t\t\t\texisting.push(row.genreName);\n\t\t\t} else {\n\t\t\t\tgenresByNovelId.set(row.novelId, [row.genreName]);\n\t\t\t}\n\t\t}\n\n\t\tconst items: NovelInfo[] = novelRows.map((row) => ({\n\t\t\tid: row.platformId,\n\t\t\tplatform: row.platform,\n\t\t\ttitle: row.name,\n\t\t\tcoverUrl: row.coverUrl,\n\t\t\tauthor: row.author,\n\t\t\tsummary: row.summary,\n\t\t\tstatus: row.status,\n\t\t\tgenres: genresByNovelId.get(row.id) ?? [],\n\t\t}));\n\n\t\treturn {\n\t\t\titems,\n\t\t\ttotal,\n\t\t\tpage,\n\t\t\tpageSize,\n\t\t};\n\t}\n\n\tasync listCachedGenres(platform: string): Promise<CachedGenreItem[]> {\n\t\tawait this.ensureReady();\n\t\tconst countExpr = sql<number>`COUNT(DISTINCT ${novels.id})`;\n\t\tconst rows = await this.db\n\t\t\t.select({\n\t\t\t\tname: genres.name,\n\t\t\t\tcount: countExpr,\n\t\t\t})\n\t\t\t.from(novelGenres)\n\t\t\t.innerJoin(genres, eq(novelGenres.genreId, genres.id))\n\t\t\t.innerJoin(novels, eq(novelGenres.novelId, novels.id))\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(novels.platform, platform),\n\t\t\t\t\tne(novels.status, \"unknown\"),\n\t\t\t\t\tne(novels.author, \"\"),\n\t\t\t\t\tne(novels.name, \"\"),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.groupBy(genres.id, genres.name)\n\t\t\t.orderBy(desc(countExpr), asc(genres.name))\n\t\t\t.all();\n\n\t\treturn rows.map((row) => ({\n\t\t\tname: row.name,\n\t\t\tcount: Number(row.count),\n\t\t}));\n\t}\n\n\tprivate async getMaxSyncCursor(\n\t\texecutor: Pick<DrizzleInstance, \"select\">,\n\t): Promise<number> {\n\t\tconst bookshelfMaxRow = await executor\n\t\t\t.select({ value: max(bookshelfItems.serverUpdatedAt) })\n\t\t\t.from(bookshelfItems)\n\t\t\t.get();\n\t\tconst progressMaxRow = await executor\n\t\t\t.select({ value: max(readingProgress.serverUpdatedAt) })\n\t\t\t.from(readingProgress)\n\t\t\t.get();\n\t\tconst categoryMaxRow = await executor\n\t\t\t.select({ value: max(bookshelfCategories.serverUpdatedAt) })\n\t\t\t.from(bookshelfCategories)\n\t\t\t.get();\n\t\tconst bookshelfMax = Number(bookshelfMaxRow?.value ?? 0);\n\t\tconst progressMax = Number(progressMaxRow?.value ?? 0);\n\t\tconst categoryMax = Number(categoryMaxRow?.value ?? 0);\n\t\treturn Math.max(bookshelfMax, progressMax, categoryMax);\n\t}\n\n\tprivate async enrichBookshelfItemsWithNovelMetadata(\n\t\texecutor: Pick<DrizzleInstance, \"select\">,\n\t\titems: BookshelfItem[],\n\t): Promise<BookshelfItem[]> {\n\t\tif (items.length === 0) {\n\t\t\treturn items;\n\t\t}\n\n\t\tconst idsByPlatform = new Map<string, Set<string>>();\n\t\tfor (const item of items) {\n\t\t\tlet idSet = idsByPlatform.get(item.platform);\n\t\t\tif (!idSet) {\n\t\t\t\tidSet = new Set<string>();\n\t\t\t\tidsByPlatform.set(item.platform, idSet);\n\t\t\t}\n\t\t\tidSet.add(item.novelId);\n\t\t}\n\n\t\tconst matchedNovels: {\n\t\t\tid: number;\n\t\t\tplatform: string;\n\t\t\tplatformId: string;\n\t\t\tstatus: NovelStatus;\n\t\t}[] = [];\n\n\t\tconst chunkSize = 500;\n\t\tfor (const [platform, idSet] of idsByPlatform) {\n\t\t\tconst allIds = Array.from(idSet);\n\t\t\tfor (let i = 0; i < allIds.length; i += chunkSize) {\n\t\t\t\tconst chunk = allIds.slice(i, i + chunkSize);\n\t\t\t\tconst rows = await executor\n\t\t\t\t\t.select({\n\t\t\t\t\t\tid: novels.id,\n\t\t\t\t\t\tplatform: novels.platform,\n\t\t\t\t\t\tplatformId: novels.platformId,\n\t\t\t\t\t\tstatus: novels.status,\n\t\t\t\t\t})\n\t\t\t\t\t.from(novels)\n\t\t\t\t\t.where(\n\t\t\t\t\t\tand(\n\t\t\t\t\t\t\teq(novels.platform, platform),\n\t\t\t\t\t\t\tinArray(novels.platformId, chunk),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\t.all();\n\t\t\t\tmatchedNovels.push(...rows);\n\t\t\t}\n\t\t}\n\n\t\tconst genresByNovelDbId = new Map<number, string[]>();\n\t\tif (matchedNovels.length > 0) {\n\t\t\tconst dbIds = matchedNovels.map((row) => row.id);\n\t\t\tfor (let i = 0; i < dbIds.length; i += chunkSize) {\n\t\t\t\tconst chunk = dbIds.slice(i, i + chunkSize);\n\t\t\t\tconst genreRows = await executor\n\t\t\t\t\t.select({\n\t\t\t\t\t\tnovelId: novelGenres.novelId,\n\t\t\t\t\t\tgenreName: genres.name,\n\t\t\t\t\t})\n\t\t\t\t\t.from(novelGenres)\n\t\t\t\t\t.innerJoin(genres, eq(novelGenres.genreId, genres.id))\n\t\t\t\t\t.where(inArray(novelGenres.novelId, chunk))\n\t\t\t\t\t.all();\n\t\t\t\tfor (const row of genreRows) {\n\t\t\t\t\tconst list = genresByNovelDbId.get(row.novelId);\n\t\t\t\t\tif (list) {\n\t\t\t\t\t\tlist.push(row.genreName);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tgenresByNovelDbId.set(row.novelId, [row.genreName]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst metaByKey = new Map<\n\t\t\tstring,\n\t\t\t{ status: NovelStatus; genres: string[] }\n\t\t>();\n\t\tfor (const novelRow of matchedNovels) {\n\t\t\tconst key = `${novelRow.platform}\\0${novelRow.platformId}`;\n\t\t\tmetaByKey.set(key, {\n\t\t\t\tstatus: novelRow.status,\n\t\t\t\tgenres: normalizeStringList(genresByNovelDbId.get(novelRow.id)),\n\t\t\t});\n\t\t}\n\n\t\treturn items.map((item) => {\n\t\t\tconst key = `${item.platform}\\0${item.novelId}`;\n\t\t\tconst novelMeta = metaByKey.get(key);\n\t\t\tconst fallbackGenres = normalizeStringList(item.genres);\n\t\t\tconst fallbackStatus: NovelStatus = item.status ?? \"unknown\";\n\t\t\tconst resolvedGenres =\n\t\t\t\tnovelMeta && novelMeta.genres.length > 0\n\t\t\t\t\t? novelMeta.genres\n\t\t\t\t\t: fallbackGenres;\n\t\t\tconst resolvedStatus: NovelStatus =\n\t\t\t\tnovelMeta && novelMeta.status !== \"unknown\"\n\t\t\t\t\t? novelMeta.status\n\t\t\t\t\t: fallbackStatus;\n\n\t\t\treturn {\n\t\t\t\t...item,\n\t\t\t\tcategoryIds: normalizeStringList(item.categoryIds),\n\t\t\t\tgenres: resolvedGenres,\n\t\t\t\tstatus: resolvedStatus,\n\t\t\t};\n\t\t});\n\t}\n\n\tasync getSyncState(since?: number): Promise<SyncStateResult> {\n\t\tawait this.ensureReady();\n\t\treturn await this.db.transaction(async (tx) => {\n\t\t\tconst maxCursor = await this.getMaxSyncCursor(tx);\n\n\t\t\tif (since === undefined || since <= 0) {\n\t\t\t\tconst bookshelfRows = await tx\n\t\t\t\t\t.select()\n\t\t\t\t\t.from(bookshelfItems)\n\t\t\t\t\t.where(isNull(bookshelfItems.deletedAt))\n\t\t\t\t\t.all();\n\t\t\t\tconst progressRows = await tx.select().from(readingProgress).all();\n\t\t\t\tconst categoryRows = await tx\n\t\t\t\t\t.select()\n\t\t\t\t\t.from(bookshelfCategories)\n\t\t\t\t\t.where(isNull(bookshelfCategories.deletedAt))\n\t\t\t\t\t.orderBy(\n\t\t\t\t\t\tasc(bookshelfCategories.sortOrder),\n\t\t\t\t\t\tasc(bookshelfCategories.createdAt),\n\t\t\t\t\t\tasc(bookshelfCategories.id),\n\t\t\t\t\t)\n\t\t\t\t\t.all();\n\n\t\t\t\tconst enrichedBookshelf =\n\t\t\t\t\tawait this.enrichBookshelfItemsWithNovelMetadata(\n\t\t\t\t\t\ttx,\n\t\t\t\t\t\tbookshelfRows.map(toBookshelfItem),\n\t\t\t\t\t);\n\n\t\t\t\treturn {\n\t\t\t\t\tbookshelf: enrichedBookshelf,\n\t\t\t\t\tprogress: progressRows.map(toReadingProgress),\n\t\t\t\t\tcategories: categoryRows.map(toBookshelfCategory),\n\t\t\t\t\tcursor: maxCursor,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst bookshelfRows = await tx\n\t\t\t\t.select()\n\t\t\t\t.from(bookshelfItems)\n\t\t\t\t.where(gt(bookshelfItems.serverUpdatedAt, since))\n\t\t\t\t.all();\n\t\t\tconst progressRows = await tx\n\t\t\t\t.select()\n\t\t\t\t.from(readingProgress)\n\t\t\t\t.where(gt(readingProgress.serverUpdatedAt, since))\n\t\t\t\t.all();\n\t\t\tconst categoryRows = await tx\n\t\t\t\t.select()\n\t\t\t\t.from(bookshelfCategories)\n\t\t\t\t.where(gt(bookshelfCategories.serverUpdatedAt, since))\n\t\t\t\t.orderBy(\n\t\t\t\t\tasc(bookshelfCategories.sortOrder),\n\t\t\t\t\tasc(bookshelfCategories.createdAt),\n\t\t\t\t\tasc(bookshelfCategories.id),\n\t\t\t\t)\n\t\t\t\t.all();\n\n\t\t\tconst enrichedBookshelf =\n\t\t\t\tawait this.enrichBookshelfItemsWithNovelMetadata(\n\t\t\t\t\ttx,\n\t\t\t\t\tbookshelfRows.map(toBookshelfItem),\n\t\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tbookshelf: enrichedBookshelf,\n\t\t\t\tprogress: progressRows.map(toReadingProgress),\n\t\t\t\tcategories: categoryRows.map(toBookshelfCategory),\n\t\t\t\tcursor: Math.max(since, maxCursor),\n\t\t\t};\n\t\t});\n\t}\n\n\tasync mergeSyncState(\n\t\tinput: MergeSyncStateInput,\n\t): Promise<MergeSyncStateResult> {\n\t\tawait this.ensureReady();\n\t\treturn await this.db.transaction(async (tx) => {\n\t\t\tlet lastCursor = await this.getMaxSyncCursor(tx);\n\t\t\tconst nextCursor = () => {\n\t\t\t\tlastCursor = Math.max(Date.now(), lastCursor + 1);\n\t\t\t\treturn lastCursor;\n\t\t\t};\n\n\t\t\tconst categoryMap = new Map<string, BookshelfCategory>();\n\t\t\tconst bookshelfMap = new Map<string, BookshelfItem>();\n\t\t\tconst progressMap = new Map<string, ReadingProgress>();\n\n\t\t\tfor (const cat of input.categories ?? []) {\n\t\t\t\tconst maxAllowedTime = Date.now() + CLOCK_SKEW_TOLERANCE_MS;\n\t\t\t\tconst effectiveUpdatedAt = Math.min(cat.updatedAt, maxAllowedTime);\n\t\t\t\tconst effectiveCreatedAt = Math.min(cat.createdAt, maxAllowedTime);\n\t\t\t\tconst trimmedName = cat.name.trim();\n\t\t\t\tconst normalizedSortOrder = Math.trunc(cat.sortOrder);\n\n\t\t\t\tconst existing = await tx\n\t\t\t\t\t.select()\n\t\t\t\t\t.from(bookshelfCategories)\n\t\t\t\t\t.where(eq(bookshelfCategories.id, cat.id))\n\t\t\t\t\t.get();\n\n\t\t\t\tif (!existing) {\n\t\t\t\t\tconst serverUpdatedAt = nextCursor();\n\t\t\t\t\tconst inserted = await tx\n\t\t\t\t\t\t.insert(bookshelfCategories)\n\t\t\t\t\t\t.values({\n\t\t\t\t\t\t\tid: cat.id,\n\t\t\t\t\t\t\tname: trimmedName,\n\t\t\t\t\t\t\tsortOrder: normalizedSortOrder,\n\t\t\t\t\t\t\tcreatedAt: effectiveCreatedAt,\n\t\t\t\t\t\t\tupdatedAt: effectiveUpdatedAt,\n\t\t\t\t\t\t\tserverUpdatedAt,\n\t\t\t\t\t\t\tdeletedAt: cat.deletedAt,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.returning()\n\t\t\t\t\t\t.get();\n\t\t\t\t\tcategoryMap.set(cat.id, toBookshelfCategory(inserted));\n\t\t\t\t} else if (effectiveUpdatedAt >= existing.updatedAt) {\n\t\t\t\t\tconst serverUpdatedAt = nextCursor();\n\t\t\t\t\tconst updated = await tx\n\t\t\t\t\t\t.update(bookshelfCategories)\n\t\t\t\t\t\t.set({\n\t\t\t\t\t\t\tname: trimmedName,\n\t\t\t\t\t\t\tsortOrder: normalizedSortOrder,\n\t\t\t\t\t\t\tupdatedAt: effectiveUpdatedAt,\n\t\t\t\t\t\t\tserverUpdatedAt,\n\t\t\t\t\t\t\tdeletedAt: cat.deletedAt,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.where(eq(bookshelfCategories.id, existing.id))\n\t\t\t\t\t\t.returning()\n\t\t\t\t\t\t.get();\n\t\t\t\t\tif (!updated) {\n\t\t\t\t\t\tthrow new Error(`Failed to update bookshelf category: ${cat.id}`);\n\t\t\t\t\t}\n\t\t\t\t\tcategoryMap.set(cat.id, toBookshelfCategory(updated));\n\t\t\t\t} else {\n\t\t\t\t\tcategoryMap.set(cat.id, toBookshelfCategory(existing));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const item of input.bookshelf ?? []) {\n\t\t\t\tconst key = `${item.platform}\\0${item.novelId}`;\n\t\t\t\tconst effectiveUpdatedAt = Math.min(\n\t\t\t\t\titem.updatedAt,\n\t\t\t\t\tDate.now() + CLOCK_SKEW_TOLERANCE_MS,\n\t\t\t\t);\n\t\t\t\tconst existing = await tx\n\t\t\t\t\t.select()\n\t\t\t\t\t.from(bookshelfItems)\n\t\t\t\t\t.where(\n\t\t\t\t\t\tand(\n\t\t\t\t\t\t\teq(bookshelfItems.platform, item.platform),\n\t\t\t\t\t\t\teq(bookshelfItems.novelId, item.novelId),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\t.get();\n\n\t\t\t\tif (!existing) {\n\t\t\t\t\tconst serverUpdatedAt = nextCursor();\n\t\t\t\t\tconst inserted = await tx\n\t\t\t\t\t\t.insert(bookshelfItems)\n\t\t\t\t\t\t.values({\n\t\t\t\t\t\t\tplatform: item.platform,\n\t\t\t\t\t\t\tnovelId: item.novelId,\n\t\t\t\t\t\t\ttitle: item.title,\n\t\t\t\t\t\t\tauthor: item.author,\n\t\t\t\t\t\t\tcoverUrl: item.coverUrl,\n\t\t\t\t\t\t\taddedAt: item.addedAt,\n\t\t\t\t\t\t\tupdatedAt: effectiveUpdatedAt,\n\t\t\t\t\t\t\tserverUpdatedAt,\n\t\t\t\t\t\t\tdeletedAt: item.deletedAt,\n\t\t\t\t\t\t\tcategoryIds: JSON.stringify(\n\t\t\t\t\t\t\t\tnormalizeStringList(item.categoryIds),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tgenresJson: JSON.stringify(normalizeStringList(item.genres)),\n\t\t\t\t\t\t\tstatus: item.status ?? \"unknown\",\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.returning()\n\t\t\t\t\t\t.get();\n\t\t\t\t\tbookshelfMap.set(key, toBookshelfItem(inserted));\n\t\t\t\t} else if (effectiveUpdatedAt >= existing.updatedAt) {\n\t\t\t\t\tconst serverUpdatedAt = nextCursor();\n\t\t\t\t\tconst nextCategoryIds =\n\t\t\t\t\t\titem.categoryIds !== undefined\n\t\t\t\t\t\t\t? JSON.stringify(normalizeStringList(item.categoryIds))\n\t\t\t\t\t\t\t: existing.categoryIds;\n\t\t\t\t\tconst nextGenresJson =\n\t\t\t\t\t\titem.genres !== undefined\n\t\t\t\t\t\t\t? JSON.stringify(normalizeStringList(item.genres))\n\t\t\t\t\t\t\t: existing.genresJson;\n\t\t\t\t\tconst nextStatus =\n\t\t\t\t\t\titem.status !== undefined ? item.status : existing.status;\n\n\t\t\t\t\tconst updated = await tx\n\t\t\t\t\t\t.update(bookshelfItems)\n\t\t\t\t\t\t.set({\n\t\t\t\t\t\t\ttitle: item.title,\n\t\t\t\t\t\t\tauthor: item.author,\n\t\t\t\t\t\t\tcoverUrl: item.coverUrl,\n\t\t\t\t\t\t\taddedAt: item.addedAt,\n\t\t\t\t\t\t\tupdatedAt: effectiveUpdatedAt,\n\t\t\t\t\t\t\tserverUpdatedAt,\n\t\t\t\t\t\t\tdeletedAt: item.deletedAt,\n\t\t\t\t\t\t\tcategoryIds: nextCategoryIds,\n\t\t\t\t\t\t\tgenresJson: nextGenresJson,\n\t\t\t\t\t\t\tstatus: nextStatus,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.where(eq(bookshelfItems.id, existing.id))\n\t\t\t\t\t\t.returning()\n\t\t\t\t\t\t.get();\n\t\t\t\t\tif (!updated) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Failed to update bookshelf item: ${item.platform}/${item.novelId}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbookshelfMap.set(key, toBookshelfItem(updated));\n\t\t\t\t} else {\n\t\t\t\t\tbookshelfMap.set(key, toBookshelfItem(existing));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const item of input.progress ?? []) {\n\t\t\t\tconst key = `${item.platform}\\0${item.novelId}`;\n\t\t\t\tconst maxAllowedTime = Date.now() + CLOCK_SKEW_TOLERANCE_MS;\n\t\t\t\tconst effectiveUpdatedAt = Math.min(item.updatedAt, maxAllowedTime);\n\t\t\t\tconst incomingHiddenAt =\n\t\t\t\t\ttypeof item.historyHiddenAt === \"number\"\n\t\t\t\t\t\t? Math.min(item.historyHiddenAt, maxAllowedTime)\n\t\t\t\t\t\t: null;\n\n\t\t\t\tconst existing = await tx\n\t\t\t\t\t.select()\n\t\t\t\t\t.from(readingProgress)\n\t\t\t\t\t.where(\n\t\t\t\t\t\tand(\n\t\t\t\t\t\t\teq(readingProgress.platform, item.platform),\n\t\t\t\t\t\t\teq(readingProgress.novelId, item.novelId),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\t.get();\n\n\t\t\t\tif (!existing) {\n\t\t\t\t\tconst serverUpdatedAt = nextCursor();\n\t\t\t\t\tconst inserted = await tx\n\t\t\t\t\t\t.insert(readingProgress)\n\t\t\t\t\t\t.values({\n\t\t\t\t\t\t\tplatform: item.platform,\n\t\t\t\t\t\t\tnovelId: item.novelId,\n\t\t\t\t\t\t\tnovelTitle: item.novelTitle,\n\t\t\t\t\t\t\tcoverUrl: item.coverUrl,\n\t\t\t\t\t\t\tvolumeId: item.volumeId,\n\t\t\t\t\t\t\tvolumeTitle: item.volumeTitle,\n\t\t\t\t\t\t\tchapterId: item.chapterId,\n\t\t\t\t\t\t\tchapterTitle: item.chapterTitle,\n\t\t\t\t\t\t\tparagraphIndex: item.paragraphIndex,\n\t\t\t\t\t\t\ttotalParagraphs: item.totalParagraphs,\n\t\t\t\t\t\t\tdeviceLabel: item.deviceLabel,\n\t\t\t\t\t\t\tupdatedAt: effectiveUpdatedAt,\n\t\t\t\t\t\t\tserverUpdatedAt,\n\t\t\t\t\t\t\thistoryHiddenAt: incomingHiddenAt,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.returning()\n\t\t\t\t\t\t.get();\n\t\t\t\t\tprogressMap.set(key, toReadingProgress(inserted));\n\t\t\t\t} else {\n\t\t\t\t\tconst existingHiddenAt = existing.historyHiddenAt ?? null;\n\t\t\t\t\tconst mergedHiddenAt =\n\t\t\t\t\t\tincomingHiddenAt === null\n\t\t\t\t\t\t\t? existingHiddenAt\n\t\t\t\t\t\t\t: existingHiddenAt === null\n\t\t\t\t\t\t\t\t? incomingHiddenAt\n\t\t\t\t\t\t\t\t: Math.max(existingHiddenAt, incomingHiddenAt);\n\t\t\t\t\tconst progressWins = effectiveUpdatedAt >= existing.updatedAt;\n\t\t\t\t\tconst hiddenChanged = mergedHiddenAt !== existingHiddenAt;\n\n\t\t\t\t\tif (progressWins || hiddenChanged) {\n\t\t\t\t\t\tconst serverUpdatedAt = nextCursor();\n\t\t\t\t\t\tconst updated = await tx\n\t\t\t\t\t\t\t.update(readingProgress)\n\t\t\t\t\t\t\t.set(\n\t\t\t\t\t\t\t\tprogressWins\n\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\tnovelTitle: item.novelTitle,\n\t\t\t\t\t\t\t\t\t\t\tcoverUrl: item.coverUrl,\n\t\t\t\t\t\t\t\t\t\t\tvolumeId: item.volumeId,\n\t\t\t\t\t\t\t\t\t\t\tvolumeTitle: item.volumeTitle,\n\t\t\t\t\t\t\t\t\t\t\tchapterId: item.chapterId,\n\t\t\t\t\t\t\t\t\t\t\tchapterTitle: item.chapterTitle,\n\t\t\t\t\t\t\t\t\t\t\tparagraphIndex: item.paragraphIndex,\n\t\t\t\t\t\t\t\t\t\t\ttotalParagraphs: item.totalParagraphs,\n\t\t\t\t\t\t\t\t\t\t\tdeviceLabel: item.deviceLabel,\n\t\t\t\t\t\t\t\t\t\t\tupdatedAt: effectiveUpdatedAt,\n\t\t\t\t\t\t\t\t\t\t\tserverUpdatedAt,\n\t\t\t\t\t\t\t\t\t\t\thistoryHiddenAt: mergedHiddenAt,\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\t\t\tserverUpdatedAt,\n\t\t\t\t\t\t\t\t\t\t\thistoryHiddenAt: mergedHiddenAt,\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.where(eq(readingProgress.id, existing.id))\n\t\t\t\t\t\t\t.returning()\n\t\t\t\t\t\t\t.get();\n\t\t\t\t\t\tif (!updated) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Failed to update reading progress: ${item.platform}/${item.novelId}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tprogressMap.set(key, toReadingProgress(updated));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tprogressMap.set(key, toReadingProgress(existing));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst enrichedBookshelf =\n\t\t\t\tawait this.enrichBookshelfItemsWithNovelMetadata(\n\t\t\t\t\ttx,\n\t\t\t\t\tArray.from(bookshelfMap.values()),\n\t\t\t\t);\n\n\t\t\tconst serverTime = Math.max(Date.now(), lastCursor);\n\t\t\treturn {\n\t\t\t\tbookshelf: enrichedBookshelf,\n\t\t\t\tprogress: Array.from(progressMap.values()),\n\t\t\t\tcategories: Array.from(categoryMap.values()),\n\t\t\t\tserverTime,\n\t\t\t};\n\t\t});\n\t}\n\n\tasync close(logger?: (message: string) => void) {\n\t\ttry {\n\t\t\tawait this.ensureReady().catch(() => {});\n\t\t\tawait this.client.execute(\"PRAGMA journal_mode = DELETE;\");\n\t\t\tlogger?.(\"WAL写入盘完成,正在关闭数据库连接...\");\n\t\t} catch (error) {\n\t\t\tlogger?.(`执行WAL检查点时发生错误: ${error}`);\n\t\t} finally {\n\t\t\tthis.client.close();\n\t\t\tlogger?.(\"数据库连接已关闭\");\n\t\t}\n\t}\n}\n","import { existsSync } from \"node:fs\";\nimport { mkdir, readFile, rm, stat, writeFile } from \"node:fs/promises\";\nimport type { BinaryResponse } from \"@acanthis-dec/browser-fetch\";\nimport type { DatabaseService } from \"./db\";\nimport type { NovelCoverMetadata, VolumeCoverMetadata } from \"./type\";\nimport {\n\tgetContentHash,\n\tgetCoverHash,\n\tgetExtFromContentType,\n\tzstdCompress,\n\tzstdDecompress,\n} from \"./utils\";\n\nexport class FSStorageService {\n\tprivate basePath: string;\n\tprivate dbService: DatabaseService;\n\n\tconstructor(basePath: string, dbService: DatabaseService) {\n\t\tthis.basePath = basePath;\n\t\tthis.dbService = dbService;\n\t}\n\n\tprivate async _initPath(path: string): Promise<void> {\n\t\tif (!existsSync(path)) {\n\t\t\tawait mkdir(path, { recursive: true });\n\t\t} else if (existsSync(path) && !(await stat(path)).isDirectory()) {\n\t\t\tawait rm(path);\n\t\t\tawait mkdir(path, { recursive: true });\n\t\t}\n\t}\n\n\tasync getNovelContent(hash: string): Promise<string | undefined> {\n\t\tconst novelCacheDir = `${this.basePath}/novels/${hash.slice(0, 2)}`;\n\t\tconst chapterFilePath = `${novelCacheDir}/${hash}.zst`;\n\t\tif (!existsSync(chapterFilePath)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst compressedData = await readFile(chapterFilePath);\n\t\tconst decompressedData = await zstdDecompress(compressedData);\n\t\treturn new TextDecoder().decode(decompressedData);\n\t}\n\n\tasync setNovelContent(content: string): Promise<string> {\n\t\tconst hash = getContentHash(content);\n\t\tconst novelCacheDir = `${this.basePath}/novels/${hash.slice(0, 2)}`;\n\t\tawait this._initPath(novelCacheDir);\n\t\tconst chapterFilePath = `${novelCacheDir}/${hash}.zst`;\n\t\tconst compressedData = await zstdCompress(Buffer.from(content, \"utf-8\"));\n\t\tawait writeFile(chapterFilePath, compressedData);\n\t\treturn hash;\n\t}\n\n\tasync getCoverData(\n\t\ttype: \"novel\" | \"volume\",\n\t\tplatform: string,\n\t\tplatformId: string,\n\t): Promise<BinaryResponse | undefined> {\n\t\tlet meta: NovelCoverMetadata | VolumeCoverMetadata | undefined;\n\t\tif (type === \"novel\") {\n\t\t\tmeta = await this.dbService.getNovelCoverMetadata(platform, platformId);\n\t\t} else if (type === \"volume\") {\n\t\t\tmeta = await this.dbService.getVolumeCoverMetadata(platform, platformId);\n\t\t}\n\t\tif (!meta) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst coverPath = `${this.basePath}/covers/${meta.hash.slice(0, 2)}/${meta.hash}.${getExtFromContentType(meta.contentType)}`;\n\t\tif (!existsSync(coverPath)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst data = await readFile(coverPath);\n\t\treturn { data, mimeType: meta.contentType };\n\t}\n\n\tasync setCoverData(\n\t\ttype: \"novel\" | \"volume\",\n\t\turl: string,\n\t\tplatform: string,\n\t\tplatformId: string,\n\t\tdata: Buffer,\n\t\tcontentType: string,\n\t): Promise<void> {\n\t\tconst coverHash = getCoverHash(data);\n\t\tconst ext = getExtFromContentType(contentType);\n\t\tconst coverDir = `${this.basePath}/covers/${coverHash.slice(0, 2)}`;\n\t\tawait this._initPath(coverDir);\n\t\tconst coverPath = `${coverDir}/${coverHash}.${ext}`;\n\t\tawait writeFile(coverPath, data);\n\t\tif (type === \"novel\") {\n\t\t\tawait this.dbService.addNovelCoverMetadata({\n\t\t\t\tplatform,\n\t\t\t\tnovelId: platformId,\n\t\t\t\thash: coverHash,\n\t\t\t\tcontentType,\n\t\t\t\toriginalUrl: url,\n\t\t\t});\n\t\t} else if (type === \"volume\") {\n\t\t\tawait this.dbService.addVolumeCoverMetadata({\n\t\t\t\tplatform,\n\t\t\t\tvolumeId: platformId,\n\t\t\t\thash: coverHash,\n\t\t\t\tcontentType,\n\t\t\t\toriginalUrl: url,\n\t\t\t});\n\t\t}\n\t}\n\n\tasync getIllustrationData(\n\t\tplatform: string,\n\t\turlHash: string,\n\t): Promise<BinaryResponse | undefined> {\n\t\tconst meta = await this.dbService.getIllustrationMetadata(\n\t\t\tplatform,\n\t\t\turlHash,\n\t\t);\n\t\tif (!meta?.fileHash || !meta?.contentType) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst ext = getExtFromContentType(meta.contentType);\n\t\tconst illustrationPath = `${this.basePath}/illustrations/${meta.fileHash.slice(0, 2)}/${meta.fileHash}.${ext}`;\n\t\tif (!existsSync(illustrationPath)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst data = await readFile(illustrationPath);\n\t\treturn { data, mimeType: meta.contentType };\n\t}\n\n\tasync setIllustrationData(\n\t\tplatform: string,\n\t\turlHash: string,\n\t\tdata: Buffer,\n\t\tcontentType: string,\n\t): Promise<void> {\n\t\tconst fileHash = getCoverHash(data);\n\t\tconst ext = getExtFromContentType(contentType);\n\t\tconst illustrationDir = `${this.basePath}/illustrations/${fileHash.slice(0, 2)}`;\n\t\tawait this._initPath(illustrationDir);\n\t\tconst illustrationPath = `${illustrationDir}/${fileHash}.${ext}`;\n\t\tawait writeFile(illustrationPath, data);\n\t\tawait this.dbService.updateIllustrationFileInfo(\n\t\t\tplatform,\n\t\t\turlHash,\n\t\t\tfileHash,\n\t\t\tcontentType,\n\t\t);\n\t}\n}\n","import type { BinaryResponse } from \"@acanthis-dec/browser-fetch\";\nimport type {\n\tCachedGenreItem,\n\tChapter,\n\tNovel,\n\tNovelSearchResult,\n} from \"@acanthis-dec/core\";\nimport type z from \"zod\";\nimport { DatabaseCookieStore } from \"./cookies\";\nimport { type DatabaseOptions, DatabaseService } from \"./db\";\nimport { FSStorageService } from \"./files\";\nimport type {\n\tListNovelsOptions,\n\tMergeSyncStateInput,\n\tMergeSyncStateResult,\n\tPaginatedNovels,\n\tSyncStateResult,\n} from \"./type\";\n\nexport interface StorageServiceOptions {\n\tdataDir?: string;\n\tdb: DatabaseOptions;\n}\n\nexport class StorageService {\n\tprivate db: DatabaseService;\n\tprivate files: FSStorageService;\n\tprivate cookieStore: DatabaseCookieStore;\n\n\tconstructor(options: StorageServiceOptions) {\n\t\tthis.db = new DatabaseService(options.db);\n\t\tthis.files = new FSStorageService(options.dataDir ?? \"\", this.db);\n\t\tthis.cookieStore = new DatabaseCookieStore(this.db);\n\t}\n\n\tasync getNovelContent(hash: string): Promise<string | undefined> {\n\t\treturn await this.files.getNovelContent(hash);\n\t}\n\n\tasync setNovelContent(content: string): Promise<string> {\n\t\treturn await this.files.setNovelContent(content);\n\t}\n\n\tasync getCoverData(\n\t\ttype: \"novel\" | \"volume\",\n\t\tplatform: string,\n\t\tplatformId: string,\n\t): Promise<BinaryResponse | undefined> {\n\t\treturn await this.files.getCoverData(type, platform, platformId);\n\t}\n\n\tasync setCoverData(\n\t\ttype: \"novel\" | \"volume\",\n\t\turl: string,\n\t\tdata: Buffer,\n\t\tcontentType: string,\n\t\tplatform: string,\n\t\tplatformId: string,\n\t): Promise<void> {\n\t\tawait this.files.setCoverData(\n\t\t\ttype,\n\t\t\turl,\n\t\t\tplatform,\n\t\t\tplatformId,\n\t\t\tdata,\n\t\t\tcontentType,\n\t\t);\n\t}\n\n\tasync addSearchResult(\n\t\tkeyword: string,\n\t\tplatform: string,\n\t\tresults: NovelSearchResult[],\n\t): Promise<void> {\n\t\tawait this.db.addSearchResult(keyword, platform, results);\n\t}\n\n\tasync searchNovels(\n\t\tkeyword: string,\n\t\tplatform: string,\n\t): Promise<NovelSearchResult[] | undefined> {\n\t\tconst data = await this.db.searchNovels(keyword, platform);\n\t\treturn data ? data.data : undefined;\n\t}\n\n\tasync getNovelCache(platform: string, platformId: string) {\n\t\tconst data = await this.db.getNovelCache(platform, platformId);\n\t\treturn data ? data.data : undefined;\n\t}\n\n\tasync addNovelCache(novel: Novel) {\n\t\tawait this.db.addNovelCache(novel);\n\t}\n\n\tasync getVolumeMeta(platform: string, platformId: string) {\n\t\treturn await this.db.getVolumeMeta(platform, platformId);\n\t}\n\n\tasync getChapterFromTitle(\n\t\ttitle: string,\n\t): Promise<Partial<Chapter> | undefined> {\n\t\treturn await this.db.getChapterFromTitle(title);\n\t}\n\n\tasync getChapterFromId(\n\t\tplatform: string,\n\t\tplatformId: string,\n\t): Promise<Chapter | undefined> {\n\t\treturn await this.db.getChapterFromId(platform, platformId);\n\t}\n\n\tasync addNovelContentHash(\n\t\tplatform: string,\n\t\tchapterId: string,\n\t\tcontentHash: string,\n\t) {\n\t\tawait this.db.addNovelContentHash(platform, chapterId, contentHash);\n\t}\n\n\tgetCookieStore() {\n\t\treturn this.cookieStore;\n\t}\n\n\tasync getCache<T>(key: string, schema: z.ZodType<T>): Promise<T | null> {\n\t\treturn await this.db.getCache(key, schema);\n\t}\n\n\tasync setCache<T>(key: string, value: T): Promise<void> {\n\t\tawait this.db.setCache(key, value);\n\t}\n\n\tasync registerIllustrations(platform: string, urls: string[]): Promise<void> {\n\t\tawait this.db.registerIllustrations(platform, urls);\n\t}\n\n\tasync getIllustrationSourceUrl(\n\t\tplatform: string,\n\t\turlHash: string,\n\t): Promise<string | undefined> {\n\t\treturn await this.db.getIllustrationSourceUrl(platform, urlHash);\n\t}\n\n\tasync getIllustrationData(\n\t\tplatform: string,\n\t\turlHash: string,\n\t): Promise<BinaryResponse | undefined> {\n\t\treturn await this.files.getIllustrationData(platform, urlHash);\n\t}\n\n\tasync setIllustrationData(\n\t\tplatform: string,\n\t\turlHash: string,\n\t\tdata: Buffer,\n\t\tcontentType: string,\n\t): Promise<void> {\n\t\tawait this.files.setIllustrationData(platform, urlHash, data, contentType);\n\t}\n\n\tasync listCachedNovels(\n\t\tplatform: string,\n\t\toptions: ListNovelsOptions,\n\t): Promise<PaginatedNovels> {\n\t\treturn await this.db.listCachedNovels(platform, options);\n\t}\n\n\tasync listCachedGenres(platform: string): Promise<CachedGenreItem[]> {\n\t\treturn await this.db.listCachedGenres(platform);\n\t}\n\n\tasync getSyncState(since?: number): Promise<SyncStateResult> {\n\t\treturn await this.db.getSyncState(since);\n\t}\n\n\tasync mergeSyncState(\n\t\tinput: MergeSyncStateInput,\n\t): Promise<MergeSyncStateResult> {\n\t\treturn await this.db.mergeSyncState(input);\n\t}\n\n\tasync close(logger?: (message: string) => void) {\n\t\tawait this.db.close(logger);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAUA,MAAa,SAAS,YACrB,UACA;CACC,IAAI,QAAQ,IAAI,CAAC,CAAC,WAAW,EAAE,eAAe,KAAK,CAAC;CACpD,UAAU,KAAK,UAAU,CAAC,CAAC,QAAQ;CACnC,YAAY,KAAK,aAAa,CAAC,CAAC,QAAQ;CACxC,MAAM,KAAK,MAAM,CAAC,CAAC,QAAQ;CAC3B,QAAQ,KAAK,QAAQ,CAAC,CAAC,QAAQ;CAC/B,SAAS,KAAK,SAAS,CAAC,CAAC,QAAQ;CACjC,UAAU,KAAK,WAAW,CAAC,CAAC,QAAQ;CACpC,QAAQ,KAAK,UAAU,EACtB,MAAM;EAAC;EAAW;EAAa;CAAS,EACzC,CAAC,CAAC,CAAC,QAAQ;CACX,UAAU,QAAQ,WAAW,CAAC,CAAC,QAAQ;AACxC,IACC,UAAU,CACV,OAAO,sBAAsB,CAAC,CAAC,GAAG,MAAM,UAAU,MAAM,UAAU,CACnE,CACD;AAEA,MAAa,SAAS,YAAY,UAAU;CAC3C,IAAI,QAAQ,IAAI,CAAC,CAAC,WAAW,EAAE,eAAe,KAAK,CAAC;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G,SAAS,KAAK,MAAM;CAC1C;CAEA,MAAM,SAAY,KAAa,OAAyB;EACvD,MAAM,KAAK,GAAG,SAAS,KAAK,KAAK;CAClC;CAEA,MAAM,sBAAsB,UAAkB,MAA+B;EAC5E,MAAM,KAAK,GAAG,sBAAsB,UAAU,IAAI;CACnD;CAEA,MAAM,yBACL,UACA,SAC8B;EAC9B,OAAO,MAAM,KAAK,GAAG,yBAAyB,UAAU,OAAO;CAChE;CAEA,MAAM,oBACL,UACA,SACsC;EACtC,OAAO,MAAM,KAAK,MAAM,oBAAoB,UAAU,OAAO;CAC9D;CAEA,MAAM,oBACL,UACA,SACA,MACA,aACgB;EAChB,MAAM,KAAK,MAAM,oBAAoB,UAAU,SAAS,MAAM,WAAW;CAC1E;CAEA,MAAM,iBACL,UACA,SAC2B;EAC3B,OAAO,MAAM,KAAK,GAAG,iBAAiB,UAAU,OAAO;CACxD;CAEA,MAAM,iBAAiB,UAA8C;EACpE,OAAO,MAAM,KAAK,GAAG,iBAAiB,QAAQ;CAC/C;CAEA,MAAM,aAAa,OAA0C;EAC5D,OAAO,MAAM,KAAK,GAAG,aAAa,KAAK;CACxC;CAEA,MAAM,eACL,OACgC;EAChC,OAAO,MAAM,KAAK,GAAG,eAAe,KAAK;CAC1C;CAEA,MAAM,MAAM,QAAoC;EAC/C,MAAM,KAAK,GAAG,MAAM,MAAM;CAC3B;AACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acanthis-dec/storage",
3
- "version": "1.1.4",
3
+ "version": "1.2.0",
4
4
  "description": "The storage module of Athanthis project, providing abilities of local cache and persistent configs.",
5
5
  "author": "ConstasJ <constasj@qq.com>",
6
6
  "license": "MIT",
@@ -26,8 +26,8 @@
26
26
  "url": "https://github.com/ConstasJ/Acanthis/issues"
27
27
  },
28
28
  "dependencies": {
29
- "@acanthis-dec/browser-fetch": "1.1.5",
30
- "@acanthis-dec/core": "1.3.0",
29
+ "@acanthis-dec/browser-fetch": "1.1.6",
30
+ "@acanthis-dec/core": "1.4.0",
31
31
  "@libsql/client": "^0.18.0",
32
32
  "drizzle-orm": "rc",
33
33
  "zod": "^4.6.7"