@muhgholy/next-drive 4.23.30 → 4.23.32
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-J2OYAYYA.js → chunk-2DCZENJ2.js} +116 -10
- package/dist/chunk-2DCZENJ2.js.map +1 -0
- package/dist/{chunk-LTWWPQJA.cjs → chunk-HWNIRA6Y.cjs} +49 -6
- package/dist/chunk-HWNIRA6Y.cjs.map +1 -0
- package/dist/{chunk-DNJRZKAF.js → chunk-IWV6G7HQ.js} +49 -7
- package/dist/chunk-IWV6G7HQ.js.map +1 -0
- package/dist/{chunk-QE5EHVVA.cjs → chunk-WUG4ATLH.cjs} +150 -44
- package/dist/chunk-WUG4ATLH.cjs.map +1 -0
- package/dist/server/actions/public.d.ts.map +1 -1
- package/dist/server/config.d.ts.map +1 -1
- package/dist/server/express.cjs +12 -12
- package/dist/server/express.js +4 -4
- package/dist/server/hono.cjs +12 -12
- package/dist/server/hono.js +4 -4
- package/dist/server/index.cjs +19 -19
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/storage-adapters/google.d.ts.map +1 -1
- package/dist/server/tus.d.ts +5 -1
- package/dist/server/tus.d.ts.map +1 -1
- package/dist/tus-5LLFMVQK.cjs +20 -0
- package/dist/tus-5LLFMVQK.cjs.map +1 -0
- package/dist/tus-C4T5ZDTG.js +3 -0
- package/dist/tus-C4T5ZDTG.js.map +1 -0
- package/dist/types/server/config.d.ts +8 -0
- package/dist/types/server/config.d.ts.map +1 -1
- package/dist/types/server/express.d.ts +3 -24
- package/dist/types/server/express.d.ts.map +1 -1
- package/dist/types/server/hono.d.ts +3 -24
- package/dist/types/server/hono.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-DNJRZKAF.js.map +0 -1
- package/dist/chunk-J2OYAYYA.js.map +0 -1
- package/dist/chunk-LTWWPQJA.cjs.map +0 -1
- package/dist/chunk-QE5EHVVA.cjs.map +0 -1
- package/dist/tus-35IUZMFV.js +0 -3
- package/dist/tus-35IUZMFV.js.map +0 -1
- package/dist/tus-PK6UHGE4.cjs +0 -16
- package/dist/tus-PK6UHGE4.cjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkHWNIRA6Y_cjs = require('./chunk-HWNIRA6Y.cjs');
|
|
4
4
|
var path = require('path');
|
|
5
5
|
var fs = require('fs');
|
|
6
6
|
var crypto = require('crypto');
|
|
@@ -80,7 +80,7 @@ var handlePublicAction = async (req, res, action, config) => {
|
|
|
80
80
|
res.status(400).json({ status: 400, message: "Could not open file: missing or invalid file ID" });
|
|
81
81
|
return true;
|
|
82
82
|
}
|
|
83
|
-
const drive = await
|
|
83
|
+
const drive = await chunkHWNIRA6Y_cjs.drive_default.findById(id);
|
|
84
84
|
if (!drive) {
|
|
85
85
|
res.status(404).json({ status: 404, message: "File not found or no longer available" });
|
|
86
86
|
return true;
|
|
@@ -109,21 +109,68 @@ var handlePublicAction = async (req, res, action, config) => {
|
|
|
109
109
|
return true;
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
|
|
112
|
+
if (config.security?.publicRateLimit) {
|
|
113
|
+
const { publicRateLimit } = config.security;
|
|
114
|
+
const abuse = globalThis.__nextDrive.abuse;
|
|
115
|
+
const now = Date.now();
|
|
116
|
+
if (now - abuse.lastSweep > 6e4) {
|
|
117
|
+
abuse.lastSweep = now;
|
|
118
|
+
for (const [seenKey, seenHits] of abuse.ipHits) {
|
|
119
|
+
const fresh = seenHits.filter((t) => now - t < 36e5);
|
|
120
|
+
if (fresh.length) abuse.ipHits.set(seenKey, fresh);
|
|
121
|
+
else abuse.ipHits.delete(seenKey);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const ip = publicRateLimit.clientId?.(req) ?? (publicRateLimit.trustedHeaders ?? ["cf-connecting-ip", "x-real-ip", "x-forwarded-for"]).map((h) => req.headers[h]).find(Boolean)?.toString().split(",")[0].trim() ?? req.socket?.remoteAddress ?? "unknown";
|
|
125
|
+
const key = `serve:${ip}`;
|
|
126
|
+
const hits = (abuse.ipHits.get(key) ?? []).filter((t) => now - t < publicRateLimit.windowMinutes * 6e4);
|
|
127
|
+
if (hits.length >= publicRateLimit.max) {
|
|
128
|
+
res.status(429).json({ status: 429, message: "Too many requests, please try again later" });
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
hits.push(now);
|
|
132
|
+
abuse.ipHits.set(key, hits);
|
|
133
|
+
}
|
|
134
|
+
const itemProvider = drive.provider?.type === "GOOGLE" ? chunkHWNIRA6Y_cjs.GoogleDriveProvider : chunkHWNIRA6Y_cjs.LocalStorageProvider;
|
|
113
135
|
const itemAccountId = drive.storageAccountId ? drive.storageAccountId.toString() : void 0;
|
|
136
|
+
const fileHash = drive.information.type === "FILE" ? drive.information.hash : void 0;
|
|
137
|
+
const fileVersion = fileHash || drive._id.toString();
|
|
138
|
+
const ifNoneMatch = req.headers["if-none-match"];
|
|
114
139
|
if (action === "thumbnail") {
|
|
115
|
-
const
|
|
140
|
+
const etag2 = `"${fileVersion}-thumb"`;
|
|
116
141
|
res.setHeader("Content-Type", "image/webp");
|
|
142
|
+
res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
|
|
143
|
+
res.setHeader("ETag", etag2);
|
|
117
144
|
if (config.cors?.enabled) {
|
|
118
145
|
res.setHeader("Cross-Origin-Resource-Policy", "cross-origin");
|
|
119
146
|
}
|
|
147
|
+
if (ifNoneMatch === etag2) {
|
|
148
|
+
res.status(304).end();
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
const abuse = globalThis.__nextDrive.abuse;
|
|
152
|
+
if (config.security?.transformConcurrency && abuse.transformActive >= config.security.transformConcurrency) {
|
|
153
|
+
res.status(503).json({ status: 503, message: "Server is busy processing images, please try again later" });
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
abuse.transformActive++;
|
|
157
|
+
let stream2;
|
|
158
|
+
try {
|
|
159
|
+
stream2 = await itemProvider.getThumbnail(drive, itemAccountId);
|
|
160
|
+
} finally {
|
|
161
|
+
abuse.transformActive--;
|
|
162
|
+
}
|
|
163
|
+
req.on("close", () => {
|
|
164
|
+
if (!res.writableEnded) stream2.destroy();
|
|
165
|
+
});
|
|
120
166
|
stream2.pipe(res);
|
|
121
167
|
return true;
|
|
122
168
|
}
|
|
123
169
|
const { stream, mime, size: fileSize } = await itemProvider.openStream(drive, itemAccountId);
|
|
124
170
|
const safeFilename = sanitizeContentDispositionFilename(drive.name);
|
|
125
171
|
const format = req.query.format;
|
|
126
|
-
const
|
|
172
|
+
const rawQuality = req.query.quality;
|
|
173
|
+
const quality = rawQuality && !isNaN(Number(rawQuality)) ? String(Math.round(Number(rawQuality) / 10) * 10) : rawQuality;
|
|
127
174
|
const display = req.query.display;
|
|
128
175
|
const sizePreset = req.query.size;
|
|
129
176
|
const fit = req.query.fit;
|
|
@@ -136,7 +183,7 @@ var handlePublicAction = async (req, res, action, config) => {
|
|
|
136
183
|
}
|
|
137
184
|
if (shouldTransform) {
|
|
138
185
|
try {
|
|
139
|
-
const settings =
|
|
186
|
+
const settings = chunkHWNIRA6Y_cjs.getImageSettings(fileSize, quality, display, sizePreset, fit, position);
|
|
140
187
|
let targetFormat = format || mime.split("/")[1];
|
|
141
188
|
if (targetFormat === "jpg") targetFormat = "jpeg";
|
|
142
189
|
if (!["jpeg", "png", "webp", "avif"].includes(targetFormat)) {
|
|
@@ -153,21 +200,49 @@ var handlePublicAction = async (req, res, action, config) => {
|
|
|
153
200
|
targetFormat
|
|
154
201
|
].join("_");
|
|
155
202
|
const cachePath = path__default.default.join(cacheDir, `${cacheKey}.bin`);
|
|
203
|
+
const etag2 = `"${fileVersion}-${cacheKey}"`;
|
|
204
|
+
res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
|
|
205
|
+
res.setHeader("ETag", etag2);
|
|
206
|
+
if (ifNoneMatch === etag2) {
|
|
207
|
+
if ("destroy" in stream) {
|
|
208
|
+
stream.destroy();
|
|
209
|
+
}
|
|
210
|
+
res.status(304).end();
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
156
213
|
if (fs__default.default.existsSync(cachePath)) {
|
|
157
214
|
const cacheStat = fs__default.default.statSync(cachePath);
|
|
158
215
|
res.setHeader("Content-Type", `image/${targetFormat}`);
|
|
159
216
|
res.setHeader("Content-Length", cacheStat.size);
|
|
160
|
-
res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
|
|
161
217
|
if (config.cors?.enabled) {
|
|
162
218
|
res.setHeader("Cross-Origin-Resource-Policy", "cross-origin");
|
|
163
219
|
}
|
|
164
220
|
if ("destroy" in stream) {
|
|
165
221
|
stream.destroy();
|
|
166
222
|
}
|
|
167
|
-
fs__default.default.createReadStream(cachePath)
|
|
223
|
+
const cachedStream = fs__default.default.createReadStream(cachePath);
|
|
224
|
+
req.on("close", () => {
|
|
225
|
+
if (!res.writableEnded) cachedStream.destroy();
|
|
226
|
+
});
|
|
227
|
+
cachedStream.pipe(res);
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
const abuse = globalThis.__nextDrive.abuse;
|
|
231
|
+
if (config.security?.transformConcurrency && abuse.transformActive >= config.security.transformConcurrency) {
|
|
232
|
+
if ("destroy" in stream) {
|
|
233
|
+
stream.destroy();
|
|
234
|
+
}
|
|
235
|
+
res.status(503).json({ status: 503, message: "Server is busy processing images, please try again later" });
|
|
168
236
|
return true;
|
|
169
237
|
}
|
|
170
238
|
if (!fs__default.default.existsSync(cacheDir)) fs__default.default.mkdirSync(cacheDir, { recursive: true });
|
|
239
|
+
if (config.security?.cacheMaxAgeDays) {
|
|
240
|
+
const maxAgeMs = config.security.cacheMaxAgeDays * 24 * 60 * 60 * 1e3;
|
|
241
|
+
for (const entry of fs__default.default.readdirSync(cacheDir)) {
|
|
242
|
+
const entryPath = path__default.default.join(cacheDir, entry);
|
|
243
|
+
if (Date.now() - fs__default.default.statSync(entryPath).mtimeMs > maxAgeMs) fs__default.default.unlinkSync(entryPath);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
171
246
|
let pipeline = sharp__default.default();
|
|
172
247
|
if (settings.width && settings.height) {
|
|
173
248
|
pipeline = pipeline.resize(settings.width, settings.height, {
|
|
@@ -191,20 +266,43 @@ var handlePublicAction = async (req, res, action, config) => {
|
|
|
191
266
|
pipeline = pipeline.avif({ quality: settings.quality, effort: settings.effort });
|
|
192
267
|
res.setHeader("Content-Type", "image/avif");
|
|
193
268
|
}
|
|
194
|
-
|
|
269
|
+
abuse.transformActive++;
|
|
195
270
|
pipeline.on("error", (err) => {
|
|
271
|
+
abuse.transformActive--;
|
|
196
272
|
console.error("[next-drive] Pipeline error:", err);
|
|
197
273
|
});
|
|
274
|
+
pipeline.on("close", () => {
|
|
275
|
+
abuse.transformActive--;
|
|
276
|
+
});
|
|
198
277
|
stream.pipe(pipeline);
|
|
278
|
+
const outStream = pipeline.clone().pipe(res);
|
|
279
|
+
req.on("close", () => {
|
|
280
|
+
if (!res.writableEnded) outStream.destroy();
|
|
281
|
+
});
|
|
199
282
|
pipeline.clone().toFile(cachePath).catch((e) => console.error("[next-drive] Cache write failed:", e));
|
|
200
|
-
pipeline.clone().pipe(res);
|
|
201
283
|
return true;
|
|
202
284
|
} catch (e) {
|
|
203
285
|
console.error("[next-drive] Image transformation failed:", e);
|
|
204
286
|
}
|
|
205
287
|
}
|
|
288
|
+
const etag = `"${fileVersion}"`;
|
|
206
289
|
res.setHeader("Content-Type", mime);
|
|
207
290
|
if (fileSize) res.setHeader("Content-Length", fileSize);
|
|
291
|
+
res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
|
|
292
|
+
res.setHeader("ETag", etag);
|
|
293
|
+
if (ifNoneMatch === etag) {
|
|
294
|
+
if ("destroy" in stream) {
|
|
295
|
+
stream.destroy();
|
|
296
|
+
}
|
|
297
|
+
res.status(304).end();
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
if ("destroy" in stream) {
|
|
301
|
+
const destroyable = stream;
|
|
302
|
+
req.on("close", () => {
|
|
303
|
+
if (!res.writableEnded) destroyable.destroy();
|
|
304
|
+
});
|
|
305
|
+
}
|
|
208
306
|
stream.pipe(res);
|
|
209
307
|
return true;
|
|
210
308
|
} catch (error) {
|
|
@@ -261,13 +359,13 @@ var handleAuthAction = async (req, res, action, config, owner) => {
|
|
|
261
359
|
oAuth2Client.setCredentials(tokens);
|
|
262
360
|
const oauth2 = googleapis.google.oauth2({ version: "v2", auth: oAuth2Client });
|
|
263
361
|
const userInfo = await oauth2.userinfo.get();
|
|
264
|
-
const existing = await
|
|
362
|
+
const existing = await chunkHWNIRA6Y_cjs.account_default.findOne({ owner, "metadata.google.email": userInfo.data.email, "metadata.provider": "GOOGLE" });
|
|
265
363
|
if (existing) {
|
|
266
364
|
existing.metadata.google.credentials = tokens;
|
|
267
365
|
existing.markModified("metadata");
|
|
268
366
|
await existing.save();
|
|
269
367
|
} else {
|
|
270
|
-
const newAccount = new
|
|
368
|
+
const newAccount = new chunkHWNIRA6Y_cjs.account_default({
|
|
271
369
|
owner,
|
|
272
370
|
name: userInfo.data.name || "Google Drive",
|
|
273
371
|
metadata: {
|
|
@@ -308,7 +406,7 @@ var handleAuthAction = async (req, res, action, config, owner) => {
|
|
|
308
406
|
return true;
|
|
309
407
|
}
|
|
310
408
|
case "listAccounts": {
|
|
311
|
-
const accounts = await
|
|
409
|
+
const accounts = await chunkHWNIRA6Y_cjs.account_default.find({ owner });
|
|
312
410
|
res.status(200).json({
|
|
313
411
|
status: 200,
|
|
314
412
|
data: {
|
|
@@ -324,20 +422,20 @@ var handleAuthAction = async (req, res, action, config, owner) => {
|
|
|
324
422
|
}
|
|
325
423
|
case "removeAccount": {
|
|
326
424
|
const { id } = req.query;
|
|
327
|
-
const account = await
|
|
425
|
+
const account = await chunkHWNIRA6Y_cjs.account_default.findOne({ _id: id, owner });
|
|
328
426
|
if (!account) {
|
|
329
427
|
res.status(404).json({ status: 404, message: "Could not disconnect: account not found" });
|
|
330
428
|
return true;
|
|
331
429
|
}
|
|
332
430
|
if (account.metadata.provider === "GOOGLE") {
|
|
333
431
|
try {
|
|
334
|
-
await
|
|
432
|
+
await chunkHWNIRA6Y_cjs.GoogleDriveProvider.revokeToken(owner, account._id.toString());
|
|
335
433
|
} catch (e) {
|
|
336
434
|
console.error("Failed to revoke Google token:", e);
|
|
337
435
|
}
|
|
338
436
|
}
|
|
339
|
-
await
|
|
340
|
-
await
|
|
437
|
+
await chunkHWNIRA6Y_cjs.account_default.deleteOne({ _id: id, owner });
|
|
438
|
+
await chunkHWNIRA6Y_cjs.drive_default.deleteMany({ owner, storageAccountId: id });
|
|
341
439
|
res.status(200).json({ status: 200, message: "Account removed" });
|
|
342
440
|
return true;
|
|
343
441
|
}
|
|
@@ -442,8 +540,8 @@ var handleDriveAction = async (ctx) => {
|
|
|
442
540
|
query.owner = owner;
|
|
443
541
|
}
|
|
444
542
|
if (afterId) query._id = { $lt: afterId };
|
|
445
|
-
const items = await
|
|
446
|
-
const plainItems =
|
|
543
|
+
const items = await chunkHWNIRA6Y_cjs.drive_default.find(query, {}, { sort: { order: 1, _id: -1 }, limit });
|
|
544
|
+
const plainItems = chunkHWNIRA6Y_cjs.withSignedUrls(await Promise.all(items.map((item) => item.toClient())), config);
|
|
447
545
|
res.status(200).json({ status: 200, message: "Items retrieved", data: { items: plainItems, hasMore: items.length === limit } });
|
|
448
546
|
return;
|
|
449
547
|
}
|
|
@@ -468,20 +566,20 @@ var handleDriveAction = async (ctx) => {
|
|
|
468
566
|
query.owner = owner;
|
|
469
567
|
}
|
|
470
568
|
if (folderId && folderId !== "root") query.parentId = folderId;
|
|
471
|
-
const items = await
|
|
472
|
-
const plainItems =
|
|
569
|
+
const items = await chunkHWNIRA6Y_cjs.drive_default.find(query, {}, { limit, sort: { createdAt: -1 } });
|
|
570
|
+
const plainItems = chunkHWNIRA6Y_cjs.withSignedUrls(await Promise.all(items.map((i) => i.toClient())), config);
|
|
473
571
|
res.status(200).json({ status: 200, message: "Results", data: { items: plainItems } });
|
|
474
572
|
return;
|
|
475
573
|
}
|
|
476
574
|
case "upload": {
|
|
477
|
-
await
|
|
575
|
+
await chunkHWNIRA6Y_cjs.handleUpload(req, res, { config, owner, authenticated, isRootMode, information, provider, accountId });
|
|
478
576
|
return;
|
|
479
577
|
}
|
|
480
578
|
case "createFolder": {
|
|
481
579
|
const folderData = createFolderBodySchema.safeParse(req.body);
|
|
482
580
|
if (!folderData.success) return void res.status(400).json({ status: 400, message: folderData.error.errors[0].message });
|
|
483
581
|
const { name, parentId } = folderData.data;
|
|
484
|
-
const item =
|
|
582
|
+
const item = chunkHWNIRA6Y_cjs.withSignedUrl(await provider.createFolder(name, parentId ?? null, owner, accountId), config);
|
|
485
583
|
res.status(201).json({ status: 201, message: "Folder created", data: { item } });
|
|
486
584
|
return;
|
|
487
585
|
}
|
|
@@ -489,9 +587,9 @@ var handleDriveAction = async (ctx) => {
|
|
|
489
587
|
const deleteData = deleteQuerySchema.safeParse(req.query);
|
|
490
588
|
if (!deleteData.success) return void res.status(400).json({ status: 400, message: "Could not move to trash: invalid ID" });
|
|
491
589
|
const { id } = deleteData.data;
|
|
492
|
-
const drive = await
|
|
590
|
+
const drive = await chunkHWNIRA6Y_cjs.drive_default.findById(id);
|
|
493
591
|
if (!drive) return void res.status(404).json({ status: 404, message: "Could not move to trash: item not found" });
|
|
494
|
-
const itemProvider = drive.provider?.type === "GOOGLE" ?
|
|
592
|
+
const itemProvider = drive.provider?.type === "GOOGLE" ? chunkHWNIRA6Y_cjs.GoogleDriveProvider : chunkHWNIRA6Y_cjs.LocalStorageProvider;
|
|
495
593
|
const itemAccountId = drive.storageAccountId ? drive.storageAccountId.toString() : void 0;
|
|
496
594
|
try {
|
|
497
595
|
await itemProvider.trash([id], owner, itemAccountId);
|
|
@@ -529,7 +627,7 @@ var handleDriveAction = async (ctx) => {
|
|
|
529
627
|
}
|
|
530
628
|
case "trash": {
|
|
531
629
|
try {
|
|
532
|
-
const { provider: trashProvider, accountId: trashAccountId } = await
|
|
630
|
+
const { provider: trashProvider, accountId: trashAccountId } = await chunkHWNIRA6Y_cjs.resolveProvider(req, owner);
|
|
533
631
|
await trashProvider.syncTrash(owner, trashAccountId);
|
|
534
632
|
} catch (e) {
|
|
535
633
|
console.error("Trash sync failed", e);
|
|
@@ -540,8 +638,8 @@ var handleDriveAction = async (ctx) => {
|
|
|
540
638
|
storageAccountId: accountId || null,
|
|
541
639
|
trashedAt: { $ne: null }
|
|
542
640
|
};
|
|
543
|
-
const items = await
|
|
544
|
-
const plainItems =
|
|
641
|
+
const items = await chunkHWNIRA6Y_cjs.drive_default.find(query, {}, { sort: { trashedAt: -1 } });
|
|
642
|
+
const plainItems = chunkHWNIRA6Y_cjs.withSignedUrls(await Promise.all(items.map((item) => item.toClient())), config);
|
|
545
643
|
res.status(200).json({ status: 200, message: "Trash items", data: { items: plainItems, hasMore: false } });
|
|
546
644
|
return;
|
|
547
645
|
}
|
|
@@ -549,16 +647,16 @@ var handleDriveAction = async (ctx) => {
|
|
|
549
647
|
const restoreData = deleteQuerySchema.safeParse(req.query);
|
|
550
648
|
if (!restoreData.success) return void res.status(400).json({ status: 400, message: "Could not restore: invalid ID" });
|
|
551
649
|
const { id } = restoreData.data;
|
|
552
|
-
const drive = await
|
|
650
|
+
const drive = await chunkHWNIRA6Y_cjs.drive_default.findById(id);
|
|
553
651
|
if (!drive) return void res.status(404).json({ status: 404, message: "Could not restore: item not found" });
|
|
554
652
|
let targetParentId = drive.parentId;
|
|
555
653
|
if (targetParentId) {
|
|
556
|
-
const parent = await
|
|
654
|
+
const parent = await chunkHWNIRA6Y_cjs.drive_default.findById(targetParentId);
|
|
557
655
|
if (parent?.trashedAt) {
|
|
558
656
|
targetParentId = null;
|
|
559
657
|
}
|
|
560
658
|
}
|
|
561
|
-
const itemProvider = drive.provider?.type === "GOOGLE" ?
|
|
659
|
+
const itemProvider = drive.provider?.type === "GOOGLE" ? chunkHWNIRA6Y_cjs.GoogleDriveProvider : chunkHWNIRA6Y_cjs.LocalStorageProvider;
|
|
562
660
|
const itemAccountId = drive.storageAccountId ? drive.storageAccountId.toString() : void 0;
|
|
563
661
|
try {
|
|
564
662
|
await itemProvider.untrash([id], owner, itemAccountId);
|
|
@@ -592,7 +690,7 @@ var handleDriveAction = async (ctx) => {
|
|
|
592
690
|
console.error(`Failed to move item ${id}`, e);
|
|
593
691
|
}
|
|
594
692
|
}
|
|
595
|
-
res.status(200).json({ status: 200, message: "Moved", data: { items:
|
|
693
|
+
res.status(200).json({ status: 200, message: "Moved", data: { items: chunkHWNIRA6Y_cjs.withSignedUrls(items, config) } });
|
|
596
694
|
return;
|
|
597
695
|
}
|
|
598
696
|
case "reorder": {
|
|
@@ -613,7 +711,7 @@ var handleDriveAction = async (ctx) => {
|
|
|
613
711
|
if (!isRootMode) {
|
|
614
712
|
query.owner = owner;
|
|
615
713
|
}
|
|
616
|
-
const existingItems = await
|
|
714
|
+
const existingItems = await chunkHWNIRA6Y_cjs.drive_default.find(query, { _id: 1, parentId: 1 });
|
|
617
715
|
if (existingItems.length !== ids.length) {
|
|
618
716
|
return void res.status(404).json({ status: 404, message: "Could not reorder: one or more items were not found" });
|
|
619
717
|
}
|
|
@@ -633,9 +731,9 @@ var handleDriveAction = async (ctx) => {
|
|
|
633
731
|
update: { $set: { order } }
|
|
634
732
|
}
|
|
635
733
|
}));
|
|
636
|
-
await
|
|
637
|
-
const updatedItems = await
|
|
638
|
-
const plainItems =
|
|
734
|
+
await chunkHWNIRA6Y_cjs.drive_default.bulkWrite(operations);
|
|
735
|
+
const updatedItems = await chunkHWNIRA6Y_cjs.drive_default.find(query, {}, { sort: { order: 1 } });
|
|
736
|
+
const plainItems = chunkHWNIRA6Y_cjs.withSignedUrls(await Promise.all(updatedItems.map((item) => item.toClient())), config);
|
|
639
737
|
res.status(200).json({ status: 200, message: "Reordered", data: { items: plainItems } });
|
|
640
738
|
return;
|
|
641
739
|
}
|
|
@@ -643,7 +741,7 @@ var handleDriveAction = async (ctx) => {
|
|
|
643
741
|
const renameData = renameBodySchema.safeParse({ id: req.query.id, ...req.body });
|
|
644
742
|
if (!renameData.success) return void res.status(400).json({ status: 400, message: "Could not rename: invalid request data" });
|
|
645
743
|
const { id, newName } = renameData.data;
|
|
646
|
-
const item =
|
|
744
|
+
const item = chunkHWNIRA6Y_cjs.withSignedUrl(await provider.rename(id, newName, owner, accountId), config);
|
|
647
745
|
res.status(200).json({ status: 200, message: "Renamed", data: { item } });
|
|
648
746
|
return;
|
|
649
747
|
}
|
|
@@ -659,7 +757,15 @@ var parseJsonBody = (req) => {
|
|
|
659
757
|
return new Promise((resolve) => {
|
|
660
758
|
try {
|
|
661
759
|
const chunks = [];
|
|
662
|
-
|
|
760
|
+
let totalBytes = 0;
|
|
761
|
+
req.on("data", (chunk) => {
|
|
762
|
+
totalBytes += chunk.length;
|
|
763
|
+
if (totalBytes > 1024 * 1024) {
|
|
764
|
+
req.destroy();
|
|
765
|
+
return resolve({});
|
|
766
|
+
}
|
|
767
|
+
chunks.push(chunk);
|
|
768
|
+
});
|
|
663
769
|
req.on("end", () => {
|
|
664
770
|
const raw = Buffer.concat(chunks).toString();
|
|
665
771
|
if (!raw) return resolve({});
|
|
@@ -684,7 +790,7 @@ var driveAPIHandler = async (req, res) => {
|
|
|
684
790
|
const action = req.query.action || (req.query.code && req.query.state ? "callback" : void 0);
|
|
685
791
|
let config;
|
|
686
792
|
try {
|
|
687
|
-
config =
|
|
793
|
+
config = chunkHWNIRA6Y_cjs.getDriveConfig();
|
|
688
794
|
} catch (error) {
|
|
689
795
|
console.error("[next-drive] Configuration error:", error);
|
|
690
796
|
res.status(500).json({ status: 500, message: "Drive is not ready: failed to initialize configuration" });
|
|
@@ -705,7 +811,7 @@ var driveAPIHandler = async (req, res) => {
|
|
|
705
811
|
const googleConfigured = !!(clientId && clientSecret && redirectUri);
|
|
706
812
|
let authenticated2 = false;
|
|
707
813
|
try {
|
|
708
|
-
await
|
|
814
|
+
await chunkHWNIRA6Y_cjs.getDriveInformation({ method: "REQUEST", req });
|
|
709
815
|
authenticated2 = true;
|
|
710
816
|
} catch {
|
|
711
817
|
authenticated2 = false;
|
|
@@ -728,7 +834,7 @@ var driveAPIHandler = async (req, res) => {
|
|
|
728
834
|
let information;
|
|
729
835
|
let authenticated = true;
|
|
730
836
|
try {
|
|
731
|
-
information = await
|
|
837
|
+
information = await chunkHWNIRA6Y_cjs.getDriveInformation({ method: "REQUEST", req });
|
|
732
838
|
} catch (err) {
|
|
733
839
|
if (action === "upload" && config.security?.unauthenticated?.enabled) {
|
|
734
840
|
information = { key: null, storage: { quotaInBytes: 0 } };
|
|
@@ -740,7 +846,7 @@ var driveAPIHandler = async (req, res) => {
|
|
|
740
846
|
const { key: owner } = information;
|
|
741
847
|
const wasAuthHandled = await handleAuthAction(req, res, action, config, owner);
|
|
742
848
|
if (wasAuthHandled) return;
|
|
743
|
-
const { provider, accountId } = await
|
|
849
|
+
const { provider, accountId } = await chunkHWNIRA6Y_cjs.resolveProvider(req, owner);
|
|
744
850
|
await handleDriveAction({
|
|
745
851
|
req,
|
|
746
852
|
res,
|
|
@@ -762,5 +868,5 @@ var driveAPIHandler = async (req, res) => {
|
|
|
762
868
|
|
|
763
869
|
exports.driveAPIHandler = driveAPIHandler;
|
|
764
870
|
exports.driveFileSchemaZod = driveFileSchemaZod;
|
|
765
|
-
//# sourceMappingURL=chunk-
|
|
766
|
-
//# sourceMappingURL=chunk-
|
|
871
|
+
//# sourceMappingURL=chunk-WUG4ATLH.cjs.map
|
|
872
|
+
//# sourceMappingURL=chunk-WUG4ATLH.cjs.map
|