sa2kit 1.6.52 → 1.6.58

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 (195) hide show
  1. package/dist/AliyunOSSProvider-KSYW2IOG.js +15 -0
  2. package/dist/{AliyunOSSProvider-2FARPAQD.js.map → AliyunOSSProvider-KSYW2IOG.js.map} +1 -1
  3. package/dist/AliyunOSSProvider-TBK3G7YK.mjs +6 -0
  4. package/dist/{AliyunOSSProvider-UMVGVBDJ.mjs.map → AliyunOSSProvider-TBK3G7YK.mjs.map} +1 -1
  5. package/dist/LocalStorageProvider-2DGYRQAB.mjs +6 -0
  6. package/dist/{LocalStorageProvider-PYOHETJV.mjs.map → LocalStorageProvider-2DGYRQAB.mjs.map} +1 -1
  7. package/dist/LocalStorageProvider-SSRW3ZJW.js +15 -0
  8. package/dist/{LocalStorageProvider-JQF5WK5H.js.map → LocalStorageProvider-SSRW3ZJW.js.map} +1 -1
  9. package/dist/UniversalFileService-336GFY6N.mjs +6 -0
  10. package/dist/{UniversalFileService-TNYKO6JN.mjs.map → UniversalFileService-336GFY6N.mjs.map} +1 -1
  11. package/dist/UniversalFileService-J6ET6KZK.js +15 -0
  12. package/dist/{UniversalFileService-RBV6EN5J.js.map → UniversalFileService-J6ET6KZK.js.map} +1 -1
  13. package/dist/booking-BXtkG2ns.d.mts +386 -0
  14. package/dist/booking-BXtkG2ns.d.ts +386 -0
  15. package/dist/bookingAdminService-B2QDjSHJ.d.ts +193 -0
  16. package/dist/bookingAdminService-Dmg7dC6V.d.mts +193 -0
  17. package/dist/calendar/index.js +11 -11
  18. package/dist/calendar/index.mjs +4 -4
  19. package/dist/cart-CcZ7rQyG.d.mts +176 -0
  20. package/dist/cart-D3o67Q3H.d.ts +176 -0
  21. package/dist/chunk-25OFOKNF.js +171 -0
  22. package/dist/chunk-25OFOKNF.js.map +1 -0
  23. package/dist/chunk-3DXPQ4YV.mjs +165 -0
  24. package/dist/chunk-3DXPQ4YV.mjs.map +1 -0
  25. package/dist/{chunk-4VJQZSPU.mjs → chunk-3NHAT7D4.mjs} +3 -4
  26. package/dist/chunk-3NHAT7D4.mjs.map +1 -0
  27. package/dist/{chunk-3JW4X3AC.mjs → chunk-622Y6LTH.mjs} +3 -3
  28. package/dist/{chunk-3JW4X3AC.mjs.map → chunk-622Y6LTH.mjs.map} +1 -1
  29. package/dist/chunk-ANKVXRPY.mjs +30 -0
  30. package/dist/chunk-ANKVXRPY.mjs.map +1 -0
  31. package/dist/chunk-CIVO4R6N.mjs +37 -0
  32. package/dist/chunk-CIVO4R6N.mjs.map +1 -0
  33. package/dist/{chunk-IZOIVYOW.js → chunk-DENROXAE.js} +2 -2
  34. package/dist/{chunk-IZOIVYOW.js.map → chunk-DENROXAE.js.map} +1 -1
  35. package/dist/{chunk-6BJ76BYC.mjs → chunk-EGJPS7OL.mjs} +3 -3
  36. package/dist/{chunk-6BJ76BYC.mjs.map → chunk-EGJPS7OL.mjs.map} +1 -1
  37. package/dist/chunk-EKIOJEJK.js +2719 -0
  38. package/dist/chunk-EKIOJEJK.js.map +1 -0
  39. package/dist/chunk-EOWTOG7Y.js +119 -0
  40. package/dist/chunk-EOWTOG7Y.js.map +1 -0
  41. package/dist/chunk-HDMIOOZY.mjs +546 -0
  42. package/dist/chunk-HDMIOOZY.mjs.map +1 -0
  43. package/dist/{chunk-MZKATHB7.js → chunk-HHVDOIPV.js} +4 -4
  44. package/dist/{chunk-MZKATHB7.js.map → chunk-HHVDOIPV.js.map} +1 -1
  45. package/dist/chunk-HJ6MH7J7.js +552 -0
  46. package/dist/chunk-HJ6MH7J7.js.map +1 -0
  47. package/dist/chunk-KH6RQ4J5.js +28 -0
  48. package/dist/chunk-KH6RQ4J5.js.map +1 -0
  49. package/dist/{chunk-GFVAIT6Y.mjs → chunk-MFG2Y6UR.mjs} +2 -2
  50. package/dist/{chunk-GFVAIT6Y.mjs.map → chunk-MFG2Y6UR.mjs.map} +1 -1
  51. package/dist/{chunk-35CXIK5Y.js → chunk-NCOXT7SK.js} +11 -11
  52. package/dist/{chunk-35CXIK5Y.js.map → chunk-NCOXT7SK.js.map} +1 -1
  53. package/dist/chunk-NZZZUMMX.mjs +784 -0
  54. package/dist/chunk-NZZZUMMX.mjs.map +1 -0
  55. package/dist/{chunk-OBIPI4GU.mjs → chunk-OFYBMMWT.mjs} +4 -4
  56. package/dist/{chunk-OBIPI4GU.mjs.map → chunk-OFYBMMWT.mjs.map} +1 -1
  57. package/dist/chunk-PVLLRDUT.js +6944 -0
  58. package/dist/chunk-PVLLRDUT.js.map +1 -0
  59. package/dist/chunk-Q5EDCKQA.js +336 -0
  60. package/dist/chunk-Q5EDCKQA.js.map +1 -0
  61. package/dist/{chunk-SHY424RZ.mjs → chunk-SNBILYSH.mjs} +6 -6
  62. package/dist/{chunk-SHY424RZ.mjs.map → chunk-SNBILYSH.mjs.map} +1 -1
  63. package/dist/chunk-TJZDPOO7.js +34 -0
  64. package/dist/chunk-TJZDPOO7.js.map +1 -0
  65. package/dist/{chunk-7JN25DJB.js → chunk-UVHPCLP6.js} +14 -14
  66. package/dist/{chunk-7JN25DJB.js.map → chunk-UVHPCLP6.js.map} +1 -1
  67. package/dist/chunk-WGD2NBVR.mjs +6904 -0
  68. package/dist/chunk-WGD2NBVR.mjs.map +1 -0
  69. package/dist/chunk-WS3QZYBI.mjs +2701 -0
  70. package/dist/chunk-WS3QZYBI.mjs.map +1 -0
  71. package/dist/chunk-XLR6QUDR.mjs +113 -0
  72. package/dist/chunk-XLR6QUDR.mjs.map +1 -0
  73. package/dist/chunk-YMS6BPXS.js +807 -0
  74. package/dist/chunk-YMS6BPXS.js.map +1 -0
  75. package/dist/chunk-YOTQG4NP.mjs +314 -0
  76. package/dist/chunk-YOTQG4NP.mjs.map +1 -0
  77. package/dist/chunk-ZGVB35L2.mjs +25 -0
  78. package/dist/chunk-ZGVB35L2.mjs.map +1 -0
  79. package/dist/chunk-ZRAW3HXA.js +43 -0
  80. package/dist/chunk-ZRAW3HXA.js.map +1 -0
  81. package/dist/{chunk-4XXIBWCO.js → chunk-ZRWED7Q6.js} +66 -66
  82. package/dist/{chunk-4XXIBWCO.js.map → chunk-ZRWED7Q6.js.map} +1 -1
  83. package/dist/{chunk-DVENFCQY.js → chunk-ZWQJSZEY.js} +4 -5
  84. package/dist/chunk-ZWQJSZEY.js.map +1 -0
  85. package/dist/components/index.js +104 -104
  86. package/dist/components/index.mjs +4 -4
  87. package/dist/index.js +146 -148
  88. package/dist/index.js.map +1 -1
  89. package/dist/index.mjs +8 -11
  90. package/dist/index.mjs.map +1 -1
  91. package/dist/logger/index.js +7 -7
  92. package/dist/logger/index.mjs +1 -4
  93. package/dist/mikuFusionGame/index.js +4 -4
  94. package/dist/mikuFusionGame/index.mjs +3 -3
  95. package/dist/portfolio/index.js +10 -10
  96. package/dist/portfolio/index.mjs +5 -5
  97. package/dist/showmasterpiece/db/index.d.mts +3028 -0
  98. package/dist/showmasterpiece/db/index.d.ts +3028 -0
  99. package/dist/showmasterpiece/db/index.js +179 -0
  100. package/dist/showmasterpiece/db/index.js.map +1 -0
  101. package/dist/showmasterpiece/db/index.mjs +6 -0
  102. package/dist/showmasterpiece/db/index.mjs.map +1 -0
  103. package/dist/showmasterpiece/index.d.mts +10 -1729
  104. package/dist/showmasterpiece/index.d.ts +10 -1729
  105. package/dist/showmasterpiece/index.js +439 -9659
  106. package/dist/showmasterpiece/index.js.map +1 -1
  107. package/dist/showmasterpiece/index.mjs +12 -9633
  108. package/dist/showmasterpiece/index.mjs.map +1 -1
  109. package/dist/showmasterpiece/logic/index.d.mts +372 -0
  110. package/dist/showmasterpiece/logic/index.d.ts +372 -0
  111. package/dist/showmasterpiece/logic/index.js +91 -0
  112. package/dist/showmasterpiece/logic/index.js.map +1 -0
  113. package/dist/showmasterpiece/logic/index.mjs +6 -0
  114. package/dist/showmasterpiece/logic/index.mjs.map +1 -0
  115. package/dist/showmasterpiece/server/index.d.mts +3 -2704
  116. package/dist/showmasterpiece/server/index.d.ts +3 -2704
  117. package/dist/showmasterpiece/server/index.js +43 -43
  118. package/dist/showmasterpiece/server/index.mjs +2 -2
  119. package/dist/showmasterpiece/ui/miniapp/index.d.mts +86 -0
  120. package/dist/showmasterpiece/ui/miniapp/index.d.ts +86 -0
  121. package/dist/showmasterpiece/ui/miniapp/index.js +196 -0
  122. package/dist/showmasterpiece/ui/miniapp/index.js.map +1 -0
  123. package/dist/showmasterpiece/ui/miniapp/index.mjs +183 -0
  124. package/dist/showmasterpiece/ui/miniapp/index.mjs.map +1 -0
  125. package/dist/showmasterpiece/ui/web/index.d.mts +600 -0
  126. package/dist/showmasterpiece/ui/web/index.d.ts +600 -0
  127. package/dist/showmasterpiece/ui/web/index.js +131 -0
  128. package/dist/showmasterpiece/ui/web/index.js.map +1 -0
  129. package/dist/showmasterpiece/ui/web/index.mjs +14 -0
  130. package/dist/showmasterpiece/ui/web/index.mjs.map +1 -0
  131. package/dist/universalExport/server/index.js +2 -4
  132. package/dist/universalExport/server/index.js.map +1 -1
  133. package/dist/universalExport/server/index.mjs +1 -3
  134. package/dist/universalExport/server/index.mjs.map +1 -1
  135. package/dist/universalFile/index.js +6 -9
  136. package/dist/universalFile/index.js.map +1 -1
  137. package/dist/universalFile/index.mjs +1 -5
  138. package/dist/universalFile/index.mjs.map +1 -1
  139. package/dist/universalFile/server/index.js +5852 -291
  140. package/dist/universalFile/server/index.js.map +1 -1
  141. package/dist/universalFile/server/index.mjs +5764 -8
  142. package/dist/universalFile/server/index.mjs.map +1 -1
  143. package/dist/utils/index.js +11 -11
  144. package/dist/utils/index.mjs +2 -2
  145. package/package.json +26 -1
  146. package/dist/AliyunOSSProvider-2FARPAQD.js +0 -15
  147. package/dist/AliyunOSSProvider-UMVGVBDJ.mjs +0 -9
  148. package/dist/LocalStorageProvider-JQF5WK5H.js +0 -15
  149. package/dist/LocalStorageProvider-PYOHETJV.mjs +0 -9
  150. package/dist/UniversalFileService-RBV6EN5J.js +0 -15
  151. package/dist/UniversalFileService-TNYKO6JN.mjs +0 -9
  152. package/dist/chunk-4NFOSCM6.js +0 -34
  153. package/dist/chunk-4NFOSCM6.js.map +0 -1
  154. package/dist/chunk-4VJQZSPU.mjs.map +0 -1
  155. package/dist/chunk-6AHYPPUP.js +0 -344
  156. package/dist/chunk-6AHYPPUP.js.map +0 -1
  157. package/dist/chunk-76V7EKBX.mjs +0 -796
  158. package/dist/chunk-76V7EKBX.mjs.map +0 -1
  159. package/dist/chunk-ACLOJXXE.js +0 -195
  160. package/dist/chunk-ACLOJXXE.js.map +0 -1
  161. package/dist/chunk-AEXPAH7Z.mjs +0 -32
  162. package/dist/chunk-AEXPAH7Z.mjs.map +0 -1
  163. package/dist/chunk-CFGX3EKK.js +0 -560
  164. package/dist/chunk-CFGX3EKK.js.map +0 -1
  165. package/dist/chunk-D2HXMGXS.js +0 -46
  166. package/dist/chunk-D2HXMGXS.js.map +0 -1
  167. package/dist/chunk-DVENFCQY.js.map +0 -1
  168. package/dist/chunk-K7WNCB4V.mjs +0 -554
  169. package/dist/chunk-K7WNCB4V.mjs.map +0 -1
  170. package/dist/chunk-L4ZYBFB2.mjs +0 -44
  171. package/dist/chunk-L4ZYBFB2.mjs.map +0 -1
  172. package/dist/chunk-M4HGHTIC.js +0 -820
  173. package/dist/chunk-M4HGHTIC.js.map +0 -1
  174. package/dist/chunk-PKKIDPXE.mjs +0 -5797
  175. package/dist/chunk-PKKIDPXE.mjs.map +0 -1
  176. package/dist/chunk-PXWDQFWV.mjs +0 -192
  177. package/dist/chunk-PXWDQFWV.mjs.map +0 -1
  178. package/dist/chunk-TSTBLX6B.js +0 -5888
  179. package/dist/chunk-TSTBLX6B.js.map +0 -1
  180. package/dist/chunk-VTGPHE4Z.mjs +0 -322
  181. package/dist/chunk-VTGPHE4Z.mjs.map +0 -1
  182. package/dist/popupConfig-BznThU1O.d.mts +0 -330
  183. package/dist/popupConfig-BznThU1O.d.ts +0 -330
  184. package/dist/showmasterpiece/migration/index.d.mts +0 -120
  185. package/dist/showmasterpiece/migration/index.d.ts +0 -120
  186. package/dist/showmasterpiece/migration/index.js +0 -595
  187. package/dist/showmasterpiece/migration/index.js.map +0 -1
  188. package/dist/showmasterpiece/migration/index.mjs +0 -589
  189. package/dist/showmasterpiece/migration/index.mjs.map +0 -1
  190. package/dist/showmasterpiece/scripts/index.d.mts +0 -28
  191. package/dist/showmasterpiece/scripts/index.d.ts +0 -28
  192. package/dist/showmasterpiece/scripts/index.js +0 -327
  193. package/dist/showmasterpiece/scripts/index.js.map +0 -1
  194. package/dist/showmasterpiece/scripts/index.mjs +0 -325
  195. package/dist/showmasterpiece/scripts/index.mjs.map +0 -1
