@serifpersia/dango 3.6.7 → 3.6.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.
Files changed (149) hide show
  1. package/README.md +1 -1
  2. package/client/dist/assets/{AnimeCard-C3P9zWi9.js → AnimeCard-DraA_TF9.js} +1 -1
  3. package/client/dist/assets/{AnimeInfo-Et6687Tl.js → AnimeInfo-BJ7pzs-P.js} +1 -1
  4. package/client/dist/assets/{AnimeInfoPage-DX4eNnlH.js → AnimeInfoPage-B_esUr5C.js} +2 -2
  5. package/client/dist/assets/{Asmr-CCdEWrFi.js → Asmr-Ckuh2xfW.js} +1 -1
  6. package/client/dist/assets/{AsmrResetProgressModal-DgEWBJOw.js → AsmrResetProgressModal-BS6UFJN4.js} +1 -1
  7. package/client/dist/assets/{AvSyncCalibrator-CQ2fjf2E.js → AvSyncCalibrator-DwHCd9yB.js} +1 -1
  8. package/client/dist/assets/{Home-DUkUTTTy.js → Home-DuM1EuvN.js} +1 -1
  9. package/client/dist/assets/{Insights-QCh4xW12.js → Insights-D3Pd9c9V.js} +1 -1
  10. package/client/dist/assets/{LibraryListPage-BoTxRqHz.js → LibraryListPage-Dm2yVn0-.js} +1 -1
  11. package/client/dist/assets/{ListeningList-DguKjI_t.js → ListeningList-D-zt6EXZ.js} +1 -1
  12. package/client/dist/assets/{Manga-HydR-L7o.js → Manga-JwprMKBk.js} +1 -1
  13. package/client/dist/assets/{MangaInfoPage-CBakEI9a.js → MangaInfoPage-DaeyJl2p.js} +1 -1
  14. package/client/dist/assets/{MangaReadPage-DwAR3iPy.js → MangaReadPage-COg0fHI9.js} +1 -1
  15. package/client/dist/assets/{MangaResetProgressModal-DGzl8vsO.js → MangaResetProgressModal-kguXv0_M.js} +1 -1
  16. package/client/dist/assets/{Mature-Pi0TxKuF.js → Mature-IHDaasrs.js} +1 -1
  17. package/client/dist/assets/{MediaCard--cuFxOCS.js → MediaCard-CpwsrXo5.js} +1 -1
  18. package/client/dist/assets/{Music-CQpyXTLH.js → Music-Dks4tPeK.js} +1 -1
  19. package/client/dist/assets/{OptionListMenu-B3D39dGS.js → OptionListMenu-11CcAsy8.js} +1 -1
  20. package/client/dist/assets/{Player-CsH4x_I_.js → Player-DQoEQkHL.js} +2 -2
  21. package/client/dist/assets/{PlayerSettings-DGxBsi3F.js → PlayerSettings-D4Ud4kv4.js} +1 -1
  22. package/client/dist/assets/{QueueOptionsButton-Djq4Cpex.js → QueueOptionsButton-B8PlPKjC.js} +1 -1
  23. package/client/dist/assets/{QueueRail-DOrYgNVX.js → QueueRail-B4Dok7U3.js} +1 -1
  24. package/client/dist/assets/{Radio-DF6g6odd.js → Radio-BHK6LSk4.js} +1 -1
  25. package/client/dist/assets/{ReadingList-DwYoBrNk.js → ReadingList-BCsxIz57.js} +1 -1
  26. package/client/dist/assets/{ResetProgressModal-CMF86mX6.js → ResetProgressModal-BXHxSfy-.js} +1 -1
  27. package/client/dist/assets/{Search-DFkhuk-x.js → Search-PK1ds07O.js} +1 -1
  28. package/client/dist/assets/{Settings-DBB2r0VQ.js → Settings-Bxk_x55l.js} +1 -1
  29. package/client/dist/assets/{SkeletonGrid-DJelJgAv.js → SkeletonGrid-CpJCZSRN.js} +1 -1
  30. package/client/dist/assets/{Trackers-DGYXFhYZ.js → Trackers-RieCh_84.js} +1 -1
  31. package/client/dist/assets/{Tv-C5MDGD2Z.js → Tv-DLytPJUj.js} +1 -1
  32. package/client/dist/assets/{TvInfo-DrKuK13u.js → TvInfo-C8djKebR.js} +1 -1
  33. package/client/dist/assets/{TvPopup-DtHilRDT.js → TvPopup-40JGGJDk.js} +1 -1
  34. package/client/dist/assets/{TvSearch-CzNxdu_w.js → TvSearch-A3hbospf.js} +1 -1
  35. package/client/dist/assets/{TvWatchlist-D7p4br6S.js → TvWatchlist-DuXjqmZM.js} +1 -1
  36. package/client/dist/assets/{Watchlist-DrOzswl2.js → Watchlist-B9wGBh0u.js} +1 -1
  37. package/client/dist/assets/{hls-BGCX7mJy.js → hls-CZ5X3Ya-.js} +1 -1
  38. package/client/dist/assets/{index-CnfZwsds.js → index-dRhc9-ol.js} +2 -2
  39. package/client/dist/assets/{useAnimeInfoData-DYXWBPF-.js → useAnimeInfoData-ZzDtLfvD.js} +1 -1
  40. package/client/dist/assets/{useAsmr-BbhQ59bk.js → useAsmr-CKOdHgol.js} +1 -1
  41. package/client/dist/assets/{useAsmrPopup-SymV1J-b.js → useAsmrPopup-SFHPhpcl.js} +1 -1
  42. package/client/dist/assets/{useMangaLibrary-DuesWQaE.js → useMangaLibrary-CKATe31P.js} +1 -1
  43. package/client/dist/assets/{useMangaPopup-D57OVGUr.js → useMangaPopup-C75QuYgY.js} +1 -1
  44. package/client/dist/assets/{useProviders-mpQb_dix.js → useProviders-CMtvZbEi.js} +1 -1
  45. package/client/dist/assets/{useTv-DGflCsSI.js → useTv-DUX4zYMr.js} +1 -1
  46. package/client/dist/assets/{useTvLibrary-BqeSmyc4.js → useTvLibrary-By4Gt-R_.js} +1 -1
  47. package/client/dist/index.html +1 -1
  48. package/package.json +2 -2
  49. package/server/dist/app-auth.js +1 -157
  50. package/server/dist/app-hono.js +7 -557
  51. package/server/dist/config.js +1 -174
  52. package/server/dist/db/drizzle.js +1 -16
  53. package/server/dist/db/schema-anime.js +1 -61
  54. package/server/dist/db/schema-asmr.js +1 -13
  55. package/server/dist/db/schema-manga.js +1 -31
  56. package/server/dist/db/schema-tv.js +1 -18
  57. package/server/dist/db.js +1 -217
  58. package/server/dist/discord-gateway.js +1 -385
  59. package/server/dist/discord-rpc.js +1 -413
  60. package/server/dist/github-sync.js +1 -508
  61. package/server/dist/google.js +1 -741
  62. package/server/dist/hono/asmr.js +1 -10
  63. package/server/dist/hono/auth.js +3 -26
  64. package/server/dist/hono/music.js +1 -209
  65. package/server/dist/hono/proxy.js +36 -783
  66. package/server/dist/hono/tv.js +5 -200
  67. package/server/dist/hono/watchlist.js +2 -338
  68. package/server/dist/lib/anilist.js +26 -1458
  69. package/server/dist/lib/anischedule.js +1 -191
  70. package/server/dist/lib/insights.js +1 -185
  71. package/server/dist/lib/ipc.js +1 -23
  72. package/server/dist/lib/kitsu.js +1 -517
  73. package/server/dist/lib/mal-import.js +1 -291
  74. package/server/dist/lib/mal.js +1 -957
  75. package/server/dist/lib/migration.js +1 -310
  76. package/server/dist/lib/offline-db.js +4 -384
  77. package/server/dist/lib/potoken.js +1 -135
  78. package/server/dist/lib/recommendations.service.js +1 -216
  79. package/server/dist/lib/temp-ids.js +1 -3
  80. package/server/dist/lib/tmdb.js +1 -72
  81. package/server/dist/lib/tracker/anilist-tracker.js +8 -245
  82. package/server/dist/lib/tracker/manga-sync.service.js +1 -773
  83. package/server/dist/lib/tracker/sync-state.js +1 -21
  84. package/server/dist/lib/tracker/sync.service.js +1 -476
  85. package/server/dist/lib/translate.js +3 -79
  86. package/server/dist/lib/ump.js +1 -106
  87. package/server/dist/lib/ytmusic.js +1 -162
  88. package/server/dist/logger.js +1 -16
  89. package/server/dist/providers/manga/manga.types.js +0 -1
  90. package/server/dist/providers/provider.interface.js +0 -1
  91. package/server/dist/providers/remote-loader.js +2 -614
  92. package/server/dist/providers/remote-types.js +1 -159
  93. package/server/dist/providers/title-matching.js +1 -226
  94. package/server/dist/providers/tv.types.js +0 -1
  95. package/server/dist/rclone.js +2 -120
  96. package/server/dist/repositories/asmr.repository.js +11 -46
  97. package/server/dist/repositories/insights.repository.js +11 -25
  98. package/server/dist/repositories/library.repository.js +3 -94
  99. package/server/dist/repositories/mal-cache.repository.js +1 -52
  100. package/server/dist/repositories/manga.repository.js +14 -58
  101. package/server/dist/repositories/notifications.repository.js +6 -52
  102. package/server/dist/repositories/queue.repository.js +5 -58
  103. package/server/dist/repositories/settings.repository.js +2 -29
  104. package/server/dist/repositories/shows-meta.repository.js +3 -56
  105. package/server/dist/repositories/temp-show-ids.repository.js +3 -63
  106. package/server/dist/repositories/tv.repository.js +11 -54
  107. package/server/dist/repositories/watched-episodes.repository.js +6 -55
  108. package/server/dist/repositories/watchlist.repository.js +3 -54
  109. package/server/dist/scripts/backfill-episode-duration.js +1 -42
  110. package/server/dist/server.js +1 -310
  111. package/server/dist/shipped-defaults.js +1 -6
  112. package/server/dist/sync-payload.js +1 -91
  113. package/server/dist/sync.js +3 -647
  114. package/server/dist/trpc/context.js +1 -7
  115. package/server/dist/trpc/errors.js +1 -15
  116. package/server/dist/trpc/index.js +1 -18
  117. package/server/dist/trpc/router.js +1 -49
  118. package/server/dist/trpc/routers/asmr-library.js +1 -112
  119. package/server/dist/trpc/routers/asmr-progress.js +1 -121
  120. package/server/dist/trpc/routers/asmr.js +1 -87
  121. package/server/dist/trpc/routers/auth.js +1 -194
  122. package/server/dist/trpc/routers/continue-watching.js +2 -58
  123. package/server/dist/trpc/routers/data.js +1 -1026
  124. package/server/dist/trpc/routers/discord.js +1 -285
  125. package/server/dist/trpc/routers/discovery.js +1 -11
  126. package/server/dist/trpc/routers/insights.js +1 -14
  127. package/server/dist/trpc/routers/manga-library.js +1 -263
  128. package/server/dist/trpc/routers/manga-progress.js +1 -169
  129. package/server/dist/trpc/routers/manga.js +1 -201
  130. package/server/dist/trpc/routers/music.js +1 -655
  131. package/server/dist/trpc/routers/notifications.js +1 -80
  132. package/server/dist/trpc/routers/progress.js +1 -109
  133. package/server/dist/trpc/routers/queue.js +1 -93
  134. package/server/dist/trpc/routers/radio.js +1 -145
  135. package/server/dist/trpc/routers/settings.js +1 -96
  136. package/server/dist/trpc/routers/tracker.js +1 -213
  137. package/server/dist/trpc/routers/tv-library.js +1 -135
  138. package/server/dist/trpc/routers/tv-progress.js +1 -159
  139. package/server/dist/trpc/routers/tv.js +1 -551
  140. package/server/dist/trpc/routers/watchlist.js +2 -549
  141. package/server/dist/trpc/validation.js +1 -258
  142. package/server/dist/utils/cache.utils.js +1 -25
  143. package/server/dist/utils/cookie.utils.js +1 -13
  144. package/server/dist/utils/db-utils.js +5 -17
  145. package/server/dist/utils/env.utils.js +5 -77
  146. package/server/dist/utils/http.utils.js +1 -82
  147. package/server/dist/utils/request-context.js +1 -2
  148. package/server/dist/utils/security.utils.js +1 -76
  149. package/server/package.json +3 -2
