@acanthis-dec/storage 1.0.6 → 1.0.8
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 +34 -35
- package/dist/index.mjs +24 -24
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -11
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { BinaryResponse, Cookie, CookieOptions, CookiesInit, CookiesStore, cookieStoreSign } from "@acanthis-dec/browser-fetch";
|
|
2
|
-
import { Client } from "@libsql/client";
|
|
3
2
|
import { Chapter, Novel, NovelSearchResult, Volume } from "@acanthis-dec/core";
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
//#region src/type.d.ts
|
|
3
|
+
import { Client } from "@libsql/client";
|
|
4
|
+
import z, { z as z$1 } from "zod";
|
|
7
5
|
interface DataWithUpdatedAt<T> {
|
|
8
6
|
data: T;
|
|
9
7
|
updatedAt: number;
|
|
@@ -22,8 +20,6 @@ interface VolumeCoverMetadata {
|
|
|
22
20
|
contentType: string;
|
|
23
21
|
originalUrl: string;
|
|
24
22
|
}
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/db.d.ts
|
|
27
23
|
type MigrationOptions = {
|
|
28
24
|
enabled?: boolean;
|
|
29
25
|
directory?: string;
|
|
@@ -32,7 +28,7 @@ type DatabaseOptions = {
|
|
|
32
28
|
path: string;
|
|
33
29
|
migrations?: MigrationOptions;
|
|
34
30
|
};
|
|
35
|
-
declare function getDrizzle(client: Client): import("drizzle-orm/libsql").LibSQLDatabase<
|
|
31
|
+
declare function getDrizzle(client: Client): import("drizzle-orm/libsql").LibSQLDatabase<import("drizzle-orm").ExtractTablesWithRelations<{
|
|
36
32
|
novels: {
|
|
37
33
|
genres: import("drizzle-orm").Many<"genres">;
|
|
38
34
|
volumes: import("drizzle-orm").Many<"volumes">;
|
|
@@ -180,7 +176,7 @@ declare function getDrizzle(client: Client): import("drizzle-orm/libsql").LibSQL
|
|
|
180
176
|
name: string;
|
|
181
177
|
tableName: "novels";
|
|
182
178
|
dataType: "string enum";
|
|
183
|
-
data: "
|
|
179
|
+
data: "completed" | "ongoing" | "unknown";
|
|
184
180
|
driverParam: string;
|
|
185
181
|
notNull: true;
|
|
186
182
|
hasDefault: false;
|
|
@@ -209,7 +205,8 @@ declare function getDrizzle(client: Client): import("drizzle-orm/libsql").LibSQL
|
|
|
209
205
|
generated: undefined;
|
|
210
206
|
}, {}>;
|
|
211
207
|
};
|
|
212
|
-
dialect:
|
|
208
|
+
dialect: 'sqlite';
|
|
209
|
+
isAlias: false;
|
|
213
210
|
}>;
|
|
214
211
|
genres: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
215
212
|
name: "genres";
|
|
@@ -248,7 +245,8 @@ declare function getDrizzle(client: Client): import("drizzle-orm/libsql").LibSQL
|
|
|
248
245
|
generated: undefined;
|
|
249
246
|
}, {}>;
|
|
250
247
|
};
|
|
251
|
-
dialect:
|
|
248
|
+
dialect: 'sqlite';
|
|
249
|
+
isAlias: false;
|
|
252
250
|
}>;
|
|
253
251
|
novelGenres: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
254
252
|
name: "novel_genres";
|
|
@@ -287,7 +285,8 @@ declare function getDrizzle(client: Client): import("drizzle-orm/libsql").LibSQL
|
|
|
287
285
|
generated: undefined;
|
|
288
286
|
}, {}>;
|
|
289
287
|
};
|
|
290
|
-
dialect:
|
|
288
|
+
dialect: 'sqlite';
|
|
289
|
+
isAlias: false;
|
|
291
290
|
}>;
|
|
292
291
|
volumes: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
293
292
|
name: "volumes";
|
|
@@ -390,7 +389,8 @@ declare function getDrizzle(client: Client): import("drizzle-orm/libsql").LibSQL
|
|
|
390
389
|
generated: undefined;
|
|
391
390
|
}, {}>;
|
|
392
391
|
};
|
|
393
|
-
dialect:
|
|
392
|
+
dialect: 'sqlite';
|
|
393
|
+
isAlias: false;
|
|
394
394
|
}>;
|
|
395
395
|
chapters: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
396
396
|
name: "chapters";
|
|
@@ -509,7 +509,8 @@ declare function getDrizzle(client: Client): import("drizzle-orm/libsql").LibSQL
|
|
|
509
509
|
generated: undefined;
|
|
510
510
|
}, {}>;
|
|
511
511
|
};
|
|
512
|
-
dialect:
|
|
512
|
+
dialect: 'sqlite';
|
|
513
|
+
isAlias: false;
|
|
513
514
|
}>;
|
|
514
515
|
keywordSearches: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
515
516
|
name: "keyword_searches";
|
|
@@ -580,7 +581,8 @@ declare function getDrizzle(client: Client): import("drizzle-orm/libsql").LibSQL
|
|
|
580
581
|
generated: undefined;
|
|
581
582
|
}, {}>;
|
|
582
583
|
};
|
|
583
|
-
dialect:
|
|
584
|
+
dialect: 'sqlite';
|
|
585
|
+
isAlias: false;
|
|
584
586
|
}>;
|
|
585
587
|
keywordNovels: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
586
588
|
name: "keyword_novels";
|
|
@@ -619,7 +621,8 @@ declare function getDrizzle(client: Client): import("drizzle-orm/libsql").LibSQL
|
|
|
619
621
|
generated: undefined;
|
|
620
622
|
}, {}>;
|
|
621
623
|
};
|
|
622
|
-
dialect:
|
|
624
|
+
dialect: 'sqlite';
|
|
625
|
+
isAlias: false;
|
|
623
626
|
}>;
|
|
624
627
|
novelCoverMetadata: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
625
628
|
name: "novel_cover_metadata";
|
|
@@ -706,7 +709,8 @@ declare function getDrizzle(client: Client): import("drizzle-orm/libsql").LibSQL
|
|
|
706
709
|
generated: undefined;
|
|
707
710
|
}, {}>;
|
|
708
711
|
};
|
|
709
|
-
dialect:
|
|
712
|
+
dialect: 'sqlite';
|
|
713
|
+
isAlias: false;
|
|
710
714
|
}>;
|
|
711
715
|
volumeCoverMetadata: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
712
716
|
name: "volume_cover_metadata";
|
|
@@ -793,7 +797,8 @@ declare function getDrizzle(client: Client): import("drizzle-orm/libsql").LibSQL
|
|
|
793
797
|
generated: undefined;
|
|
794
798
|
}, {}>;
|
|
795
799
|
};
|
|
796
|
-
dialect:
|
|
800
|
+
dialect: 'sqlite';
|
|
801
|
+
isAlias: false;
|
|
797
802
|
}>;
|
|
798
803
|
cookies: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
799
804
|
name: "cookies";
|
|
@@ -947,7 +952,7 @@ declare function getDrizzle(client: Client): import("drizzle-orm/libsql").LibSQL
|
|
|
947
952
|
name: string;
|
|
948
953
|
tableName: "cookies";
|
|
949
954
|
dataType: "string enum";
|
|
950
|
-
data: "
|
|
955
|
+
data: "Lax" | "None" | "Strict";
|
|
951
956
|
driverParam: string;
|
|
952
957
|
notNull: false;
|
|
953
958
|
hasDefault: false;
|
|
@@ -992,7 +997,8 @@ declare function getDrizzle(client: Client): import("drizzle-orm/libsql").LibSQL
|
|
|
992
997
|
generated: undefined;
|
|
993
998
|
}, {}>;
|
|
994
999
|
};
|
|
995
|
-
dialect:
|
|
1000
|
+
dialect: 'sqlite';
|
|
1001
|
+
isAlias: false;
|
|
996
1002
|
}>;
|
|
997
1003
|
generalCache: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
998
1004
|
name: "general_cache";
|
|
@@ -1031,13 +1037,14 @@ declare function getDrizzle(client: Client): import("drizzle-orm/libsql").LibSQL
|
|
|
1031
1037
|
generated: undefined;
|
|
1032
1038
|
}, {}>;
|
|
1033
1039
|
};
|
|
1034
|
-
dialect:
|
|
1040
|
+
dialect: 'sqlite';
|
|
1041
|
+
isAlias: false;
|
|
1035
1042
|
}>;
|
|
1036
1043
|
}>>> & {
|
|
1037
1044
|
$client: Client;
|
|
1038
1045
|
};
|
|
1039
1046
|
type DrizzleInstance = ReturnType<typeof getDrizzle>;
|
|
1040
|
-
declare class DatabaseService {
|
|
1047
|
+
export declare class DatabaseService {
|
|
1041
1048
|
private client;
|
|
1042
1049
|
db: DrizzleInstance;
|
|
1043
1050
|
constructor(options: DatabaseOptions);
|
|
@@ -1054,13 +1061,11 @@ declare class DatabaseService {
|
|
|
1054
1061
|
addNovelCoverMetadata(metadata: NovelCoverMetadata): Promise<void>;
|
|
1055
1062
|
getVolumeCoverMetadata(platform: string, volumeId: string): Promise<VolumeCoverMetadata | undefined>;
|
|
1056
1063
|
addVolumeCoverMetadata(metadata: VolumeCoverMetadata): Promise<void>;
|
|
1057
|
-
getCache<T>(key: string, schema: z.ZodType<T>): Promise<T | null>;
|
|
1064
|
+
getCache<T>(key: string, schema: z$1.ZodType<T>): Promise<T | null>;
|
|
1058
1065
|
setCache<T>(key: string, value: T): Promise<void>;
|
|
1059
1066
|
close(logger?: (message: string) => void): Promise<void>;
|
|
1060
1067
|
}
|
|
1061
|
-
|
|
1062
|
-
//#region src/cookies.d.ts
|
|
1063
|
-
declare class DatabaseCookieStore implements CookiesStore {
|
|
1068
|
+
export declare class DatabaseCookieStore implements CookiesStore {
|
|
1064
1069
|
private db;
|
|
1065
1070
|
[cookieStoreSign]: true;
|
|
1066
1071
|
constructor(dbService: DatabaseService);
|
|
@@ -1074,9 +1079,7 @@ declare class DatabaseCookieStore implements CookiesStore {
|
|
|
1074
1079
|
update(init: CookiesInit): Promise<void>;
|
|
1075
1080
|
[Symbol.asyncIterator](): AsyncIterator<Cookie>;
|
|
1076
1081
|
}
|
|
1077
|
-
|
|
1078
|
-
//#region src/files.d.ts
|
|
1079
|
-
declare class FSStorageService {
|
|
1082
|
+
export declare class FSStorageService {
|
|
1080
1083
|
private basePath;
|
|
1081
1084
|
private dbService;
|
|
1082
1085
|
constructor(basePath: string, dbService: DatabaseService);
|
|
@@ -1086,13 +1089,11 @@ declare class FSStorageService {
|
|
|
1086
1089
|
getCoverData(type: "novel" | "volume", platform: string, platformId: string): Promise<BinaryResponse | undefined>;
|
|
1087
1090
|
setCoverData(type: "novel" | "volume", url: string, platform: string, platformId: string, data: Buffer, contentType: string): Promise<void>;
|
|
1088
1091
|
}
|
|
1089
|
-
//#endregion
|
|
1090
|
-
//#region src/service.d.ts
|
|
1091
1092
|
interface StorageServiceOptions {
|
|
1092
1093
|
dataDir?: string;
|
|
1093
1094
|
db: DatabaseOptions;
|
|
1094
1095
|
}
|
|
1095
|
-
declare class StorageService {
|
|
1096
|
+
export declare class StorageService {
|
|
1096
1097
|
private db;
|
|
1097
1098
|
private files;
|
|
1098
1099
|
private cookieStore;
|
|
@@ -1110,10 +1111,8 @@ declare class StorageService {
|
|
|
1110
1111
|
getChapterFromId(platform: string, platformId: string): Promise<Chapter | undefined>;
|
|
1111
1112
|
addNovelContentHash(platform: string, chapterId: string, contentHash: string): Promise<void>;
|
|
1112
1113
|
getCookieStore(): DatabaseCookieStore;
|
|
1113
|
-
getCache<T>(key: string, schema: z
|
|
1114
|
+
getCache<T>(key: string, schema: z.ZodType<T>): Promise<T | null>;
|
|
1114
1115
|
setCache<T>(key: string, value: T): Promise<void>;
|
|
1115
1116
|
close(logger?: (message: string) => void): Promise<void>;
|
|
1116
1117
|
}
|
|
1117
|
-
|
|
1118
|
-
export { DatabaseCookieStore, type DatabaseOptions, DatabaseService, FSStorageService, type MigrationOptions, StorageService, type StorageServiceOptions };
|
|
1119
|
-
//# sourceMappingURL=index.d.mts.map
|
|
1118
|
+
export type { DatabaseOptions, MigrationOptions, StorageServiceOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -8,8 +8,8 @@ import { drizzle } from "drizzle-orm/libsql";
|
|
|
8
8
|
import { migrate } from "drizzle-orm/libsql/migrator";
|
|
9
9
|
import { mkdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
10
10
|
import { createHash } from "node:crypto";
|
|
11
|
-
import { zstdCompress, zstdDecompress } from "node:zlib";
|
|
12
|
-
|
|
11
|
+
import { zstdCompress as zstdCompress$1, zstdDecompress as zstdDecompress$1 } from "node:zlib";
|
|
12
|
+
// src/table.ts
|
|
13
13
|
const novels = sqliteTable("novels", {
|
|
14
14
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
15
15
|
platform: text("platform").notNull(),
|
|
@@ -155,8 +155,7 @@ const relations = defineRelations({
|
|
|
155
155
|
to: r.novels.id.through(r.keywordNovels.novelId)
|
|
156
156
|
}) }
|
|
157
157
|
}));
|
|
158
|
-
|
|
159
|
-
//#region src/cookies.ts
|
|
158
|
+
// src/cookies.ts
|
|
160
159
|
var DatabaseCookieStore = class {
|
|
161
160
|
db;
|
|
162
161
|
[cookieStoreSign] = true;
|
|
@@ -293,9 +292,9 @@ var DatabaseCookieStore = class {
|
|
|
293
292
|
const parsedUrl = typeof url === "string" ? new URL(url) : url;
|
|
294
293
|
const hostname = parsedUrl.hostname;
|
|
295
294
|
const pathname = parsedUrl.pathname;
|
|
296
|
-
const now = Date.now();
|
|
297
295
|
const secure = parsedUrl.protocol === "https:";
|
|
298
296
|
return (await this.db.query.cookies.findMany()).filter((cookie) => {
|
|
297
|
+
const now = Date.now();
|
|
299
298
|
if (cookie.secure && !secure) return false;
|
|
300
299
|
if (cookie.domain && !matchesDomain(cookie.domain, hostname)) return false;
|
|
301
300
|
if (cookie.path && !matchesPath(cookie.path, pathname)) return false;
|
|
@@ -335,8 +334,10 @@ var DatabaseCookieStore = class {
|
|
|
335
334
|
httpOnly: cookie.httpOnly,
|
|
336
335
|
sameSite: cookie.sameSite ?? "Lax"
|
|
337
336
|
});
|
|
338
|
-
else if (typeof init === "object")
|
|
339
|
-
|
|
337
|
+
else if (typeof init === "object") {
|
|
338
|
+
if (Symbol.iterator in init) for (const [name, value] of init) await this.set(name, value);
|
|
339
|
+
else for (const [name, value] of Object.entries(init)) await this.set(name, value);
|
|
340
|
+
}
|
|
340
341
|
}
|
|
341
342
|
[Symbol.asyncIterator]() {
|
|
342
343
|
const allCookies = this.db.query.cookies.findMany();
|
|
@@ -364,8 +365,7 @@ var DatabaseCookieStore = class {
|
|
|
364
365
|
} };
|
|
365
366
|
}
|
|
366
367
|
};
|
|
367
|
-
|
|
368
|
-
//#region src/db.ts
|
|
368
|
+
// src/db.ts
|
|
369
369
|
function getDrizzle(client) {
|
|
370
370
|
return drizzle({
|
|
371
371
|
client,
|
|
@@ -431,7 +431,7 @@ var DatabaseService = class {
|
|
|
431
431
|
});
|
|
432
432
|
}
|
|
433
433
|
async searchNovels(keyword, platform) {
|
|
434
|
-
const minQueryTime = Date.now() -
|
|
434
|
+
const minQueryTime = Date.now() - 1728e5;
|
|
435
435
|
const searchRecord = await this.db.query.keywordSearches.findFirst({
|
|
436
436
|
where: {
|
|
437
437
|
keyword,
|
|
@@ -708,19 +708,18 @@ var DatabaseService = class {
|
|
|
708
708
|
}
|
|
709
709
|
}
|
|
710
710
|
};
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
const zstdCompress$1 = (data) => {
|
|
711
|
+
// src/utils.ts
|
|
712
|
+
const zstdCompress = (data) => {
|
|
714
713
|
return new Promise((resolve, reject) => {
|
|
715
|
-
zstdCompress(data, (err, compressedData) => {
|
|
714
|
+
zstdCompress$1(data, (err, compressedData) => {
|
|
716
715
|
if (err) reject(err);
|
|
717
716
|
else resolve(compressedData);
|
|
718
717
|
});
|
|
719
718
|
});
|
|
720
719
|
};
|
|
721
|
-
const zstdDecompress
|
|
720
|
+
const zstdDecompress = (data) => {
|
|
722
721
|
return new Promise((resolve, reject) => {
|
|
723
|
-
zstdDecompress(data, (err, decompressedData) => {
|
|
722
|
+
zstdDecompress$1(data, (err, decompressedData) => {
|
|
724
723
|
if (err) reject(err);
|
|
725
724
|
else resolve(decompressedData);
|
|
726
725
|
});
|
|
@@ -740,8 +739,7 @@ function getExtFromContentType(contentType) {
|
|
|
740
739
|
if (contentType.includes("avif")) return "avif";
|
|
741
740
|
return "bin";
|
|
742
741
|
}
|
|
743
|
-
|
|
744
|
-
//#region src/files.ts
|
|
742
|
+
// src/files.ts
|
|
745
743
|
var FSStorageService = class {
|
|
746
744
|
basePath;
|
|
747
745
|
dbService;
|
|
@@ -759,14 +757,17 @@ var FSStorageService = class {
|
|
|
759
757
|
async getNovelContent(hash) {
|
|
760
758
|
const chapterFilePath = `${`${this.basePath}/novels/${hash.slice(0, 2)}`}/${hash}.zst`;
|
|
761
759
|
if (!existsSync(chapterFilePath)) return;
|
|
762
|
-
const
|
|
760
|
+
const compressedData = await readFile(chapterFilePath);
|
|
761
|
+
const decompressedData = await zstdDecompress(compressedData);
|
|
763
762
|
return new TextDecoder().decode(decompressedData);
|
|
764
763
|
}
|
|
765
764
|
async setNovelContent(content) {
|
|
766
765
|
const hash = getContentHash(content);
|
|
767
766
|
const novelCacheDir = `${this.basePath}/novels/${hash.slice(0, 2)}`;
|
|
768
767
|
await this._initPath(novelCacheDir);
|
|
769
|
-
|
|
768
|
+
const chapterFilePath = `${novelCacheDir}/${hash}.zst`;
|
|
769
|
+
const compressedData = await zstdCompress(Buffer.from(content, "utf-8"));
|
|
770
|
+
await writeFile(chapterFilePath, compressedData);
|
|
770
771
|
return hash;
|
|
771
772
|
}
|
|
772
773
|
async getCoverData(type, platform, platformId) {
|
|
@@ -786,7 +787,8 @@ var FSStorageService = class {
|
|
|
786
787
|
const ext = getExtFromContentType(contentType);
|
|
787
788
|
const coverDir = `${this.basePath}/covers/${coverHash.slice(0, 2)}`;
|
|
788
789
|
await this._initPath(coverDir);
|
|
789
|
-
|
|
790
|
+
const coverPath = `${coverDir}/${coverHash}.${ext}`;
|
|
791
|
+
await writeFile(coverPath, data);
|
|
790
792
|
if (type === "novel") await this.dbService.addNovelCoverMetadata({
|
|
791
793
|
platform,
|
|
792
794
|
novelId: platformId,
|
|
@@ -803,8 +805,7 @@ var FSStorageService = class {
|
|
|
803
805
|
});
|
|
804
806
|
}
|
|
805
807
|
};
|
|
806
|
-
|
|
807
|
-
//#region src/service.ts
|
|
808
|
+
// src/service.ts
|
|
808
809
|
var StorageService = class {
|
|
809
810
|
db;
|
|
810
811
|
files;
|
|
@@ -865,7 +866,6 @@ var StorageService = class {
|
|
|
865
866
|
await this.db.close(logger);
|
|
866
867
|
}
|
|
867
868
|
};
|
|
868
|
-
//#endregion
|
|
869
869
|
export { DatabaseCookieStore, DatabaseService, FSStorageService, StorageService };
|
|
870
870
|
|
|
871
871
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["zstdCompress","zstdDecompress","zstdDecompress","zstdCompress"],"sources":["../src/table.ts","../src/cookies.ts","../src/db.ts","../src/utils.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} 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 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},\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 now = Date.now();\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\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 { existsSync, mkdirSync, rmSync, statSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport type {\n\tChapter,\n\tNovel,\n\tNovelSearchResult,\n\tVolume,\n} from \"@acanthis-dec/core\";\nimport { type Client, createClient } from \"@libsql/client\";\nimport { and, eq } from \"drizzle-orm\";\nimport { drizzle } from \"drizzle-orm/libsql\";\nimport { migrate } from \"drizzle-orm/libsql/migrator\";\nimport type { z } from \"zod\";\nimport {\n\tchapters,\n\tgeneralCache,\n\tgenres,\n\tkeywordNovels,\n\tkeywordSearches,\n\tnovelCoverMetadata,\n\tnovelGenres,\n\tnovels,\n\trelations,\n\tvolumeCoverMetadata,\n\tvolumes,\n} from \"./table\";\nimport type {\n\tDataWithUpdatedAt,\n\tNovelCoverMetadata,\n\tVolumeCoverMetadata,\n} from \"./type\";\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\nexport class DatabaseService {\n\tprivate client: Client;\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.client.execute(\"PRAGMA journal_mode = WAL;\");\n\t\tthis.db = getDrizzle(this.client);\n\t\tif (options.migrations?.enabled ?? true) {\n\t\t\tthis._migrate(options.migrations?.directory);\n\t\t}\n\t}\n\n\tprivate _migrate(directory?: string) {\n\t\tif (!this.db) throw new Error(\"Database not initialized\");\n\t\tmigrate(this.db, {\n\t\t\tmigrationsFolder: directory || \"migrations\",\n\t\t});\n\t}\n\n\tasync addSearchResult(\n\t\tkeyword: string,\n\t\tplatform: string,\n\t\tresults: NovelSearchResult[],\n\t) {\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\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.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\tfor (const volume of novel.volumes) {\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\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\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\t\t});\n\t}\n\n\tasync getNovelCache(\n\t\tplatform: string,\n\t\tplatformId: string,\n\t): Promise<DataWithUpdatedAt<Novel | null>> {\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\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\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\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.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\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\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\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\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\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.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 close(logger?: (message: string) => void) {\n\t\ttry {\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 { 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 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 } 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","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\";\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 close(logger?: (message: string) => void) {\n\t\tawait this.db.close(logger);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AASA,MAAa,SAAS,YACrB,UACA;CACC,IAAI,QAAQ,IAAI,CAAC,CAAC,WAAW,EA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AK;CAClC;CAEA,MAAM,MAAM,QAAoC;EAC/C,MAAM,KAAK,GAAG,MAAM,MAAM;CAC3B;AACD"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["zc","zd"],"sources":["../src/table.ts","../src/cookies.ts","../src/db.ts","../src/utils.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} 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 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},\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 { existsSync, mkdirSync, rmSync, statSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport type {\n\tChapter,\n\tNovel,\n\tNovelSearchResult,\n\tVolume,\n} from \"@acanthis-dec/core\";\nimport { type Client, createClient } from \"@libsql/client\";\nimport { and, eq } from \"drizzle-orm\";\nimport { drizzle } from \"drizzle-orm/libsql\";\nimport { migrate } from \"drizzle-orm/libsql/migrator\";\nimport type { z } from \"zod\";\nimport {\n\tchapters,\n\tgeneralCache,\n\tgenres,\n\tkeywordNovels,\n\tkeywordSearches,\n\tnovelCoverMetadata,\n\tnovelGenres,\n\tnovels,\n\trelations,\n\tvolumeCoverMetadata,\n\tvolumes,\n} from \"./table\";\nimport type {\n\tDataWithUpdatedAt,\n\tNovelCoverMetadata,\n\tVolumeCoverMetadata,\n} from \"./type\";\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\nexport class DatabaseService {\n\tprivate client: Client;\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.client.execute(\"PRAGMA journal_mode = WAL;\");\n\t\tthis.db = getDrizzle(this.client);\n\t\tif (options.migrations?.enabled ?? true) {\n\t\t\tthis._migrate(options.migrations?.directory);\n\t\t}\n\t}\n\n\tprivate _migrate(directory?: string) {\n\t\tif (!this.db) throw new Error(\"Database not initialized\");\n\t\tmigrate(this.db, {\n\t\t\tmigrationsFolder: directory || \"migrations\",\n\t\t});\n\t}\n\n\tasync addSearchResult(\n\t\tkeyword: string,\n\t\tplatform: string,\n\t\tresults: NovelSearchResult[],\n\t) {\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\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.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\tfor (const volume of novel.volumes) {\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\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\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\t\t});\n\t}\n\n\tasync getNovelCache(\n\t\tplatform: string,\n\t\tplatformId: string,\n\t): Promise<DataWithUpdatedAt<Novel | null>> {\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\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\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\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.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\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\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\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\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\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.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 close(logger?: (message: string) => void) {\n\t\ttry {\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 { 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 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 } 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","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\";\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 close(logger?: (message: string) => void) {\n\t\tawait this.db.close(logger);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AASA,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,CA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1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acanthis-dec/storage",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
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,20 +26,20 @@
|
|
|
26
26
|
"url": "https://github.com/ConstasJ/Acanthis/issues"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@
|
|
29
|
+
"@acanthis-dec/browser-fetch": "1.1.2",
|
|
30
|
+
"@acanthis-dec/core": "1.1.0",
|
|
31
|
+
"@libsql/client": "^0.18.0",
|
|
30
32
|
"drizzle-orm": "rc",
|
|
31
|
-
"zod": "^4.
|
|
32
|
-
"@acanthis-dec/browser-fetch": "1.1.0",
|
|
33
|
-
"@acanthis-dec/core": "1.1.0"
|
|
33
|
+
"zod": "^4.6.7"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"drizzle-kit": "rc",
|
|
38
|
-
"tsdown": "0.22.2",
|
|
39
|
-
"tsx": "4.22.4",
|
|
40
|
-
"typescript": "6.0.3",
|
|
36
|
+
"@acanthis-dec/config-tsdown": "1.0.0",
|
|
41
37
|
"@acanthis-dec/config-typescript": "1.0.0",
|
|
42
|
-
"@
|
|
38
|
+
"@types/node": "26.6.6",
|
|
39
|
+
"drizzle-kit": "rc",
|
|
40
|
+
"tsdown": "0.23.7",
|
|
41
|
+
"tsx": "4.23.15",
|
|
42
|
+
"typescript": "7.0.2"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "tsdown",
|