@@ -1,589 +0,0 @@
1
- import { comicUniverseArtworks, comicUniverseCollections } from '../../chunk-SHY424RZ.mjs';
2
- import '../../chunk-PAX4S7QM.mjs';
3
- import '../../chunk-GFVAIT6Y.mjs';
4
- import { fileStorageProviders, fileFolders, fileMetadata } from '../../chunk-PKKIDPXE.mjs';
5
- import '../../chunk-VTGPHE4Z.mjs';
6
- import '../../chunk-K7WNCB4V.mjs';
7
- import '../../chunk-AEXPAH7Z.mjs';
8
- import '../../chunk-76V7EKBX.mjs';
9
- import '../../chunk-PXWDQFWV.mjs';
10
- import '../../chunk-L4ZYBFB2.mjs';
11
- import '../../chunk-WMJKH4XE.mjs';
12
- import { inArray, and, or, isNull, eq } from 'drizzle-orm';
13
- import { v4 } from 'uuid';
14
- import { createHash } from 'crypto';
15
- import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'fs';
16
- import { join } from 'path';
17
-
18
- var ArtworkMigrator = class {
19
- constructor(db, config) {
20
- this.folderCache = /* @__PURE__ */ new Map();
21
- this.storageProviderCache = /* @__PURE__ */ new Map();
22
- this.db = db;
23
- this.config = config;
24
- this.stats = {
25
- totalArtworks: 0,
26
- processedCount: 0,
27
- successCount: 0,
28
- failedCount: 0,
29
- skippedCount: 0,
30
- totalFileSize: 0,
31
- processedFileSize: 0,
32
- errors: []
33
- };
34
- }
35
- /**
36
- * 开始迁移
37
- */
38
- async migrate() {
39
- console.log("\u{1F680} [ArtworkMigrator] \u5F00\u59CB\u4F5C\u54C1\u56FE\u7247\u8FC1\u79FB...");
40
- console.log("\u{1F4CB} [ArtworkMigrator] \u914D\u7F6E:", this.config);
41
- try {
42
- await this.analyzeData();
43
- await this.prepareMigrationEnvironment();
44
- await this.performBatchMigration();
45
- this.generateReport();
46
- return this.stats;
47
- } catch (error) {
48
- console.error("\u{1F4A5} [ArtworkMigrator] \u8FC1\u79FB\u5931\u8D25:", error);
49
- throw error;
50
- }
51
- }
52
- /**
53
- * 分析现有数据
54
- */
55
- async analyzeData() {
56
- console.log("\u{1F50D} [ArtworkMigrator] \u5206\u6790\u73B0\u6709\u6570\u636E...");
57
- const whereConditions = [];
58
- if (this.config.collectionIds && this.config.collectionIds.length > 0) {
59
- whereConditions.push(inArray(comicUniverseArtworks.collectionId, this.config.collectionIds));
60
- }
61
- whereConditions.push(
62
- and(
63
- or(
64
- isNull(comicUniverseArtworks.fileId),
65
- eq(comicUniverseArtworks.migrationStatus, "pending"),
66
- eq(comicUniverseArtworks.migrationStatus, "failed")
67
- ),
68
- // 必须有image数据(兼容可能的null值)
69
- eq(comicUniverseArtworks.isActive, true)
70
- )
71
- );
72
- const query = this.db.select({
73
- id: comicUniverseArtworks.id,
74
- title: comicUniverseArtworks.title,
75
- image: comicUniverseArtworks.image,
76
- collectionId: comicUniverseArtworks.collectionId,
77
- migrationStatus: comicUniverseArtworks.migrationStatus
78
- }).from(comicUniverseArtworks);
79
- if (whereConditions.length > 0) {
80
- query.where(and(...whereConditions));
81
- }
82
- const artworks = await query;
83
- this.stats.totalArtworks = artworks.length;
84
- for (const artwork of artworks) {
85
- if (artwork.image && artwork.image.startsWith("data:")) {
86
- const base64Data = artwork.image.split(",")[1];
87
- if (base64Data) {
88
- this.stats.totalFileSize += Math.round(base64Data.length * 0.75);
89
- }
90
- }
91
- }
92
- console.log("\u{1F4CA} [ArtworkMigrator] \u6570\u636E\u5206\u6790\u7ED3\u679C:", {
93
- totalArtworks: this.stats.totalArtworks,
94
- totalFileSize: `${(this.stats.totalFileSize / 1024 / 1024).toFixed(2)} MB`,
95
- collectionFilter: this.config.collectionIds?.length || "all"
96
- });
97
- if (this.stats.totalArtworks === 0) {
98
- console.log("\u2139\uFE0F [ArtworkMigrator] \u6CA1\u6709\u9700\u8981\u8FC1\u79FB\u7684\u4F5C\u54C1");
99
- return;
100
- }
101
- }
102
- /**
103
- * 准备迁移环境
104
- */
105
- async prepareMigrationEnvironment() {
106
- console.log("\u{1F6E0}\uFE0F [ArtworkMigrator] \u51C6\u5907\u8FC1\u79FB\u73AF\u5883...");
107
- await this.ensureStorageProvider();
108
- await this.ensureModuleFolders();
109
- if (this.config.backupOldData && !this.config.dryRun) {
110
- await this.backupOriginalData();
111
- }
112
- }
113
- /**
114
- * 确保存储提供者存在
115
- */
116
- async ensureStorageProvider() {
117
- let provider = this.storageProviderCache.get("local-default");
118
- if (!provider) {
119
- const [existingProvider] = await this.db.select().from(fileStorageProviders).where(eq(fileStorageProviders.name, "local-default")).limit(1);
120
- if (existingProvider) {
121
- provider = existingProvider;
122
- } else if (!this.config.dryRun) {
123
- [provider] = await this.db.insert(fileStorageProviders).values({
124
- name: "local-default",
125
- type: "local",
126
- config: {
127
- basePath: "./uploads",
128
- publicUrl: "/uploads"
129
- },
130
- isDefault: true,
131
- isActive: true
132
- }).returning();
133
- } else {
134
- provider = {
135
- id: 1,
136
- name: "local-default",
137
- type: "local",
138
- config: {
139
- basePath: "./uploads",
140
- publicUrl: "/uploads"
141
- },
142
- isDefault: true,
143
- isActive: true,
144
- priority: 100,
145
- maxFileSize: null,
146
- supportedMimeTypes: null,
147
- createdAt: /* @__PURE__ */ new Date(),
148
- updatedAt: /* @__PURE__ */ new Date()
149
- };
150
- }
151
- if (provider) {
152
- this.storageProviderCache.set("local-default", provider);
153
- }
154
- }
155
- }
156
- /**
157
- * 确保模块文件夹存在
158
- */
159
- async ensureModuleFolders() {
160
- const rootFolderId = v4();
161
- const rootFolderName = "ShowMasterpiece";
162
- let rootFolder = this.folderCache.get(rootFolderName);
163
- if (!rootFolder) {
164
- const [existingFolder] = await this.db.select().from(fileFolders).where(eq(fileFolders.name, rootFolderName)).limit(1);
165
- if (existingFolder) {
166
- rootFolder = existingFolder;
167
- } else if (!this.config.dryRun) {
168
- [rootFolder] = await this.db.insert(fileFolders).values({
169
- id: rootFolderId,
170
- name: rootFolderName,
171
- path: "/showmasterpiece",
172
- moduleId: "showmasterpiece",
173
- depth: 1,
174
- sortOrder: 1,
175
- isSystem: true,
176
- createdBy: "system"
177
- }).returning();
178
- } else {
179
- rootFolder = {
180
- id: rootFolderId,
181
- name: rootFolderName,
182
- path: "/showmasterpiece",
183
- moduleId: "showmasterpiece",
184
- depth: 1,
185
- sortOrder: 1,
186
- isSystem: true,
187
- createdBy: "system"
188
- };
189
- }
190
- if (rootFolder) {
191
- this.folderCache.set(rootFolderName, rootFolder);
192
- }
193
- }
194
- let collectionIds = this.config.collectionIds;
195
- if (!collectionIds) {
196
- const artworks = await this.db.select({ collectionId: comicUniverseArtworks.collectionId }).from(comicUniverseArtworks).where(eq(comicUniverseArtworks.isActive, true));
197
- const uniqueCollectionIds = [...new Set(artworks.map((a) => a.collectionId))];
198
- collectionIds = uniqueCollectionIds;
199
- }
200
- if (collectionIds && collectionIds.length > 0) {
201
- const collections = await this.db.select({
202
- id: comicUniverseCollections.id,
203
- title: comicUniverseCollections.title
204
- }).from(comicUniverseCollections).where(inArray(comicUniverseCollections.id, collectionIds));
205
- for (const collection of collections) {
206
- const folderName = `Collection-${collection.id}`;
207
- let collectionFolder = this.folderCache.get(folderName);
208
- if (!collectionFolder) {
209
- if (!this.config.dryRun) {
210
- const folderId = v4();
211
- [collectionFolder] = await this.db.insert(fileFolders).values({
212
- id: folderId,
213
- name: collection.title,
214
- path: `/showmasterpiece/collection-${collection.id}`,
215
- moduleId: "showmasterpiece",
216
- parentId: rootFolder?.id,
217
- depth: 2,
218
- sortOrder: collection.id,
219
- isSystem: false,
220
- createdBy: "system"
221
- }).returning();
222
- } else {
223
- collectionFolder = {
224
- id: v4(),
225
- name: collection.title,
226
- path: `/showmasterpiece/collection-${collection.id}`,
227
- moduleId: "showmasterpiece",
228
- parentId: rootFolder?.id,
229
- depth: 2,
230
- sortOrder: collection.id,
231
- isSystem: false,
232
- createdBy: "system"
233
- };
234
- }
235
- this.folderCache.set(folderName, collectionFolder);
236
- }
237
- }
238
- }
239
- }
240
- /**
241
- * 备份原始数据
242
- */
243
- async backupOriginalData() {
244
- console.log("\u{1F4BE} [ArtworkMigrator] \u5907\u4EFD\u539F\u59CB\u6570\u636E...");
245
- const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
246
- const backupDir = `./backups/showmasterpiece/${timestamp}`;
247
- if (!existsSync(backupDir)) {
248
- mkdirSync(backupDir, { recursive: true });
249
- }
250
- const artworks = await this.db.select().from(comicUniverseArtworks).where(eq(comicUniverseArtworks.isActive, true));
251
- writeFileSync(
252
- join(backupDir, "artworks_backup.json"),
253
- JSON.stringify(artworks, null, 2)
254
- );
255
- console.log(`\u2705 [ArtworkMigrator] \u5907\u4EFD\u5B8C\u6210: ${backupDir}`);
256
- }
257
- /**
258
- * 执行批量迁移
259
- */
260
- async performBatchMigration() {
261
- console.log("\u{1F504} [ArtworkMigrator] \u5F00\u59CB\u6279\u91CF\u8FC1\u79FB...");
262
- const whereConditions = [];
263
- if (this.config.collectionIds && this.config.collectionIds.length > 0) {
264
- whereConditions.push(inArray(comicUniverseArtworks.collectionId, this.config.collectionIds));
265
- }
266
- whereConditions.push(
267
- and(
268
- or(
269
- isNull(comicUniverseArtworks.fileId),
270
- eq(comicUniverseArtworks.migrationStatus, "pending"),
271
- eq(comicUniverseArtworks.migrationStatus, "failed")
272
- ),
273
- eq(comicUniverseArtworks.isActive, true)
274
- )
275
- );
276
- const query = this.db.select().from(comicUniverseArtworks);
277
- if (whereConditions.length > 0) {
278
- query.where(and(...whereConditions));
279
- }
280
- const artworks = await query;
281
- const totalBatches = Math.ceil(artworks.length / this.config.batchSize);
282
- for (let i = 0; i < totalBatches; i++) {
283
- const start = i * this.config.batchSize;
284
- const end = Math.min(start + this.config.batchSize, artworks.length);
285
- const batch = artworks.slice(start, end);
286
- console.log(`\u{1F4E6} [ArtworkMigrator] \u5904\u7406\u6279\u6B21 ${i + 1}/${totalBatches}`);
287
- for (const artwork of batch) {
288
- try {
289
- await this.migrateArtwork(artwork);
290
- } catch (error) {
291
- console.error(`\u274C [ArtworkMigrator] \u8FC1\u79FB\u4F5C\u54C1\u5931\u8D25 ${artwork.id}:`, error);
292
- this.stats.errors.push({
293
- artworkId: artwork.id,
294
- error: error instanceof Error ? error.message : String(error),
295
- timestamp: /* @__PURE__ */ new Date()
296
- });
297
- this.stats.failedCount++;
298
- }
299
- this.stats.processedCount++;
300
- }
301
- }
302
- }
303
- /**
304
- * 迁移单个作品
305
- */
306
- async migrateArtwork(artwork) {
307
- console.log(`\u{1F4C4} [ArtworkMigrator] \u8FC1\u79FB\u4F5C\u54C1: ${artwork.id} - ${artwork.title}`);
308
- if (artwork.fileId && artwork.migrationStatus === "completed" && !this.config.forceOverwrite) {
309
- console.log(`\u23ED\uFE0F [ArtworkMigrator] \u4F5C\u54C1 ${artwork.id} \u5DF2\u8FC1\u79FB\uFF0C\u8DF3\u8FC7`);
310
- this.stats.skippedCount++;
311
- return;
312
- }
313
- if (!artwork.image || !artwork.image.startsWith("data:")) {
314
- console.log(`\u26A0\uFE0F [ArtworkMigrator] \u4F5C\u54C1 ${artwork.id} \u6CA1\u6709\u6709\u6548\u7684\u56FE\u7247\u6570\u636E`);
315
- this.stats.skippedCount++;
316
- return;
317
- }
318
- const { mimeType, buffer, extension } = this.parseBase64Image(artwork.image);
319
- const fileSize = buffer.length;
320
- const md5Hash = createHash("md5").update(buffer).digest("hex");
321
- const sha256Hash = createHash("sha256").update(buffer).digest("hex");
322
- const provider = this.storageProviderCache.get("local-default");
323
- if (!provider) {
324
- throw new Error("\u5B58\u50A8\u63D0\u4F9B\u8005\u672A\u627E\u5230");
325
- }
326
- const folderName = `Collection-${artwork.collectionId}`;
327
- const folder = this.folderCache.get(folderName) || this.folderCache.get("ShowMasterpiece");
328
- if (!folder) {
329
- throw new Error("\u76EE\u6807\u6587\u4EF6\u5939\u672A\u627E\u5230");
330
- }
331
- const storedName = `artwork-${artwork.id}-${Date.now()}${extension}`;
332
- const storagePath = `showmasterpiece/collection-${artwork.collectionId}/${storedName}`;
333
- const fullPath = join("./uploads", storagePath);
334
- if (!this.config.dryRun) {
335
- const dir = fullPath.substring(0, fullPath.lastIndexOf("/"));
336
- if (!existsSync(dir)) {
337
- mkdirSync(dir, { recursive: true });
338
- }
339
- writeFileSync(fullPath, buffer);
340
- }
341
- if (this.config.validateFiles && !this.config.dryRun) {
342
- const savedBuffer = readFileSync(fullPath);
343
- const savedHash = createHash("md5").update(savedBuffer).digest("hex");
344
- if (savedHash !== md5Hash) {
345
- throw new Error("\u6587\u4EF6\u9A8C\u8BC1\u5931\u8D25\uFF1A\u54C8\u5E0C\u4E0D\u5339\u914D");
346
- }
347
- }
348
- let fileRecord = null;
349
- if (!this.config.dryRun) {
350
- [fileRecord] = await this.db.insert(fileMetadata).values({
351
- originalName: `${artwork.title}${extension}`,
352
- storedName,
353
- extension: extension.substring(1),
354
- mimeType,
355
- size: fileSize,
356
- md5Hash,
357
- sha256Hash,
358
- storagePath,
359
- storageProviderId: provider.id,
360
- folderId: folder.id,
361
- moduleId: "showmasterpiece",
362
- businessId: artwork.collectionId.toString(),
363
- tags: ["artwork", "masterpiece"],
364
- uploaderId: "system"
365
- }).returning();
366
- }
367
- if (!this.config.dryRun && fileRecord) {
368
- await this.db.update(comicUniverseArtworks).set({
369
- fileId: fileRecord.id,
370
- migrationStatus: "completed",
371
- updatedAt: /* @__PURE__ */ new Date()
372
- }).where(eq(comicUniverseArtworks.id, artwork.id));
373
- }
374
- this.stats.successCount++;
375
- this.stats.processedFileSize += fileSize;
376
- console.log(`\u2705 [ArtworkMigrator] \u4F5C\u54C1 ${artwork.id} \u8FC1\u79FB\u6210\u529F`);
377
- }
378
- /**
379
- * 解析Base64图片
380
- */
381
- parseBase64Image(dataUrl) {
382
- const matches = dataUrl.match(/^data:([^;]+);base64,(.+)$/);
383
- if (!matches) {
384
- throw new Error("\u65E0\u6548\u7684Base64\u56FE\u7247\u683C\u5F0F");
385
- }
386
- const mimeType = matches[1];
387
- const base64Data = matches[2];
388
- const buffer = Buffer.from(base64Data, "base64");
389
- const extensionMap = {
390
- "image/jpeg": ".jpg",
391
- "image/jpg": ".jpg",
392
- "image/png": ".png",
393
- "image/gif": ".gif",
394
- "image/webp": ".webp",
395
- "image/bmp": ".bmp"
396
- };
397
- const extension = extensionMap[mimeType] || ".jpg";
398
- return { mimeType, buffer, extension };
399
- }
400
- /**
401
- * 生成迁移报告
402
- */
403
- generateReport() {
404
- console.log("\n\u{1F4CA} [ArtworkMigrator] \u8FC1\u79FB\u5B8C\u6210\u62A5\u544A:");
405
- console.log("=".repeat(50));
406
- console.log(`\u603B\u4F5C\u54C1\u6570: ${this.stats.totalArtworks}`);
407
- console.log(`\u5904\u7406\u6570\u91CF: ${this.stats.processedCount}`);
408
- console.log(`\u6210\u529F\u6570\u91CF: ${this.stats.successCount}`);
409
- console.log(`\u5931\u8D25\u6570\u91CF: ${this.stats.failedCount}`);
410
- console.log(`\u8DF3\u8FC7\u6570\u91CF: ${this.stats.skippedCount}`);
411
- console.log(`\u603B\u6587\u4EF6\u5927\u5C0F: ${(this.stats.totalFileSize / 1024 / 1024).toFixed(2)} MB`);
412
- console.log(`\u5DF2\u5904\u7406\u5927\u5C0F: ${(this.stats.processedFileSize / 1024 / 1024).toFixed(2)} MB`);
413
- if (this.stats.errors.length > 0) {
414
- console.log("\n\u274C \u9519\u8BEF\u8BE6\u60C5:");
415
- this.stats.errors.forEach((error, index) => {
416
- console.log(`${index + 1}. \u4F5C\u54C1 ${error.artworkId}: ${error.error}`);
417
- });
418
- }
419
- const successRate = this.stats.totalArtworks > 0 ? (this.stats.successCount / this.stats.totalArtworks * 100).toFixed(2) : "0";
420
- console.log(`
421
- \u2705 \u6210\u529F\u7387: ${successRate}%`);
422
- }
423
- /**
424
- * 回滚单个作品
425
- */
426
- async rollbackArtwork(artworkId) {
427
- console.log(`\u{1F504} [ArtworkMigrator] \u56DE\u6EDA\u4F5C\u54C1: ${artworkId}`);
428
- const [artwork] = await this.db.select().from(comicUniverseArtworks).where(eq(comicUniverseArtworks.id, artworkId)).limit(1);
429
- if (!artwork) {
430
- throw new Error(`\u4F5C\u54C1 ${artworkId} \u4E0D\u5B58\u5728`);
431
- }
432
- if (!artwork.fileId) {
433
- console.log(`\u26A0\uFE0F [ArtworkMigrator] \u4F5C\u54C1 ${artworkId} \u6CA1\u6709\u6587\u4EF6\u5F15\u7528\uFF0C\u65E0\u9700\u56DE\u6EDA`);
434
- return;
435
- }
436
- const [fileRecord] = await this.db.select().from(fileMetadata).where(eq(fileMetadata.id, artwork.fileId)).limit(1);
437
- if (fileRecord) {
438
- const fullPath = join("./uploads", fileRecord.storagePath);
439
- if (existsSync(fullPath)) {
440
- console.log(`\u{1F4C1} [ArtworkMigrator] \u4FDD\u7559\u6587\u4EF6: ${fullPath}`);
441
- }
442
- await this.db.delete(fileMetadata).where(eq(fileMetadata.id, artwork.fileId));
443
- }
444
- await this.db.update(comicUniverseArtworks).set({
445
- fileId: null,
446
- migrationStatus: "pending",
447
- updatedAt: /* @__PURE__ */ new Date()
448
- }).where(eq(comicUniverseArtworks.id, artworkId));
449
- console.log(`\u2705 [ArtworkMigrator] \u4F5C\u54C1 ${artworkId} \u56DE\u6EDA\u5B8C\u6210`);
450
- }
451
- };
452
-
453
- // src/showmasterpiece/migration/runMigration.ts
454
- function parseMigrationArguments(args) {
455
- const config = {
456
- batchSize: 50,
457
- dryRun: false,
458
- validateFiles: true,
459
- backupOldData: true,
460
- forceOverwrite: false,
461
- enableOSSUpload: false,
462
- collectionIds: void 0
463
- };
464
- let showHelp = false;
465
- for (let i = 0; i < args.length; i++) {
466
- const arg = args[i];
467
- switch (arg) {
468
- case "--help":
469
- case "-h":
470
- showHelp = true;
471
- break;
472
- case "--dry-run":
473
- config.dryRun = true;
474
- break;
475
- case "--batch-size": {
476
- const batchSize = parseInt(args[++i] || "", 10);
477
- if (isNaN(batchSize) || batchSize <= 0) {
478
- throw new Error("\u6279\u5927\u5C0F\u5FC5\u987B\u662F\u5927\u4E8E0\u7684\u6570\u5B57");
479
- }
480
- config.batchSize = batchSize;
481
- break;
482
- }
483
- case "--collection-id":
484
- case "--collection-ids": {
485
- const collectionIdsStr = args[++i];
486
- if (!collectionIdsStr) {
487
- throw new Error("\u8BF7\u6307\u5B9A\u753B\u96C6ID");
488
- }
489
- config.collectionIds = collectionIdsStr.split(",").map((id) => {
490
- const num = parseInt(id.trim(), 10);
491
- if (isNaN(num)) {
492
- throw new Error(`\u65E0\u6548\u7684\u753B\u96C6ID: ${id}`);
493
- }
494
- return num;
495
- });
496
- break;
497
- }
498
- case "--no-validate":
499
- config.validateFiles = false;
500
- break;
501
- case "--validate":
502
- config.validateFiles = true;
503
- break;
504
- case "--no-backup":
505
- config.backupOldData = false;
506
- break;
507
- case "--backup":
508
- config.backupOldData = true;
509
- break;
510
- case "--force":
511
- config.forceOverwrite = true;
512
- break;
513
- case "--enable-oss":
514
- config.enableOSSUpload = true;
515
- break;
516
- default:
517
- throw new Error(`\u672A\u77E5\u9009\u9879: ${arg}`);
518
- }
519
- }
520
- return { config, showHelp };
521
- }
522
- function getMigrationHelpText() {
523
- return `
524
- ShowMasterpiece\u6A21\u5757\u56FE\u7247\u8FC1\u79FB\u5DE5\u5177
525
-
526
- \u7528\u6CD5:
527
- npx tsx src/modules/showmasterpiece/migration/runMigration.ts [\u9009\u9879]
528
-
529
- \u9009\u9879:
530
- -h, --help \u663E\u793A\u5E2E\u52A9\u4FE1\u606F
531
- --dry-run \u8BD5\u8FD0\u884C\uFF0C\u4E0D\u5B9E\u9645\u6267\u884C\u8FC1\u79FB
532
- --batch-size <number> \u6279\u5904\u7406\u5927\u5C0F\uFF08\u9ED8\u8BA4: 50\uFF09
533
- --collection-id <ids> \u6307\u5B9A\u753B\u96C6ID\uFF0C\u7528\u9017\u53F7\u5206\u9694\uFF08\u5982: 1,2,3\uFF09
534
- --validate \u9A8C\u8BC1\u6587\u4EF6\u5B8C\u6574\u6027\uFF08\u9ED8\u8BA4\u5F00\u542F\uFF09
535
- --no-validate \u8DF3\u8FC7\u6587\u4EF6\u9A8C\u8BC1
536
- --backup \u5907\u4EFD\u539F\u59CB\u6570\u636E\uFF08\u9ED8\u8BA4\u5F00\u542F\uFF09
537
- --no-backup \u8DF3\u8FC7\u6570\u636E\u5907\u4EFD
538
- --force \u5F3A\u5236\u8986\u76D6\u5DF2\u5B58\u5728\u7684\u6587\u4EF6
539
- --enable-oss \u542F\u7528OSS\u4E0A\u4F20
540
-
541
- \u793A\u4F8B:
542
- # \u8BD5\u8FD0\u884C\uFF0C\u67E5\u770B\u5C06\u8981\u8FC1\u79FB\u7684\u6570\u636E
543
- npx tsx src/modules/showmasterpiece/migration/runMigration.ts --dry-run
544
-
545
- # \u8FC1\u79FB\u6307\u5B9A\u753B\u96C6\u7684\u4F5C\u54C1
546
- npx tsx src/modules/showmasterpiece/migration/runMigration.ts --collection-id 1,2,3
547
-
548
- # \u5C0F\u6279\u91CF\u6D4B\u8BD5\u8FC1\u79FB
549
- npx tsx src/modules/showmasterpiece/migration/runMigration.ts --batch-size 5 --dry-run
550
-
551
- # \u5B8C\u6574\u8FC1\u79FB\uFF08\u5305\u542B\u9A8C\u8BC1\u548C\u5907\u4EFD\uFF09
552
- npx tsx src/modules/showmasterpiece/migration/runMigration.ts --validate --backup
553
-
554
- # \u5F3A\u5236\u8986\u76D6\u5DF2\u8FC1\u79FB\u7684\u6587\u4EF6
555
- npx tsx src/modules/showmasterpiece/migration/runMigration.ts --force
556
-
557
- # \u4E0D\u9A8C\u8BC1\u6587\u4EF6\uFF0C\u5FEB\u901F\u8FC1\u79FB
558
- npx tsx src/modules/showmasterpiece/migration/runMigration.ts --no-validate --no-backup
559
-
560
- \u6CE8\u610F\u4E8B\u9879:
561
- - \u9996\u6B21\u8FD0\u884C\u5EFA\u8BAE\u4F7F\u7528 --dry-run \u8FDB\u884C\u6D4B\u8BD5
562
- - \u8FC1\u79FB\u524D\u4F1A\u81EA\u52A8\u5907\u4EFD\u539F\u59CB\u6570\u636E\uFF08\u9664\u975E\u4F7F\u7528 --no-backup\uFF09
563
- - \u4F7F\u7528 --force \u9009\u9879\u4F1A\u8986\u76D6\u5DF2\u8FC1\u79FB\u7684\u6587\u4EF6
564
- - \u8FC1\u79FB\u8FC7\u7A0B\u4E2D\u8BF7\u4FDD\u6301\u6570\u636E\u5E93\u8FDE\u63A5\u7A33\u5B9A
565
- `;
566
- }
567
- function validateMigrationPrerequisites(config) {
568
- console.log("\u{1F50D} \u9A8C\u8BC1\u8FC1\u79FB\u524D\u7F6E\u6761\u4EF6...");
569
- if (!process.env.DATABASE_URL) {
570
- throw new Error("\u6570\u636E\u5E93\u8FDE\u63A5URL\u672A\u8BBE\u7F6E\uFF0C\u8BF7\u8BBE\u7F6E DATABASE_URL \u73AF\u5883\u53D8\u91CF");
571
- }
572
- const nodeVersion = process.version;
573
- const majorVersion = parseInt(nodeVersion.slice(1).split(".")[0] ?? "0", 10);
574
- if (majorVersion < 16) {
575
- throw new Error(`Node.js\u7248\u672C\u8FC7\u4F4E: ${nodeVersion}\uFF0C\u8BF7\u4F7F\u7528 Node.js 16 \u6216\u66F4\u9AD8\u7248\u672C`);
576
- }
577
- if (config.dryRun) {
578
- console.log("\u{1F50D} \u5F53\u524D\u4E3A\u8BD5\u8FD0\u884C\u6A21\u5F0F\uFF0C\u4E0D\u4F1A\u5B9E\u9645\u4FEE\u6539\u6570\u636E");
579
- }
580
- console.log("\u2705 \u524D\u7F6E\u6761\u4EF6\u9A8C\u8BC1\u901A\u8FC7");
581
- }
582
- async function runArtworkMigration(db, config) {
583
- const migrator = new ArtworkMigrator(db, config);
584
- return migrator.migrate();
585
- }
586
-
587
- export { ArtworkMigrator, getMigrationHelpText, parseMigrationArguments, runArtworkMigration, validateMigrationPrerequisites };
588
- //# sourceMappingURL=index.mjs.map
589
- //# sourceMappingURL=index.mjs.map