@@ -1,174 +1 @@
1
- import fs from 'fs';
2
- import os from 'os';
3
- import path from 'path';
4
- import dotenv from 'dotenv';
5
- import { SHIPPED_DEFAULTS } from './shipped-defaults.js';
6
- export const SERVER_ROOT = path.resolve(import.meta.dirname, '..');
7
- const PACKAGE_ROOT = path.resolve(SERVER_ROOT, '..');
8
- function resolveDataRoot() {
9
- if (process.platform === 'win32' && process.env.APPDATA) {
10
- return path.join(process.env.APPDATA, 'dango');
11
- }
12
- if (process.platform === 'darwin') {
13
- return path.join(os.homedir(), 'Library', 'Application Support', 'dango');
14
- }
15
- if (process.env.XDG_DATA_HOME) {
16
- return path.join(process.env.XDG_DATA_HOME, 'dango');
17
- }
18
- return path.join(os.homedir(), '.local', 'share', 'dango');
19
- }
20
- function moveFileIfNeeded(sourcePath, destinationPath) {
21
- if (!fs.existsSync(sourcePath) || fs.existsSync(destinationPath)) {
22
- return;
23
- }
24
- try {
25
- fs.renameSync(sourcePath, destinationPath);
26
- }
27
- catch {
28
- fs.copyFileSync(sourcePath, destinationPath);
29
- fs.unlinkSync(sourcePath);
30
- }
31
- }
32
- function migrateLegacyData(packageServerRoot, dataRoot) {
33
- const legacyFiles = [
34
- '.env',
35
- 'google_tokens.json',
36
- 'sync_manifest.json',
37
- 'sync_manifest.dev.json',
38
- 'anime.db',
39
- 'anime.db-shm',
40
- 'anime.db-wal',
41
- 'anime.dev.db',
42
- 'anime.dev.db-shm',
43
- 'anime.dev.db-wal',
44
- ];
45
- fs.mkdirSync(dataRoot, { recursive: true });
46
- for (const filename of legacyFiles) {
47
- moveFileIfNeeded(path.join(packageServerRoot, filename), path.join(dataRoot, filename));
48
- }
49
- for (const filename of [
50
- 'manga.db',
51
- 'manga.db-shm',
52
- 'manga.db-wal',
53
- 'manga.dev.db',
54
- 'manga.dev.db-shm',
55
- 'manga.dev.db-wal',
56
- 'manga.sync_manifest.json',
57
- 'manga.sync_manifest.dev.json',
58
- 'tv.db',
59
- 'tv.db-shm',
60
- 'tv.db-wal',
61
- 'tv.dev.db',
62
- 'tv.dev.db-shm',
63
- 'tv.dev.db-wal',
64
- 'tv.sync_manifest.json',
65
- 'tv.sync_manifest.dev.json',
66
- 'asmr.db',
67
- 'asmr.db-shm',
68
- 'asmr.db-wal',
69
- 'asmr.dev.db',
70
- 'asmr.dev.db-shm',
71
- 'asmr.dev.db-wal',
72
- 'asmr.sync_manifest.json',
73
- 'asmr.sync_manifest.dev.json',
74
- ]) {
75
- moveFileIfNeeded(path.join(packageServerRoot, filename), path.join(dataRoot, filename));
76
- }
77
- }
78
- function resolveLegacyDataRoot() {
79
- if (process.platform === 'win32' && process.env.APPDATA) {
80
- return path.join(process.env.APPDATA, 'ani-web');
81
- }
82
- if (process.platform === 'darwin') {
83
- return path.join(os.homedir(), 'Library', 'Application Support', 'ani-web');
84
- }
85
- if (process.env.XDG_DATA_HOME) {
86
- return path.join(process.env.XDG_DATA_HOME, 'ani-web');
87
- }
88
- return path.join(os.homedir(), '.local', 'share', 'ani-web');
89
- }
90
- function migrateFromAniWeb(dataRoot) {
91
- const legacyRoot = resolveLegacyDataRoot();
92
- if (legacyRoot === dataRoot)
93
- return;
94
- if (!fs.existsSync(legacyRoot))
95
- return;
96
- const filesToMigrate = [
97
- '.env',
98
- 'google_tokens.json',
99
- 'sync_manifest.json',
100
- 'sync_manifest.dev.json',
101
- 'anime.db',
102
- 'anime.db-shm',
103
- 'anime.db-wal',
104
- 'anime.dev.db',
105
- 'anime.dev.db-shm',
106
- 'anime.dev.db-wal',
107
- ];
108
- fs.mkdirSync(dataRoot, { recursive: true });
109
- for (const filename of filesToMigrate) {
110
- moveFileIfNeeded(path.join(legacyRoot, filename), path.join(dataRoot, filename));
111
- }
112
- }
113
- const DATA_ROOT = resolveDataRoot();
114
- const ENV_PATH = path.join(DATA_ROOT, '.env');
115
- migrateLegacyData(SERVER_ROOT, DATA_ROOT);
116
- migrateFromAniWeb(DATA_ROOT);
117
- dotenv.config({ path: path.join(SERVER_ROOT, '.env') });
118
- dotenv.config({ path: ENV_PATH, override: true });
119
- const IS_DEV = process.argv.includes('--dev');
120
- const PORT = Number(process.env.PORT) || 3000;
121
- const DEV_PORT = Number(process.env.DEV_PORT) || 5173;
122
- const HOST = process.env.HOST || '0.0.0.0';
123
- const GOOGLE_REDIRECT_URI = IS_DEV
124
- ? `http://localhost:${DEV_PORT}/api/auth/google/callback`
125
- : `http://localhost:${PORT}/api/auth/google/callback`;
126
- export const CONFIG = {
127
- ROOT: DATA_ROOT,
128
- SERVER_ROOT,
129
- PACKAGE_ROOT,
130
- ENV_PATH,
131
- TOKEN_PATH: path.join(DATA_ROOT, 'google_tokens.json'),
132
- LOCAL_MANIFEST_PATH: path.join(DATA_ROOT, IS_DEV ? 'sync_manifest.dev.json' : 'sync_manifest.json'),
133
- MANGA_LOCAL_MANIFEST_PATH: path.join(DATA_ROOT, IS_DEV ? 'manga.sync_manifest.dev.json' : 'manga.sync_manifest.json'),
134
- TV_LOCAL_MANIFEST_PATH: path.join(DATA_ROOT, IS_DEV ? 'tv.sync_manifest.dev.json' : 'tv.sync_manifest.json'),
135
- ASMR_LOCAL_MANIFEST_PATH: path.join(DATA_ROOT, IS_DEV ? 'asmr.sync_manifest.dev.json' : 'asmr.sync_manifest.json'),
136
- DB_NAME_PROD: 'anime.db',
137
- DB_NAME_DEV: 'anime.dev.db',
138
- MANGA_DB_NAME_PROD: 'manga.db',
139
- MANGA_DB_NAME_DEV: 'manga.dev.db',
140
- TV_DB_NAME_PROD: 'tv.db',
141
- TV_DB_NAME_DEV: 'tv.dev.db',
142
- ASMR_DB_NAME_PROD: 'asmr.db',
143
- ASMR_DB_NAME_DEV: 'asmr.dev.db',
144
- REMOTE_FOLDER_PROD: 'dango_db',
145
- REMOTE_FOLDER_DEV: 'dango_dev_db',
146
- MANIFEST_FILENAME: IS_DEV ? 'sync_manifest.dev.json' : 'sync_manifest.json',
147
- GOOGLE_SCOPES: [
148
- 'https://www.googleapis.com/auth/drive.appdata',
149
- 'https://www.googleapis.com/auth/drive.file',
150
- 'https://www.googleapis.com/auth/userinfo.email',
151
- ],
152
- GOOGLE_SYNC_FILENAME: IS_DEV ? 'sync.dev.json' : 'sync.json',
153
- MANGA_GOOGLE_SYNC_FILENAME: IS_DEV ? 'manga.sync.dev.json' : 'manga.sync.json',
154
- TV_GOOGLE_SYNC_FILENAME: IS_DEV ? 'tv.sync.dev.json' : 'tv.sync.json',
155
- ASMR_GOOGLE_SYNC_FILENAME: IS_DEV ? 'asmr.sync.dev.json' : 'asmr.sync.json',
156
- RCLONE_SYNC_FILENAME: IS_DEV ? 'sync.dev.json' : 'sync.json',
157
- MANGA_RCLONE_SYNC_FILENAME: IS_DEV ? 'manga.sync.dev.json' : 'manga.sync.json',
158
- TV_RCLONE_SYNC_FILENAME: IS_DEV ? 'tv.sync.dev.json' : 'tv.sync.json',
159
- ASMR_RCLONE_SYNC_FILENAME: IS_DEV ? 'asmr.sync.dev.json' : 'asmr.sync.json',
160
- IS_DEV,
161
- PORT,
162
- HOST,
163
- GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
164
- GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,
165
- GOOGLE_REDIRECT_URI: GOOGLE_REDIRECT_URI,
166
- GOOGLE_AUTH_WORKER_URL: process.env.GOOGLE_AUTH_WORKER_URL || SHIPPED_DEFAULTS.GOOGLE_AUTH_WORKER_URL || '',
167
- RCLONE_REMOTE: process.env.RCLONE_REMOTE,
168
- SYNC_PROVIDER: process.env.SYNC_PROVIDER,
169
- DISCORD_CLIENT_ID: process.env.DISCORD_CLIENT_ID || SHIPPED_DEFAULTS.DISCORD_CLIENT_ID || undefined,
170
- APP_PASSWORD_HASH: process.env.APP_PASSWORD_HASH || '',
171
- PROVIDER_REPO_URL: process.env.PROVIDER_REPO_URL || SHIPPED_DEFAULTS.PROVIDER_REPO_URL || '',
172
- PROVIDER_ENABLED: process.env.PROVIDER_ENABLED || '',
173
- PROVIDER_REPO_REFRESH_MS: parseInt(process.env.PROVIDER_REPO_REFRESH_MS || '', 10) || 21600000,
174
- };
1
+ import i from"fs";import r from"os";import n from"path";import d from"dotenv";import{SHIPPED_DEFAULTS as c}from"./shipped-defaults.js";const E=n.resolve(import.meta.dirname,".."),A=n.resolve(E,"..");function R(){return process.platform==="win32"&&process.env.APPDATA?n.join(process.env.APPDATA,"dango"):process.platform==="darwin"?n.join(r.homedir(),"Library","Application Support","dango"):process.env.XDG_DATA_HOME?n.join(process.env.XDG_DATA_HOME,"dango"):n.join(r.homedir(),".local","share","dango")}function m(e,o){if(!(!i.existsSync(e)||i.existsSync(o)))try{i.renameSync(e,o)}catch{i.copyFileSync(e,o),i.unlinkSync(e)}}function D(e,o){const t=[".env","google_tokens.json","sync_manifest.json","sync_manifest.dev.json","anime.db","anime.db-shm","anime.db-wal","anime.dev.db","anime.dev.db-shm","anime.dev.db-wal"];i.mkdirSync(o,{recursive:!0});for(const a of t)m(n.join(e,a),n.join(o,a));for(const a of["manga.db","manga.db-shm","manga.db-wal","manga.dev.db","manga.dev.db-shm","manga.dev.db-wal","manga.sync_manifest.json","manga.sync_manifest.dev.json","tv.db","tv.db-shm","tv.db-wal","tv.dev.db","tv.dev.db-shm","tv.dev.db-wal","tv.sync_manifest.json","tv.sync_manifest.dev.json","asmr.db","asmr.db-shm","asmr.db-wal","asmr.dev.db","asmr.dev.db-shm","asmr.dev.db-wal","asmr.sync_manifest.json","asmr.sync_manifest.dev.json"])m(n.join(e,a),n.join(o,a))}function p(){return process.platform==="win32"&&process.env.APPDATA?n.join(process.env.APPDATA,"ani-web"):process.platform==="darwin"?n.join(r.homedir(),"Library","Application Support","ani-web"):process.env.XDG_DATA_HOME?n.join(process.env.XDG_DATA_HOME,"ani-web"):n.join(r.homedir(),".local","share","ani-web")}function f(e){const o=p();if(o===e||!i.existsSync(o))return;const t=[".env","google_tokens.json","sync_manifest.json","sync_manifest.dev.json","anime.db","anime.db-shm","anime.db-wal","anime.dev.db","anime.dev.db-shm","anime.dev.db-wal"];i.mkdirSync(e,{recursive:!0});for(const a of t)m(n.join(o,a),n.join(e,a))}const _=R(),O=n.join(_,".env");D(E,_),f(_),d.config({path:n.join(E,".env")}),d.config({path:O,override:!0});const s=process.argv.includes("--dev"),v=Number(process.env.PORT)||3e3,j=Number(process.env.DEV_PORT)||5173,L=process.env.HOST||"0.0.0.0",N=s?`http://localhost:${j}/api/auth/google/callback`:`http://localhost:${v}/api/auth/google/callback`,S={ROOT:_,SERVER_ROOT:E,PACKAGE_ROOT:A,ENV_PATH:O,TOKEN_PATH:n.join(_,"google_tokens.json"),LOCAL_MANIFEST_PATH:n.join(_,s?"sync_manifest.dev.json":"sync_manifest.json"),MANGA_LOCAL_MANIFEST_PATH:n.join(_,s?"manga.sync_manifest.dev.json":"manga.sync_manifest.json"),TV_LOCAL_MANIFEST_PATH:n.join(_,s?"tv.sync_manifest.dev.json":"tv.sync_manifest.json"),ASMR_LOCAL_MANIFEST_PATH:n.join(_,s?"asmr.sync_manifest.dev.json":"asmr.sync_manifest.json"),DB_NAME_PROD:"anime.db",DB_NAME_DEV:"anime.dev.db",MANGA_DB_NAME_PROD:"manga.db",MANGA_DB_NAME_DEV:"manga.dev.db",TV_DB_NAME_PROD:"tv.db",TV_DB_NAME_DEV:"tv.dev.db",ASMR_DB_NAME_PROD:"asmr.db",ASMR_DB_NAME_DEV:"asmr.dev.db",REMOTE_FOLDER_PROD:"dango_db",REMOTE_FOLDER_DEV:"dango_dev_db",MANIFEST_FILENAME:s?"sync_manifest.dev.json":"sync_manifest.json",GOOGLE_SCOPES:["https://www.googleapis.com/auth/drive.appdata","https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/userinfo.email"],GOOGLE_SYNC_FILENAME:s?"sync.dev.json":"sync.json",MANGA_GOOGLE_SYNC_FILENAME:s?"manga.sync.dev.json":"manga.sync.json",TV_GOOGLE_SYNC_FILENAME:s?"tv.sync.dev.json":"tv.sync.json",ASMR_GOOGLE_SYNC_FILENAME:s?"asmr.sync.dev.json":"asmr.sync.json",RCLONE_SYNC_FILENAME:s?"sync.dev.json":"sync.json",MANGA_RCLONE_SYNC_FILENAME:s?"manga.sync.dev.json":"manga.sync.json",TV_RCLONE_SYNC_FILENAME:s?"tv.sync.dev.json":"tv.sync.json",ASMR_RCLONE_SYNC_FILENAME:s?"asmr.sync.dev.json":"asmr.sync.json",IS_DEV:s,PORT:v,HOST:L,GOOGLE_CLIENT_ID:process.env.GOOGLE_CLIENT_ID,GOOGLE_CLIENT_SECRET:process.env.GOOGLE_CLIENT_SECRET,GOOGLE_REDIRECT_URI:N,GOOGLE_AUTH_WORKER_URL:process.env.GOOGLE_AUTH_WORKER_URL||c.GOOGLE_AUTH_WORKER_URL||"",RCLONE_REMOTE:process.env.RCLONE_REMOTE,SYNC_PROVIDER:process.env.SYNC_PROVIDER,DISCORD_CLIENT_ID:process.env.DISCORD_CLIENT_ID||c.DISCORD_CLIENT_ID||void 0,APP_PASSWORD_HASH:process.env.APP_PASSWORD_HASH||"",PROVIDER_REPO_URL:process.env.PROVIDER_REPO_URL||c.PROVIDER_REPO_URL||"",PROVIDER_ENABLED:process.env.PROVIDER_ENABLED||"",PROVIDER_REPO_REFRESH_MS:parseInt(process.env.PROVIDER_REPO_REFRESH_MS||"",10)||216e5};export{S as CONFIG,E as SERVER_ROOT};
@@ -1,16 +1 @@
1
- import { drizzle } from 'drizzle-orm/node-sqlite';
2
- export function createDrizzle(db) {
3
- return drizzle({ client: db.getClient() });
4
- }
5
- const cache = new WeakMap();
6
- export function getDrizzle(db) {
7
- let d = cache.get(db);
8
- if (!d) {
9
- d = createDrizzle(db);
10
- cache.set(db, d);
11
- }
12
- return d;
13
- }
14
- export async function runTx(db, fn) {
15
- await db.transact(fn);
16
- }
1
+ import{drizzle as r}from"drizzle-orm/node-sqlite";function p(e){return r({client:e.getClient()})}const a=new WeakMap;function i(e){let t=a.get(e);return t||(t=p(e),a.set(e,t)),t}async function o(e,t){await e.transact(t)}export{p as createDrizzle,i as getDrizzle,o as runTx};
@@ -1,61 +1 @@
1
- import { sql } from 'drizzle-orm';
2
- import { integer, primaryKey, real, sqliteTable, text } from 'drizzle-orm/sqlite-core';
3
- export const watchedEpisodes = sqliteTable('watched_episodes', {
4
- showId: text('showId').notNull(),
5
- episodeNumber: text('episodeNumber').notNull(),
6
- watchedAt: text('watchedAt'),
7
- currentTime: real('currentTime'),
8
- duration: real('duration'),
9
- }, (t) => [primaryKey({ columns: [t.showId, t.episodeNumber] })]);
10
- export const watchlist = sqliteTable('watchlist', {
11
- id: text('id').notNull(),
12
- name: text('name'),
13
- thumbnail: text('thumbnail'),
14
- status: text('status'),
15
- nativeName: text('nativeName'),
16
- englishName: text('englishName'),
17
- type: text('type'),
18
- }, (t) => [primaryKey({ columns: [t.id] })]);
19
- export const showsMeta = sqliteTable('shows_meta', {
20
- id: text('id').notNull(),
21
- name: text('name'),
22
- thumbnail: text('thumbnail'),
23
- nativeName: text('nativeName'),
24
- englishName: text('englishName'),
25
- episodeCount: integer('episodeCount'),
26
- status: text('status'),
27
- genres: text('genres'),
28
- popularityScore: integer('popularityScore'),
29
- type: text('type'),
30
- anilistId: integer('anilistId'),
31
- isAdult: integer('isAdult'),
32
- episodeDuration: integer('episodeDuration'),
33
- }, (t) => [primaryKey({ columns: [t.id] })]);
34
- export const settings = sqliteTable('settings', {
35
- key: text('key').notNull(),
36
- value: text('value'),
37
- }, (t) => [primaryKey({ columns: [t.key] })]);
38
- export const queue = sqliteTable('queue', {
39
- id: integer('id'),
40
- showId: text('showId').notNull(),
41
- episodeNumber: text('episodeNumber').notNull(),
42
- queueOrder: integer('queue_order').notNull(),
43
- });
44
- export const discoveredNotifications = sqliteTable('discovered_notifications', {
45
- showId: text('showId').notNull(),
46
- episodeNumber: text('episodeNumber').notNull(),
47
- discoveredAt: text('discoveredAt').default(sql `CURRENT_TIMESTAMP`),
48
- }, (t) => [primaryKey({ columns: [t.showId, t.episodeNumber] })]);
49
- export const dismissedNotifications = sqliteTable('dismissed_notifications', {
50
- showId: text('showId').notNull(),
51
- episodeNumber: text('episodeNumber').notNull(),
52
- dismissedAt: text('dismissedAt').default(sql `CURRENT_TIMESTAMP`),
53
- }, (t) => [primaryKey({ columns: [t.showId, t.episodeNumber] })]);
54
- export const tempShowIds = sqliteTable('temp_show_ids', {
55
- id: text('id').notNull(),
56
- provider: text('provider').notNull(),
57
- nativeId: text('nativeId').notNull(),
58
- title: text('title').notNull(),
59
- thumbnail: text('thumbnail'),
60
- createdAt: integer('createdAt').notNull(),
61
- }, (t) => [primaryKey({ columns: [t.id] })]);
1
+ import{sql as d}from"drizzle-orm";import{integer as o,primaryKey as i,real as n,sqliteTable as s,text as e}from"drizzle-orm/sqlite-core";const a=s("watched_episodes",{showId:e("showId").notNull(),episodeNumber:e("episodeNumber").notNull(),watchedAt:e("watchedAt"),currentTime:n("currentTime"),duration:n("duration")},t=>[i({columns:[t.showId,t.episodeNumber]})]),r=s("watchlist",{id:e("id").notNull(),name:e("name"),thumbnail:e("thumbnail"),status:e("status"),nativeName:e("nativeName"),englishName:e("englishName"),type:e("type")},t=>[i({columns:[t.id]})]),m=s("shows_meta",{id:e("id").notNull(),name:e("name"),thumbnail:e("thumbnail"),nativeName:e("nativeName"),englishName:e("englishName"),episodeCount:o("episodeCount"),status:e("status"),genres:e("genres"),popularityScore:o("popularityScore"),type:e("type"),anilistId:o("anilistId"),isAdult:o("isAdult"),episodeDuration:o("episodeDuration")},t=>[i({columns:[t.id]})]),p=s("settings",{key:e("key").notNull(),value:e("value")},t=>[i({columns:[t.key]})]),N=s("queue",{id:o("id"),showId:e("showId").notNull(),episodeNumber:e("episodeNumber").notNull(),queueOrder:o("queue_order").notNull()}),c=s("discovered_notifications",{showId:e("showId").notNull(),episodeNumber:e("episodeNumber").notNull(),discoveredAt:e("discoveredAt").default(d`CURRENT_TIMESTAMP`)},t=>[i({columns:[t.showId,t.episodeNumber]})]),h=s("dismissed_notifications",{showId:e("showId").notNull(),episodeNumber:e("episodeNumber").notNull(),dismissedAt:e("dismissedAt").default(d`CURRENT_TIMESTAMP`)},t=>[i({columns:[t.showId,t.episodeNumber]})]),w=s("temp_show_ids",{id:e("id").notNull(),provider:e("provider").notNull(),nativeId:e("nativeId").notNull(),title:e("title").notNull(),thumbnail:e("thumbnail"),createdAt:o("createdAt").notNull()},t=>[i({columns:[t.id]})]);export{c as discoveredNotifications,h as dismissedNotifications,N as queue,p as settings,m as showsMeta,w as tempShowIds,a as watchedEpisodes,r as watchlist};
@@ -1,13 +1 @@
1
- import { integer, primaryKey, real, sqliteTable, text } from 'drizzle-orm/sqlite-core';
2
- export const asmrProgress = sqliteTable('asmr_progress', {
3
- workId: text('workId').notNull(),
4
- trackIndex: integer('trackIndex').notNull(),
5
- trackLabel: text('trackLabel'),
6
- currentTime: real('currentTime'),
7
- duration: real('duration'),
8
- updatedAt: integer('updatedAt'),
9
- title: text('title'),
10
- thumbnail: text('thumbnail'),
11
- rjCode: text('rjCode'),
12
- isAdult: integer('isAdult'),
13
- }, (t) => [primaryKey({ columns: [t.workId, t.trackIndex] })]);
1
+ import{integer as t,primaryKey as d,real as a,sqliteTable as l,text as r}from"drizzle-orm/sqlite-core";const i=l("asmr_progress",{workId:r("workId").notNull(),trackIndex:t("trackIndex").notNull(),trackLabel:r("trackLabel"),currentTime:a("currentTime"),duration:a("duration"),updatedAt:t("updatedAt"),title:r("title"),thumbnail:r("thumbnail"),rjCode:r("rjCode"),isAdult:t("isAdult")},e=>[d({columns:[e.workId,e.trackIndex]})]);export{i as asmrProgress};
@@ -1,31 +1 @@
1
- import { integer, primaryKey, sqliteTable, text } from 'drizzle-orm/sqlite-core';
2
- export const mangaLibrary = sqliteTable('manga_library', {
3
- id: text('id').notNull(),
4
- provider: text('provider').notNull(),
5
- mangaId: text('mangaId').notNull(),
6
- title: text('title'),
7
- cover: text('cover'),
8
- status: text('status'),
9
- author: text('author'),
10
- altTitle: text('altTitle'),
11
- contentRating: text('contentRating'),
12
- lastChapterId: text('lastChapterId'),
13
- lastChapterNumber: text('lastChapterNumber'),
14
- lastPage: integer('lastPage'),
15
- updatedAt: integer('updatedAt'),
16
- anilistId: integer('anilistId'),
17
- anilistIdSource: text('anilistIdSource'),
18
- }, (t) => [primaryKey({ columns: [t.id] })]);
19
- export const mangaProgress = sqliteTable('manga_progress', {
20
- mangaId: text('mangaId').notNull(),
21
- chapterId: text('chapterId').notNull(),
22
- chapterNumber: text('chapterNumber'),
23
- page: integer('page'),
24
- pageCount: integer('pageCount'),
25
- updatedAt: integer('updatedAt'),
26
- title: text('title'),
27
- cover: text('cover'),
28
- provider: text('provider'),
29
- altTitle: text('altTitle'),
30
- contentRating: text('contentRating'),
31
- }, (t) => [primaryKey({ columns: [t.mangaId, t.chapterId] })]);
1
+ import{integer as a,primaryKey as r,sqliteTable as l,text as t}from"drizzle-orm/sqlite-core";const i=l("manga_library",{id:t("id").notNull(),provider:t("provider").notNull(),mangaId:t("mangaId").notNull(),title:t("title"),cover:t("cover"),status:t("status"),author:t("author"),altTitle:t("altTitle"),contentRating:t("contentRating"),lastChapterId:t("lastChapterId"),lastChapterNumber:t("lastChapterNumber"),lastPage:a("lastPage"),updatedAt:a("updatedAt"),anilistId:a("anilistId"),anilistIdSource:t("anilistIdSource")},e=>[r({columns:[e.id]})]),o=l("manga_progress",{mangaId:t("mangaId").notNull(),chapterId:t("chapterId").notNull(),chapterNumber:t("chapterNumber"),page:a("page"),pageCount:a("pageCount"),updatedAt:a("updatedAt"),title:t("title"),cover:t("cover"),provider:t("provider"),altTitle:t("altTitle"),contentRating:t("contentRating")},e=>[r({columns:[e.mangaId,e.chapterId]})]);export{i as mangaLibrary,o as mangaProgress};
@@ -1,18 +1 @@
1
- import { integer, primaryKey, real, sqliteTable, text } from 'drizzle-orm/sqlite-core';
2
- export const tvProgress = sqliteTable('tv_progress', {
3
- mediaId: text('mediaId').notNull(),
4
- season: integer('season').notNull(),
5
- episode: integer('episode').notNull(),
6
- currentTime: real('currentTime'),
7
- duration: real('duration'),
8
- updatedAt: integer('updatedAt'),
9
- title: text('title'),
10
- poster: text('poster'),
11
- backdrop: text('backdrop'),
12
- year: text('year'),
13
- overview: text('overview'),
14
- tmdbId: integer('tmdbId'),
15
- mediaType: text('mediaType'),
16
- adult: integer('adult'),
17
- completed: integer('completed'),
18
- }, (t) => [primaryKey({ columns: [t.mediaId, t.season, t.episode] })]);
1
+ import{integer as t,primaryKey as r,real as o,sqliteTable as a,text as e}from"drizzle-orm/sqlite-core";const s=a("tv_progress",{mediaId:e("mediaId").notNull(),season:t("season").notNull(),episode:t("episode").notNull(),currentTime:o("currentTime"),duration:o("duration"),updatedAt:t("updatedAt"),title:e("title"),poster:e("poster"),backdrop:e("backdrop"),year:e("year"),overview:e("overview"),tmdbId:t("tmdbId"),mediaType:e("mediaType"),adult:t("adult"),completed:t("completed")},d=>[r({columns:[d.mediaId,d.season,d.episode]})]);export{s as tvProgress};
package/server/dist/db.js CHANGED
@@ -1,217 +1 @@
1
- import { DatabaseSync } from 'node:sqlite';
2
- import { AsyncLocalStorage } from 'node:async_hooks';
3
- import fs from 'fs';
4
- import path from 'path';
5
- import logger from './logger.js';
6
- const txOwner = new AsyncLocalStorage();
7
- export class DatabaseWrapper {
8
- db;
9
- isClosed = false;
10
- statementCache = new Map();
11
- txDepth = 0;
12
- txQueue = Promise.resolve();
13
- constructor(_dbPath, db) {
14
- this.db = db;
15
- }
16
- static async create(dbPath) {
17
- try {
18
- const dir = path.dirname(dbPath);
19
- if (!fs.existsSync(dir)) {
20
- fs.mkdirSync(dir, { recursive: true });
21
- }
22
- const db = new DatabaseSync(dbPath);
23
- return new DatabaseWrapper(dbPath, db);
24
- }
25
- catch (e) {
26
- logger.error({ err: e }, `Failed to initialize database at ${dbPath}`);
27
- throw e;
28
- }
29
- }
30
- getClient() {
31
- return this.db;
32
- }
33
- configure(option, value) {
34
- if (option === 'busyTimeout') {
35
- this.db.exec(`PRAGMA busy_timeout = ${value}`);
36
- }
37
- }
38
- serialize(cb) {
39
- const outer = this.txDepth === 0;
40
- const level = this.txDepth;
41
- this.run(outer ? 'BEGIN IMMEDIATE' : `SAVEPOINT dango_sp_${level}`);
42
- this.txDepth = level + 1;
43
- try {
44
- txOwner.run(this, cb);
45
- }
46
- catch (e) {
47
- this.txDepth = level;
48
- try {
49
- this.run(outer ? 'ROLLBACK' : `ROLLBACK TO SAVEPOINT dango_sp_${level}`);
50
- }
51
- catch {
52
- // ignore
53
- }
54
- throw e;
55
- }
56
- this.txDepth = level;
57
- this.run(outer ? 'COMMIT' : `RELEASE SAVEPOINT dango_sp_${level}`);
58
- }
59
- acquireTxQueue() {
60
- const prev = this.txQueue;
61
- let release;
62
- const current = new Promise((res) => {
63
- release = res;
64
- });
65
- this.txQueue = prev.then(() => current);
66
- return prev.then(() => release);
67
- }
68
- async transact(fn) {
69
- if (txOwner.getStore() === this) {
70
- const level = this.txDepth;
71
- this.run(`SAVEPOINT dango_sp_${level}`);
72
- this.txDepth = level + 1;
73
- try {
74
- await fn(this);
75
- }
76
- catch (e) {
77
- this.txDepth = level;
78
- try {
79
- this.run(`ROLLBACK TO SAVEPOINT dango_sp_${level}`);
80
- }
81
- catch {
82
- // ignore
83
- }
84
- throw e;
85
- }
86
- this.txDepth = level;
87
- this.run(`RELEASE SAVEPOINT dango_sp_${level}`);
88
- return;
89
- }
90
- const release = await this.acquireTxQueue();
91
- try {
92
- await txOwner.run(this, async () => {
93
- this.run('BEGIN IMMEDIATE');
94
- this.txDepth = 1;
95
- try {
96
- await fn(this);
97
- }
98
- catch (e) {
99
- this.txDepth = 0;
100
- try {
101
- this.run('ROLLBACK');
102
- }
103
- catch {
104
- // ignore
105
- }
106
- throw e;
107
- }
108
- this.txDepth = 0;
109
- this.run('COMMIT');
110
- });
111
- }
112
- finally {
113
- release();
114
- }
115
- }
116
- close(cb) {
117
- if (this.isClosed) {
118
- if (cb)
119
- cb(null);
120
- return;
121
- }
122
- try {
123
- this.isClosed = true;
124
- this.statementCache.clear();
125
- this.db.close();
126
- if (cb)
127
- cb(null);
128
- }
129
- catch (e) {
130
- logger.error({ err: e }, 'Error during database close');
131
- if (cb)
132
- cb(e);
133
- }
134
- }
135
- isClosedCheck() {
136
- return this.isClosed;
137
- }
138
- getPreparedStatement(query) {
139
- let stmt = this.statementCache.get(query);
140
- if (!stmt) {
141
- if (this.statementCache.size > 100) {
142
- this.statementCache.clear();
143
- }
144
- stmt = this.db.prepare(query);
145
- this.statementCache.set(query, stmt);
146
- }
147
- return stmt;
148
- }
149
- run(query, params = []) {
150
- if (this.isClosed) {
151
- throw new Error('Database is closed');
152
- }
153
- const stmt = this.getPreparedStatement(query);
154
- if (params.length > 0) {
155
- stmt.run(...params);
156
- }
157
- else {
158
- stmt.run();
159
- }
160
- }
161
- get(query, params = []) {
162
- if (this.isClosed) {
163
- throw new Error('Database is closed');
164
- }
165
- const stmt = this.getPreparedStatement(query);
166
- if (params.length > 0) {
167
- return stmt.get(...params);
168
- }
169
- return stmt.get();
170
- }
171
- all(query, params = []) {
172
- if (this.isClosed) {
173
- throw new Error('Database is closed');
174
- }
175
- const stmt = this.getPreparedStatement(query);
176
- if (params.length > 0) {
177
- return stmt.all(...params);
178
- }
179
- return stmt.all();
180
- }
181
- prepare(query) {
182
- const stmt = this.getPreparedStatement(query);
183
- return {
184
- run: (...args) => {
185
- stmt.run(...args);
186
- },
187
- all: () => {
188
- return stmt.all();
189
- },
190
- get: () => {
191
- return stmt.get();
192
- },
193
- finalize: () => { },
194
- };
195
- }
196
- backup(backupPath) {
197
- try {
198
- if (fs.existsSync(backupPath)) {
199
- fs.rmSync(backupPath, { force: true });
200
- }
201
- this.db.exec(`VACUUM INTO '${backupPath}'`);
202
- }
203
- catch (e) {
204
- logger.error({ err: e, backupPath }, 'Database backup failed via VACUUM INTO');
205
- throw e;
206
- }
207
- }
208
- checkpoint() {
209
- try {
210
- this.db.exec('PRAGMA wal_checkpoint(TRUNCATE)');
211
- }
212
- catch (e) {
213
- logger.error({ err: e }, 'Database WAL checkpoint failed');
214
- throw e;
215
- }
216
- }
217
- }
1
+ import{DatabaseSync as h}from"node:sqlite";import{AsyncLocalStorage as c}from"node:async_hooks";import s from"fs";import l from"path";import n from"./logger.js";const a=new c;class o{db;isClosed=!1;statementCache=new Map;txDepth=0;txQueue=Promise.resolve();constructor(t,e){this.db=e}static async create(t){try{const e=l.dirname(t);s.existsSync(e)||s.mkdirSync(e,{recursive:!0});const r=new h(t);return new o(t,r)}catch(e){throw n.error({err:e},`Failed to initialize database at ${t}`),e}}getClient(){return this.db}configure(t,e){t==="busyTimeout"&&this.db.exec(`PRAGMA busy_timeout = ${e}`)}serialize(t){const e=this.txDepth===0,r=this.txDepth;this.run(e?"BEGIN IMMEDIATE":`SAVEPOINT dango_sp_${r}`),this.txDepth=r+1;try{a.run(this,t)}catch(i){this.txDepth=r;try{this.run(e?"ROLLBACK":`ROLLBACK TO SAVEPOINT dango_sp_${r}`)}catch{}throw i}this.txDepth=r,this.run(e?"COMMIT":`RELEASE SAVEPOINT dango_sp_${r}`)}acquireTxQueue(){const t=this.txQueue;let e;const r=new Promise(i=>{e=i});return this.txQueue=t.then(()=>r),t.then(()=>e)}async transact(t){if(a.getStore()===this){const r=this.txDepth;this.run(`SAVEPOINT dango_sp_${r}`),this.txDepth=r+1;try{await t(this)}catch(i){this.txDepth=r;try{this.run(`ROLLBACK TO SAVEPOINT dango_sp_${r}`)}catch{}throw i}this.txDepth=r,this.run(`RELEASE SAVEPOINT dango_sp_${r}`);return}const e=await this.acquireTxQueue();try{await a.run(this,async()=>{this.run("BEGIN IMMEDIATE"),this.txDepth=1;try{await t(this)}catch(r){this.txDepth=0;try{this.run("ROLLBACK")}catch{}throw r}this.txDepth=0,this.run("COMMIT")})}finally{e()}}close(t){if(this.isClosed){t&&t(null);return}try{this.isClosed=!0,this.statementCache.clear(),this.db.close(),t&&t(null)}catch(e){n.error({err:e},"Error during database close"),t&&t(e)}}isClosedCheck(){return this.isClosed}getPreparedStatement(t){let e=this.statementCache.get(t);return e||(this.statementCache.size>100&&this.statementCache.clear(),e=this.db.prepare(t),this.statementCache.set(t,e)),e}run(t,e=[]){if(this.isClosed)throw new Error("Database is closed");const r=this.getPreparedStatement(t);e.length>0?r.run(...e):r.run()}get(t,e=[]){if(this.isClosed)throw new Error("Database is closed");const r=this.getPreparedStatement(t);return e.length>0?r.get(...e):r.get()}all(t,e=[]){if(this.isClosed)throw new Error("Database is closed");const r=this.getPreparedStatement(t);return e.length>0?r.all(...e):r.all()}prepare(t){const e=this.getPreparedStatement(t);return{run:(...r)=>{e.run(...r)},all:()=>e.all(),get:()=>e.get(),finalize:()=>{}}}backup(t){try{s.existsSync(t)&&s.rmSync(t,{force:!0}),this.db.exec(`VACUUM INTO '${t}'`)}catch(e){throw n.error({err:e,backupPath:t},"Database backup failed via VACUUM INTO"),e}}checkpoint(){try{this.db.exec("PRAGMA wal_checkpoint(TRUNCATE)")}catch(t){throw n.error({err:t},"Database WAL checkpoint failed"),t}}}export{o as DatabaseWrapper};