@muhgholy/next-drive 4.3.0 → 4.4.0
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/{chunk-MTGJTRD5.js → chunk-5CAP2MNG.js} +41 -10
- package/dist/chunk-5CAP2MNG.js.map +1 -0
- package/dist/{chunk-25MNL2OG.cjs → chunk-ZNXH3LYN.cjs} +41 -10
- package/dist/chunk-ZNXH3LYN.cjs.map +1 -0
- package/dist/server/config.d.ts.map +1 -1
- package/dist/server/express.cjs +11 -11
- package/dist/server/express.js +2 -2
- package/dist/server/index.cjs +13 -13
- package/dist/server/index.js +1 -1
- package/dist/server/utils/migration.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-25MNL2OG.cjs.map +0 -1
- package/dist/chunk-MTGJTRD5.js.map +0 -1
|
@@ -68,6 +68,24 @@ var drive_default = Drive;
|
|
|
68
68
|
// src/server/utils/migration.ts
|
|
69
69
|
var MIGRATION_FILE = ".migration-version";
|
|
70
70
|
var CURRENT_VERSION = 1;
|
|
71
|
+
var isReadyForMigration = () => {
|
|
72
|
+
if (mongoose.connection.readyState !== 1) {
|
|
73
|
+
console.warn("[next-drive] Migration skipped: Database not connected");
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
};
|
|
78
|
+
var isNewInstallation = (storagePath) => {
|
|
79
|
+
if (!fs.existsSync(storagePath)) return true;
|
|
80
|
+
const hasOldDriveDir = fs.existsSync(path.join(storagePath, "drive"));
|
|
81
|
+
const hasOldCacheDir = fs.existsSync(path.join(storagePath, "cache", "thumbnails"));
|
|
82
|
+
const hasOldLibraryDir = fs.existsSync(path.join(storagePath, "library", "google"));
|
|
83
|
+
const hasRootLevelFiles = fs.existsSync(storagePath) && fs.readdirSync(storagePath).some((entry) => {
|
|
84
|
+
const entryPath = path.join(storagePath, entry);
|
|
85
|
+
return fs.statSync(entryPath).isDirectory() && /^[a-f0-9]{24}$/i.test(entry) && entry !== "file";
|
|
86
|
+
});
|
|
87
|
+
return !hasOldDriveDir && !hasOldCacheDir && !hasOldLibraryDir && !hasRootLevelFiles;
|
|
88
|
+
};
|
|
71
89
|
var migrations = [
|
|
72
90
|
{
|
|
73
91
|
version: 1,
|
|
@@ -185,6 +203,12 @@ var migrations = [
|
|
|
185
203
|
}
|
|
186
204
|
];
|
|
187
205
|
var runMigrations = async (storagePath) => {
|
|
206
|
+
if (!isReadyForMigration()) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (!fs.existsSync(storagePath)) {
|
|
210
|
+
fs.mkdirSync(storagePath, { recursive: true });
|
|
211
|
+
}
|
|
188
212
|
const versionFile = path.join(storagePath, MIGRATION_FILE);
|
|
189
213
|
let currentVersion = 0;
|
|
190
214
|
if (fs.existsSync(versionFile)) {
|
|
@@ -195,8 +219,10 @@ var runMigrations = async (storagePath) => {
|
|
|
195
219
|
}
|
|
196
220
|
}
|
|
197
221
|
if (currentVersion >= CURRENT_VERSION) return;
|
|
198
|
-
if (
|
|
199
|
-
|
|
222
|
+
if (isNewInstallation(storagePath)) {
|
|
223
|
+
console.log("[next-drive] New installation detected, skipping migration");
|
|
224
|
+
fs.writeFileSync(versionFile, String(CURRENT_VERSION));
|
|
225
|
+
return;
|
|
200
226
|
}
|
|
201
227
|
const pendingMigrations = migrations.filter((m) => m.version > currentVersion);
|
|
202
228
|
for (const migration of pendingMigrations.sort((a, b) => a.version - b.version)) {
|
|
@@ -213,14 +239,15 @@ var runMigrations = async (storagePath) => {
|
|
|
213
239
|
|
|
214
240
|
// src/server/config.ts
|
|
215
241
|
var globalConfig = null;
|
|
216
|
-
var
|
|
242
|
+
var migrationPromise = null;
|
|
243
|
+
var configInitialized = false;
|
|
217
244
|
var driveConfiguration = async (config) => {
|
|
218
245
|
if (mongoose.connection.readyState !== 1) {
|
|
219
246
|
throw new Error("Database not connected. Please connect to Mongoose before initializing next-drive.");
|
|
220
247
|
}
|
|
221
|
-
if (
|
|
222
|
-
|
|
223
|
-
|
|
248
|
+
if (configInitialized && globalConfig) {
|
|
249
|
+
if (migrationPromise) await migrationPromise;
|
|
250
|
+
return globalConfig;
|
|
224
251
|
}
|
|
225
252
|
const mode = config.mode || "NORMAL";
|
|
226
253
|
if (mode === "ROOT") {
|
|
@@ -233,7 +260,6 @@ var driveConfiguration = async (config) => {
|
|
|
233
260
|
allowedMimeTypes: ["*/*"]
|
|
234
261
|
}
|
|
235
262
|
};
|
|
236
|
-
return globalConfig;
|
|
237
263
|
} else {
|
|
238
264
|
if (!config.information) {
|
|
239
265
|
throw new Error("information callback is required in NORMAL mode");
|
|
@@ -249,8 +275,13 @@ var driveConfiguration = async (config) => {
|
|
|
249
275
|
},
|
|
250
276
|
information: config.information
|
|
251
277
|
};
|
|
252
|
-
return globalConfig;
|
|
253
278
|
}
|
|
279
|
+
configInitialized = true;
|
|
280
|
+
if (!migrationPromise) {
|
|
281
|
+
migrationPromise = runMigrations(config.storage.path);
|
|
282
|
+
}
|
|
283
|
+
await migrationPromise;
|
|
284
|
+
return globalConfig;
|
|
254
285
|
};
|
|
255
286
|
var getDriveConfig = () => {
|
|
256
287
|
if (!globalConfig) throw new Error("Drive configuration not initialized");
|
|
@@ -2050,5 +2081,5 @@ var driveAPIHandler = async (req, res) => {
|
|
|
2050
2081
|
};
|
|
2051
2082
|
|
|
2052
2083
|
export { driveAPIHandler, driveConfiguration, driveDelete, driveFilePath, driveFileSchemaZod, driveGetUrl, driveInfo, driveList, driveReadFile, driveUpload, getDriveConfig, getDriveInformation };
|
|
2053
|
-
//# sourceMappingURL=chunk-
|
|
2054
|
-
//# sourceMappingURL=chunk-
|
|
2084
|
+
//# sourceMappingURL=chunk-5CAP2MNG.js.map
|
|
2085
|
+
//# sourceMappingURL=chunk-5CAP2MNG.js.map
|