@acanthis-dec/storage 1.0.2 → 1.0.3

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.mjs CHANGED
@@ -634,12 +634,23 @@ var DatabaseService = class {
634
634
  platform: metadata.platform,
635
635
  platformId: metadata.novelId
636
636
  } }).execute() : null;
637
+ let novelId = null;
638
+ if (!novel) novelId = (await this.db.insert(novels).values({
639
+ platform: metadata.platform ?? "",
640
+ platformId: metadata.novelId ?? "",
641
+ name: "",
642
+ coverUrl: metadata.originalUrl ?? "",
643
+ author: "",
644
+ summary: "",
645
+ status: "unknown",
646
+ updateAt: Date.now()
647
+ }).onConflictDoNothing().returning({ id: novels.id }).get())?.id ?? null;
637
648
  await this.db.insert(novelCoverMetadata).values({
638
649
  hash: metadata.hash,
639
650
  contentType: metadata.contentType,
640
651
  originalUrl: metadata.originalUrl,
641
- novelId: novel?.id ?? null
642
- }).run();
652
+ novelId: novel?.id ?? novelId ?? null
653
+ }).onConflictDoNothing().run();
643
654
  }
644
655
  async getVolumeCoverMetadata(platform, volumeId) {
645
656
  const queryResult = await this.db.query.volumeCoverMetadata.findFirst({
@@ -668,7 +679,7 @@ var DatabaseService = class {
668
679
  contentType: metadata.contentType,
669
680
  originalUrl: metadata.originalUrl,
670
681
  volumeId: volume?.id ?? null
671
- }).run();
682
+ }).onConflictDoNothing().run();
672
683
  }
