sa2kit 1.6.44 → 1.6.45
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/AliyunOSSProvider-2FARPAQD.js +15 -0
- package/dist/{AliyunOSSProvider-HCNGDJL7.js.map → AliyunOSSProvider-2FARPAQD.js.map} +1 -1
- package/dist/AliyunOSSProvider-UMVGVBDJ.mjs +9 -0
- package/dist/{AliyunOSSProvider-4W47OFEK.mjs.map → AliyunOSSProvider-UMVGVBDJ.mjs.map} +1 -1
- package/dist/CollisionBalls-BpHufX3H.d.mts +41 -0
- package/dist/CollisionBalls-BpHufX3H.d.ts +41 -0
- package/dist/ConfigService-QR67WYNK.mjs +4 -0
- package/dist/{ConfigService-V6ZK273Z.mjs.map → ConfigService-QR67WYNK.mjs.map} +1 -1
- package/dist/{ConfigService-3DIC6C3Q.js → ConfigService-UYC6ZTCM.js} +3 -3
- package/dist/{ConfigService-3DIC6C3Q.js.map → ConfigService-UYC6ZTCM.js.map} +1 -1
- package/dist/GenericOrderManager-e4WizpNf.d.mts +28 -0
- package/dist/GenericOrderManager-e4WizpNf.d.ts +28 -0
- package/dist/LocalStorageProvider-JQF5WK5H.js +15 -0
- package/dist/{LocalStorageProvider-PP7MA5OT.js.map → LocalStorageProvider-JQF5WK5H.js.map} +1 -1
- package/dist/LocalStorageProvider-PYOHETJV.mjs +9 -0
- package/dist/{LocalStorageProvider-3RVPCQB3.mjs.map → LocalStorageProvider-PYOHETJV.mjs.map} +1 -1
- package/dist/PMXParser-RLBDO7YK.mjs +4 -0
- package/dist/{PMXParser-RNVQL76A.mjs.map → PMXParser-RLBDO7YK.mjs.map} +1 -1
- package/dist/{PMXParser-2VTA737I.js → PMXParser-XHNO2KNI.js} +3 -3
- package/dist/{PMXParser-2VTA737I.js.map → PMXParser-XHNO2KNI.js.map} +1 -1
- package/dist/UniversalFileService-RBV6EN5J.js +15 -0
- package/dist/UniversalFileService-RBV6EN5J.js.map +1 -0
- package/dist/UniversalFileService-TNYKO6JN.mjs +9 -0
- package/dist/UniversalFileService-TNYKO6JN.mjs.map +1 -0
- package/dist/analytics/index.js +1 -1
- package/dist/analytics/index.mjs +1 -1
- package/dist/analytics/server/index.js +1 -1
- package/dist/analytics/server/index.mjs +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/index.mjs +1 -1
- package/dist/audioDetection/index.js +1 -1
- package/dist/audioDetection/index.mjs +1 -1
- package/dist/auth/client/index.js +1 -1
- package/dist/auth/client/index.mjs +1 -1
- package/dist/auth/components/index.js +1 -1
- package/dist/auth/components/index.mjs +1 -1
- package/dist/auth/hooks/index.js +1 -1
- package/dist/auth/hooks/index.mjs +1 -1
- package/dist/auth/index.js +1 -1
- package/dist/auth/index.mjs +1 -1
- package/dist/auth/middleware/index.js +1 -1
- package/dist/auth/middleware/index.mjs +1 -1
- package/dist/auth/routes/index.js +1 -1
- package/dist/auth/routes/index.mjs +1 -1
- package/dist/auth/schema/index.js +1 -1
- package/dist/auth/schema/index.mjs +1 -1
- package/dist/auth/services/index.js +1 -1
- package/dist/auth/services/index.mjs +1 -1
- package/dist/calendar/index.js +12 -12
- package/dist/calendar/index.mjs +5 -5
- package/dist/calendar/routes/index.js +1 -1
- package/dist/calendar/routes/index.mjs +1 -1
- package/dist/calendar/server.js +1 -1
- package/dist/calendar/server.mjs +1 -1
- package/dist/chunk-2PS5PIXV.mjs +443 -0
- package/dist/chunk-2PS5PIXV.mjs.map +1 -0
- package/dist/chunk-35CXIK5Y.js +277 -0
- package/dist/chunk-35CXIK5Y.js.map +1 -0
- package/dist/{chunk-GMIUSZXC.mjs → chunk-3JW4X3AC.mjs} +3 -3
- package/dist/{chunk-GMIUSZXC.mjs.map → chunk-3JW4X3AC.mjs.map} +1 -1
- package/dist/chunk-3M6T5KVD.js +453 -0
- package/dist/chunk-3M6T5KVD.js.map +1 -0
- package/dist/chunk-3TNR6IMC.js +168 -0
- package/dist/chunk-3TNR6IMC.js.map +1 -0
- package/dist/chunk-4NFOSCM6.js +34 -0
- package/dist/chunk-4NFOSCM6.js.map +1 -0
- package/dist/{chunk-3NHAT7D4.mjs → chunk-4VJQZSPU.mjs} +4 -3
- package/dist/chunk-4VJQZSPU.mjs.map +1 -0
- package/dist/{chunk-SCDDMIF6.js → chunk-4XXIBWCO.js} +66 -66
- package/dist/{chunk-SCDDMIF6.js.map → chunk-4XXIBWCO.js.map} +1 -1
- package/dist/chunk-6AHYPPUP.js +344 -0
- package/dist/chunk-6AHYPPUP.js.map +1 -0
- package/dist/{chunk-EGJPS7OL.mjs → chunk-6BJ76BYC.mjs} +3 -3
- package/dist/{chunk-EGJPS7OL.mjs.map → chunk-6BJ76BYC.mjs.map} +1 -1
- package/dist/chunk-76V7EKBX.mjs +796 -0
- package/dist/chunk-76V7EKBX.mjs.map +1 -0
- package/dist/chunk-ACLOJXXE.js +195 -0
- package/dist/chunk-ACLOJXXE.js.map +1 -0
- package/dist/chunk-AEXPAH7Z.mjs +32 -0
- package/dist/chunk-AEXPAH7Z.mjs.map +1 -0
- package/dist/chunk-CFGX3EKK.js +560 -0
- package/dist/chunk-CFGX3EKK.js.map +1 -0
- package/dist/chunk-D2HXMGXS.js +46 -0
- package/dist/chunk-D2HXMGXS.js.map +1 -0
- package/dist/chunk-DM2GUVUH.js +1201 -0
- package/dist/chunk-DM2GUVUH.js.map +1 -0
- package/dist/{chunk-ZWQJSZEY.js → chunk-DVENFCQY.js} +5 -4
- package/dist/chunk-DVENFCQY.js.map +1 -0
- package/dist/chunk-EONPKLEJ.mjs +163 -0
- package/dist/chunk-EONPKLEJ.mjs.map +1 -0
- package/dist/{chunk-L47ZOYHL.js → chunk-EUIXQPPU.js} +4 -4
- package/dist/{chunk-L47ZOYHL.js.map → chunk-EUIXQPPU.js.map} +1 -1
- package/dist/chunk-K7WNCB4V.mjs +554 -0
- package/dist/chunk-K7WNCB4V.mjs.map +1 -0
- package/dist/chunk-L4ZYBFB2.mjs +44 -0
- package/dist/chunk-L4ZYBFB2.mjs.map +1 -0
- package/dist/chunk-M4HGHTIC.js +820 -0
- package/dist/chunk-M4HGHTIC.js.map +1 -0
- package/dist/{chunk-HHVDOIPV.js → chunk-MZKATHB7.js} +4 -4
- package/dist/{chunk-HHVDOIPV.js.map → chunk-MZKATHB7.js.map} +1 -1
- package/dist/{chunk-UKT3PLON.mjs → chunk-NXQVTAOP.mjs} +3 -3
- package/dist/{chunk-UKT3PLON.mjs.map → chunk-NXQVTAOP.mjs.map} +1 -1
- package/dist/chunk-OBIPI4GU.mjs +266 -0
- package/dist/chunk-OBIPI4GU.mjs.map +1 -0
- package/dist/chunk-PAX4S7QM.mjs +94 -0
- package/dist/chunk-PAX4S7QM.mjs.map +1 -0
- package/dist/chunk-PXWDQFWV.mjs +192 -0
- package/dist/chunk-PXWDQFWV.mjs.map +1 -0
- package/dist/chunk-QROLPPXP.mjs +5797 -0
- package/dist/chunk-QROLPPXP.mjs.map +1 -0
- package/dist/chunk-TGNUEULF.mjs +1158 -0
- package/dist/chunk-TGNUEULF.mjs.map +1 -0
- package/dist/chunk-VBQFVXOW.mjs +2772 -0
- package/dist/chunk-VBQFVXOW.mjs.map +1 -0
- package/dist/chunk-VLZ5N6XZ.js +5888 -0
- package/dist/chunk-VLZ5N6XZ.js.map +1 -0
- package/dist/chunk-VTGPHE4Z.mjs +322 -0
- package/dist/chunk-VTGPHE4Z.mjs.map +1 -0
- package/dist/chunk-WMJKH4XE.mjs +30 -0
- package/dist/{chunk-BJTO5JO5.mjs.map → chunk-WMJKH4XE.mjs.map} +1 -1
- package/dist/chunk-XYQMAF7H.js +96 -0
- package/dist/chunk-XYQMAF7H.js.map +1 -0
- package/dist/chunk-Z3G3IXEF.js +2814 -0
- package/dist/chunk-Z3G3IXEF.js.map +1 -0
- package/dist/chunk-Z6ZWNWWR.js +35 -0
- package/dist/{chunk-DGUM43GV.js.map → chunk-Z6ZWNWWR.js.map} +1 -1
- package/dist/components/index.d.mts +378 -0
- package/dist/components/index.d.ts +378 -0
- package/dist/components/index.js +414 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +9 -0
- package/dist/components/index.mjs.map +1 -0
- package/dist/config/index.js +1 -1
- package/dist/config/index.mjs +1 -1
- package/dist/config/server/index.js +1 -1
- package/dist/config/server/index.mjs +1 -1
- package/dist/fileService-O3W6YXCI.mjs +4 -0
- package/dist/fileService-O3W6YXCI.mjs.map +1 -0
- package/dist/fileService-YUDIYOAS.js +13 -0
- package/dist/fileService-YUDIYOAS.js.map +1 -0
- package/dist/i18n/index.js +7 -7
- package/dist/i18n/index.mjs +1 -1
- package/dist/imageCrop/index.js +1 -1
- package/dist/imageCrop/index.mjs +1 -1
- package/dist/index.d.mts +9 -580
- package/dist/index.d.ts +9 -580
- package/dist/index.js +297 -956
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +103 -789
- package/dist/index.mjs.map +1 -1
- package/dist/logger/index.js +8 -8
- package/dist/logger/index.mjs +5 -2
- package/dist/mikuFireworks3D/index.js +1 -1
- package/dist/mikuFireworks3D/index.mjs +1 -1
- package/dist/mikuFireworks3D/server/index.js +1 -1
- package/dist/mikuFireworks3D/server/index.mjs +1 -1
- package/dist/mikuFusionGame/index.js +5 -5
- package/dist/mikuFusionGame/index.mjs +4 -4
- package/dist/mmd/admin/index.js +1 -1
- package/dist/mmd/admin/index.mjs +1 -1
- package/dist/mmd/index.js +2 -2
- package/dist/mmd/index.mjs +2 -2
- package/dist/mmd/server/index.js +1 -1
- package/dist/mmd/server/index.mjs +1 -1
- package/dist/music/index.js +1 -1
- package/dist/music/index.mjs +1 -1
- package/dist/music/server/index.js +1 -1
- package/dist/music/server/index.mjs +1 -1
- package/dist/navigation/index.d.mts +93 -0
- package/dist/navigation/index.d.ts +93 -0
- package/dist/navigation/index.js +29 -0
- package/dist/navigation/index.js.map +1 -0
- package/dist/navigation/index.mjs +4 -0
- package/dist/navigation/index.mjs.map +1 -0
- package/dist/popupConfig-BznThU1O.d.mts +330 -0
- package/dist/popupConfig-BznThU1O.d.ts +330 -0
- package/dist/portfolio/index.d.mts +57 -0
- package/dist/portfolio/index.d.ts +57 -0
- package/dist/portfolio/index.js +35 -0
- package/dist/portfolio/index.js.map +1 -0
- package/dist/portfolio/index.mjs +10 -0
- package/dist/portfolio/index.mjs.map +1 -0
- package/dist/request/index.js +1 -1
- package/dist/request/index.mjs +1 -1
- package/dist/showmasterpiece/index.d.mts +2524 -0
- package/dist/showmasterpiece/index.d.ts +2524 -0
- package/dist/showmasterpiece/index.js +9681 -0
- package/dist/showmasterpiece/index.js.map +1 -0
- package/dist/showmasterpiece/index.mjs +9631 -0
- package/dist/showmasterpiece/index.mjs.map +1 -0
- package/dist/showmasterpiece/migration/index.d.mts +120 -0
- package/dist/showmasterpiece/migration/index.d.ts +120 -0
- package/dist/showmasterpiece/migration/index.js +595 -0
- package/dist/showmasterpiece/migration/index.js.map +1 -0
- package/dist/showmasterpiece/migration/index.mjs +589 -0
- package/dist/showmasterpiece/migration/index.mjs.map +1 -0
- package/dist/showmasterpiece/scripts/index.d.mts +28 -0
- package/dist/showmasterpiece/scripts/index.d.ts +28 -0
- package/dist/showmasterpiece/scripts/index.js +327 -0
- package/dist/showmasterpiece/scripts/index.js.map +1 -0
- package/dist/showmasterpiece/scripts/index.mjs +325 -0
- package/dist/showmasterpiece/scripts/index.mjs.map +1 -0
- package/dist/showmasterpiece/server/index.d.mts +2698 -0
- package/dist/showmasterpiece/server/index.d.ts +2698 -0
- package/dist/showmasterpiece/server/index.js +179 -0
- package/dist/showmasterpiece/server/index.js.map +1 -0
- package/dist/showmasterpiece/server/index.mjs +6 -0
- package/dist/showmasterpiece/server/index.mjs.map +1 -0
- package/dist/storage/index.js +8 -8
- package/dist/storage/index.mjs +2 -2
- package/dist/testYourself/admin/index.js +1 -1
- package/dist/testYourself/admin/index.mjs +1 -1
- package/dist/testYourself/index.js +2 -2
- package/dist/testYourself/index.mjs +2 -2
- package/dist/testYourself/server/index.js +1 -1
- package/dist/testYourself/server/index.mjs +1 -1
- package/dist/universalExport/index.js +154 -1195
- package/dist/universalExport/index.js.map +1 -1
- package/dist/universalExport/index.mjs +2 -1157
- package/dist/universalExport/index.mjs.map +1 -1
- package/dist/universalExport/server/index.js +5 -3
- package/dist/universalExport/server/index.js.map +1 -1
- package/dist/universalExport/server/index.mjs +4 -2
- package/dist/universalExport/server/index.mjs.map +1 -1
- package/dist/universalFile/index.js +10 -7
- package/dist/universalFile/index.js.map +1 -1
- package/dist/universalFile/index.mjs +6 -2
- package/dist/universalFile/index.mjs.map +1 -1
- package/dist/universalFile/server/index.d.mts +592 -265
- package/dist/universalFile/server/index.d.ts +592 -265
- package/dist/universalFile/server/index.js +298 -5637
- package/dist/universalFile/server/index.js.map +1 -1
- package/dist/universalFile/server/index.mjs +8 -5559
- package/dist/universalFile/server/index.mjs.map +1 -1
- package/dist/utils/index.js +12 -12
- package/dist/utils/index.mjs +3 -3
- package/package.json +36 -1
- package/dist/AliyunOSSProvider-4W47OFEK.mjs +0 -6
- package/dist/AliyunOSSProvider-HCNGDJL7.js +0 -15
- package/dist/ConfigService-V6ZK273Z.mjs +0 -4
- package/dist/LocalStorageProvider-3RVPCQB3.mjs +0 -6
- package/dist/LocalStorageProvider-PP7MA5OT.js +0 -15
- package/dist/PMXParser-RNVQL76A.mjs +0 -4
- package/dist/chunk-25OFOKNF.js +0 -171
- package/dist/chunk-25OFOKNF.js.map +0 -1
- package/dist/chunk-3DXPQ4YV.mjs +0 -165
- package/dist/chunk-3DXPQ4YV.mjs.map +0 -1
- package/dist/chunk-3NHAT7D4.mjs.map +0 -1
- package/dist/chunk-BJTO5JO5.mjs +0 -10
- package/dist/chunk-CIVO4R6N.mjs +0 -37
- package/dist/chunk-CIVO4R6N.mjs.map +0 -1
- package/dist/chunk-DGUM43GV.js +0 -12
- package/dist/chunk-HDMIOOZY.mjs +0 -546
- package/dist/chunk-HDMIOOZY.mjs.map +0 -1
- package/dist/chunk-HJ6MH7J7.js +0 -552
- package/dist/chunk-HJ6MH7J7.js.map +0 -1
- package/dist/chunk-KH6RQ4J5.js +0 -28
- package/dist/chunk-KH6RQ4J5.js.map +0 -1
- package/dist/chunk-Q5EDCKQA.js +0 -336
- package/dist/chunk-Q5EDCKQA.js.map +0 -1
- package/dist/chunk-YOTQG4NP.mjs +0 -314
- package/dist/chunk-YOTQG4NP.mjs.map +0 -1
- package/dist/chunk-ZGVB35L2.mjs +0 -25
- package/dist/chunk-ZGVB35L2.mjs.map +0 -1
- package/dist/chunk-ZRAW3HXA.js +0 -43
- package/dist/chunk-ZRAW3HXA.js.map +0 -1
- package/dist/chunk-ZWQJSZEY.js.map +0 -1
|
@@ -0,0 +1,589 @@
|
|
|
1
|
+
import { comicUniverseArtworks, comicUniverseCollections } from '../../chunk-VBQFVXOW.mjs';
|
|
2
|
+
import '../../chunk-PAX4S7QM.mjs';
|
|
3
|
+
import '../../chunk-EONPKLEJ.mjs';
|
|
4
|
+
import { fileStorageProviders, fileFolders, fileMetadata } from '../../chunk-QROLPPXP.mjs';
|
|
5
|
+
import '../../chunk-76V7EKBX.mjs';
|
|
6
|
+
import '../../chunk-VTGPHE4Z.mjs';
|
|
7
|
+
import '../../chunk-K7WNCB4V.mjs';
|
|
8
|
+
import '../../chunk-AEXPAH7Z.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
|