673
684
  async getCache(key, schema) {
674
685
  const record = await this.db.query.generalCache.findFirst({ where: { key } }).execute();
@@ -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\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 ?? null,\n\t\t\t})\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.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,CAAC,CAAC,QAAQ;CAC/B,SAAS,KAAK,SAAS,CAAC,CAAC,QAAQ;CACjC,UAAU,KAAK,WAAW,CAAC,CAAC,QAAQ;CACpC,QAAQ,KAAK,UAAU,EACtB,MAAM;EAAC;EAAW;EAAa;CAAS,EACzC,CAAC,CAAC,CAAC,QAAQ;CACX,UAAU,QAAQ,WAAW,CAAC,CAAC,QAAQ;AACxC,IACC,UAAU,CACV,OAAO,sBAAsB,CAAC,CAAC,GAAG,MAAM,UAAU,MAAM,UAAU,CACnE,CACD;AAEA,MAAa,SAAS,YAAY,UAAU;CAC3C,IAAI,QAAQ,IAAI,CAAC,CAAC,WAAW,EAAE,eAAe,KAAK,CAAC;CACpD,MAAM,KAAK,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,OAAO;AACrC,CAAC;AAED,MAAa,cAAc,YAC1B,gBACA;CACC,SAAS,QAAQ,UAAU,CAAC,CAC1B,QAAQ,CAAC,CACT,iBAAiB,OAAO,IAAI,EAAE,UAAU,UAAU,CAAC;CACrD,SAAS,QAAQ,UAAU,CAAC,CAC1B,QAAQ,CAAC,CACT,iBAAiB,OAAO,IAAI,EAAE,UAAU,UAAU,CAAC;AACtD,IACC,UAAU,CAAC,WAAW,EAAE,SAAS,CAAC,MAAM,SAAS,MAAM,OAAO,EAAE,CAAC,CAAC,CACpE;AAEA,MAAa,UAAU,YACtB,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UACA,YACgB;EAChB,MAAM,KAAK,MAAM,aAChB,MACA,KACA,UACA,YACA,MACA,WACD;CACD;CAEA,MAAM,gBACL,SACA,UACA,SACgB;EAChB,MAAM,KAAK,GAAG,gBAAgB,SAAS,UAAU,OAAO;CACzD;CAEA,MAAM,aACL,SACA,UAC2C;EAC3C,MAAM,OAAO,MAAM,KAAK,GAAG,aAAa,SAAS,QAAQ;EACzD,OAAO,OAAO,KAAK,OAAO,KAAA;CAC3B;CAEA,MAAM,cAAc,UAAkB,YAAoB;EACzD,MAAM,OAAO,MAAM,KAAK,GAAG,cAAc,UAAU,UAAU;EAC7D,OAAO,OAAO,KAAK,OAAO,KAAA;CAC3B;CAEA,MAAM,cAAc,OAAc;EACjC,MAAM,KAAK,GAAG,cAAc,KAAK;CAClC;CAEA,MAAM,cAAc,UAAkB,YAAoB;EACzD,OAAO,MAAM,KAAK,GAAG,cAAc,UAAU,UAAU;CACxD;CAEA,MAAM,oBACL,OACwC;EACxC,OAAO,MAAM,KAAK,GAAG,oBAAoB,KAAK;CAC/C;CAEA,MAAM,iBACL,UACA,YAC+B;EAC/B,OAAO,MAAM,KAAK,GAAG,iBAAiB,UAAU,UAAU;CAC3D;CAEA,MAAM,oBACL,UACA,WACA,aACC;EACD,MAAM,KAAK,GAAG,oBAAoB,UAAU,WAAW,WAAW;CACnE;CAEA,iBAAiB;EAChB,OAAO,KAAK;CACb;CAEA,MAAM,SAAY,KAAa,QAAyC;EACvE,OAAO,MAAM,KAAK,GAAG,SAAS,KAAK,MAAM;CAC1C;CAEA,MAAM,SAAY,KAAa,OAAyB;EACvD,MAAM,KAAK,GAAG,SAAS,KAAK,KAAK;CAClC;CAEA,MAAM,MAAM,QAAoC;EAC/C,MAAM,KAAK,GAAG,MAAM,MAAM;CAC3B;AACD"}
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,EAAE,eAAe,KAAK,CAAC;CACpD,UAAU,KAAK,UAAU,CAAC,CAAC,QAAQ;CACnC,YAAY,KAAK,aAAa,CAAC,CAAC,QAAQ;CACxC,MAAM,KAAK,MAAM,CAAC,CAAC,QAAQ;CAC3B,QAAQ,KAAK,QAAQ,CAAC,CAAC,QAAQ;CAC/B,SAAS,KAAK,SAAS,CAAC,CAAC,QAAQ;CACjC,UAAU,KAAK,WAAW,CAAC,CAAC,QAAQ;CACpC,QAAQ,KAAK,UAAU,EACtB,MAAM;EAAC;EAAW;EAAa;CAAS,EACzC,CAAC,CAAC,CAAC,Q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CAEA,MAAM,aACL,SACA,UAC2C;EAC3C,MAAM,OAAO,MAAM,KAAK,GAAG,aAAa,SAAS,QAAQ;EACzD,OAAO,OAAO,KAAK,OAAO,KAAA;CAC3B;CAEA,MAAM,cAAc,UAAkB,YAAoB;EACzD,MAAM,OAAO,MAAM,KAAK,GAAG,cAAc,UAAU,UAAU;EAC7D,OAAO,OAAO,KAAK,OAAO,KAAA;CAC3B;CAEA,MAAM,cAAc,OAAc;EACjC,MAAM,KAAK,GAAG,cAAc,KAAK;CAClC;CAEA,MAAM,cAAc,UAAkB,YAAoB;EACzD,OAAO,MAAM,KAAK,GAAG,cAAc,UAAU,UAAU;CACxD;CAEA,MAAM,oBACL,OACwC;EACxC,OAAO,MAAM,KAAK,GAAG,oBAAoB,KAAK;CAC/C;CAEA,MAAM,iBACL,UACA,YAC+B;EAC/B,OAAO,MAAM,KAAK,GAAG,iBAAiB,UAAU,UAAU;CAC3D;CAEA,MAAM,oBACL,UACA,WACA,aACC;EACD,MAAM,KAAK,GAAG,oBAAoB,UAAU,WAAW,WAAW;CACnE;CAEA,iBAAiB;EAChB,OAAO,KAAK;CACb;CAEA,MAAM,SAAY,KAAa,QAAyC;EACvE,OAAO,MAAM,KAAK,GAAG,SAAS,KAAK,MAAM;CAC1C;CAEA,MAAM,SAAY,KAAa,OAAyB;EACvD,MAAM,KAAK,GAAG,SAAS,KAAK,KAAK;CAClC;CAEA,MAAM,MAAM,QAAoC;EAC/C,MAAM,KAAK,GAAG,MAAM,MAAM;CAC3B;AACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acanthis-dec/storage",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
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",
@@ -38,8 +38,8 @@
38
38
  "tsdown": "0.22.2",
39
39
  "tsx": "4.22.4",
40
40
  "typescript": "6.0.3",
41
- "@acanthis-dec/config-tsdown": "1.0.0",
42
- "@acanthis-dec/config-typescript": "1.0.0"
41
+ "@acanthis-dec/config-typescript": "1.0.0",
42
+ "@acanthis-dec/config-tsdown": "1.0.0"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "tsdown",