@muhgholy/next-drive 4.23.33 → 4.23.34
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/README.md +79 -3
- package/dist/{chunk-HWNIRA6Y.cjs → chunk-DHIHCER6.cjs} +220 -71
- package/dist/chunk-DHIHCER6.cjs.map +1 -0
- package/dist/{chunk-2DCZENJ2.js → chunk-E72MTT6W.js} +3 -3
- package/dist/{chunk-2DCZENJ2.js.map → chunk-E72MTT6W.js.map} +1 -1
- package/dist/{chunk-WUG4ATLH.cjs → chunk-PKNXKHGS.cjs} +37 -37
- package/dist/{chunk-WUG4ATLH.cjs.map → chunk-PKNXKHGS.cjs.map} +1 -1
- package/dist/{chunk-IWV6G7HQ.js → chunk-QMPV4YSZ.js} +221 -73
- package/dist/chunk-QMPV4YSZ.js.map +1 -0
- package/dist/server/controllers/drive.d.ts +33 -2
- package/dist/server/controllers/drive.d.ts.map +1 -1
- package/dist/server/errors.d.ts +12 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/express.cjs +16 -12
- package/dist/server/express.cjs.map +1 -1
- package/dist/server/express.d.ts +3 -0
- package/dist/server/express.d.ts.map +1 -1
- package/dist/server/express.js +4 -4
- package/dist/server/express.js.map +1 -1
- package/dist/server/hono.cjs +16 -12
- package/dist/server/hono.cjs.map +1 -1
- package/dist/server/hono.d.ts +3 -0
- package/dist/server/hono.d.ts.map +1 -1
- package/dist/server/hono.js +4 -4
- package/dist/server/hono.js.map +1 -1
- package/dist/server/index.cjs +23 -19
- package/dist/server/index.d.ts +3 -0
- 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.map +1 -1
- package/dist/tus-EQ2IXSRE.cjs +20 -0
- package/dist/tus-EQ2IXSRE.cjs.map +1 -0
- package/dist/tus-ODCMFEBZ.js +3 -0
- package/dist/tus-ODCMFEBZ.js.map +1 -0
- package/dist/types/server/storage.d.ts +4 -1
- package/dist/types/server/storage.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-HWNIRA6Y.cjs.map +0 -1
- package/dist/chunk-IWV6G7HQ.js.map +0 -1
- package/dist/tus-5LLFMVQK.cjs +0 -20
- package/dist/tus-5LLFMVQK.cjs.map +0 -1
- package/dist/tus-C4T5ZDTG.js +0 -3
- package/dist/tus-C4T5ZDTG.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkDHIHCER6_cjs = require('./chunk-DHIHCER6.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 chunkDHIHCER6_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;
|
|
@@ -131,7 +131,7 @@ var handlePublicAction = async (req, res, action, config) => {
|
|
|
131
131
|
hits.push(now);
|
|
132
132
|
abuse.ipHits.set(key, hits);
|
|
133
133
|
}
|
|
134
|
-
const itemProvider = drive.provider?.type === "GOOGLE" ?
|
|
134
|
+
const itemProvider = drive.provider?.type === "GOOGLE" ? chunkDHIHCER6_cjs.GoogleDriveProvider : chunkDHIHCER6_cjs.LocalStorageProvider;
|
|
135
135
|
const itemAccountId = drive.storageAccountId ? drive.storageAccountId.toString() : void 0;
|
|
136
136
|
const fileHash = drive.information.type === "FILE" ? drive.information.hash : void 0;
|
|
137
137
|
const fileVersion = fileHash || drive._id.toString();
|
|
@@ -183,7 +183,7 @@ var handlePublicAction = async (req, res, action, config) => {
|
|
|
183
183
|
}
|
|
184
184
|
if (shouldTransform) {
|
|
185
185
|
try {
|
|
186
|
-
const settings =
|
|
186
|
+
const settings = chunkDHIHCER6_cjs.getImageSettings(fileSize, quality, display, sizePreset, fit, position);
|
|
187
187
|
let targetFormat = format || mime.split("/")[1];
|
|
188
188
|
if (targetFormat === "jpg") targetFormat = "jpeg";
|
|
189
189
|
if (!["jpeg", "png", "webp", "avif"].includes(targetFormat)) {
|
|
@@ -359,13 +359,13 @@ var handleAuthAction = async (req, res, action, config, owner) => {
|
|
|
359
359
|
oAuth2Client.setCredentials(tokens);
|
|
360
360
|
const oauth2 = googleapis.google.oauth2({ version: "v2", auth: oAuth2Client });
|
|
361
361
|
const userInfo = await oauth2.userinfo.get();
|
|
362
|
-
const existing = await
|
|
362
|
+
const existing = await chunkDHIHCER6_cjs.account_default.findOne({ owner, "metadata.google.email": userInfo.data.email, "metadata.provider": "GOOGLE" });
|
|
363
363
|
if (existing) {
|
|
364
364
|
existing.metadata.google.credentials = tokens;
|
|
365
365
|
existing.markModified("metadata");
|
|
366
366
|
await existing.save();
|
|
367
367
|
} else {
|
|
368
|
-
const newAccount = new
|
|
368
|
+
const newAccount = new chunkDHIHCER6_cjs.account_default({
|
|
369
369
|
owner,
|
|
370
370
|
name: userInfo.data.name || "Google Drive",
|
|
371
371
|
metadata: {
|
|
@@ -406,7 +406,7 @@ var handleAuthAction = async (req, res, action, config, owner) => {
|
|
|
406
406
|
return true;
|
|
407
407
|
}
|
|
408
408
|
case "listAccounts": {
|
|
409
|
-
const accounts = await
|
|
409
|
+
const accounts = await chunkDHIHCER6_cjs.account_default.find({ owner });
|
|
410
410
|
res.status(200).json({
|
|
411
411
|
status: 200,
|
|
412
412
|
data: {
|
|
@@ -422,20 +422,20 @@ var handleAuthAction = async (req, res, action, config, owner) => {
|
|
|
422
422
|
}
|
|
423
423
|
case "removeAccount": {
|
|
424
424
|
const { id } = req.query;
|
|
425
|
-
const account = await
|
|
425
|
+
const account = await chunkDHIHCER6_cjs.account_default.findOne({ _id: id, owner });
|
|
426
426
|
if (!account) {
|
|
427
427
|
res.status(404).json({ status: 404, message: "Could not disconnect: account not found" });
|
|
428
428
|
return true;
|
|
429
429
|
}
|
|
430
430
|
if (account.metadata.provider === "GOOGLE") {
|
|
431
431
|
try {
|
|
432
|
-
await
|
|
432
|
+
await chunkDHIHCER6_cjs.GoogleDriveProvider.revokeToken(owner, account._id.toString());
|
|
433
433
|
} catch (e) {
|
|
434
434
|
console.error("Failed to revoke Google token:", e);
|
|
435
435
|
}
|
|
436
436
|
}
|
|
437
|
-
await
|
|
438
|
-
await
|
|
437
|
+
await chunkDHIHCER6_cjs.account_default.deleteOne({ _id: id, owner });
|
|
438
|
+
await chunkDHIHCER6_cjs.drive_default.deleteMany({ owner, storageAccountId: id });
|
|
439
439
|
res.status(200).json({ status: 200, message: "Account removed" });
|
|
440
440
|
return true;
|
|
441
441
|
}
|
|
@@ -540,8 +540,8 @@ var handleDriveAction = async (ctx) => {
|
|
|
540
540
|
query.owner = owner;
|
|
541
541
|
}
|
|
542
542
|
if (afterId) query._id = { $lt: afterId };
|
|
543
|
-
const items = await
|
|
544
|
-
const plainItems =
|
|
543
|
+
const items = await chunkDHIHCER6_cjs.drive_default.find(query, {}, { sort: { order: 1, _id: -1 }, limit });
|
|
544
|
+
const plainItems = chunkDHIHCER6_cjs.withSignedUrls(await Promise.all(items.map((item) => item.toClient())), config);
|
|
545
545
|
res.status(200).json({ status: 200, message: "Items retrieved", data: { items: plainItems, hasMore: items.length === limit } });
|
|
546
546
|
return;
|
|
547
547
|
}
|
|
@@ -566,20 +566,20 @@ var handleDriveAction = async (ctx) => {
|
|
|
566
566
|
query.owner = owner;
|
|
567
567
|
}
|
|
568
568
|
if (folderId && folderId !== "root") query.parentId = folderId;
|
|
569
|
-
const items = await
|
|
570
|
-
const plainItems =
|
|
569
|
+
const items = await chunkDHIHCER6_cjs.drive_default.find(query, {}, { limit, sort: { createdAt: -1 } });
|
|
570
|
+
const plainItems = chunkDHIHCER6_cjs.withSignedUrls(await Promise.all(items.map((i) => i.toClient())), config);
|
|
571
571
|
res.status(200).json({ status: 200, message: "Results", data: { items: plainItems } });
|
|
572
572
|
return;
|
|
573
573
|
}
|
|
574
574
|
case "upload": {
|
|
575
|
-
await
|
|
575
|
+
await chunkDHIHCER6_cjs.handleUpload(req, res, { config, owner, authenticated, isRootMode, information, provider, accountId });
|
|
576
576
|
return;
|
|
577
577
|
}
|
|
578
578
|
case "createFolder": {
|
|
579
579
|
const folderData = createFolderBodySchema.safeParse(req.body);
|
|
580
580
|
if (!folderData.success) return void res.status(400).json({ status: 400, message: folderData.error.errors[0].message });
|
|
581
581
|
const { name, parentId } = folderData.data;
|
|
582
|
-
const item =
|
|
582
|
+
const item = chunkDHIHCER6_cjs.withSignedUrl(await provider.createFolder(name, parentId ?? null, owner, accountId), config);
|
|
583
583
|
res.status(201).json({ status: 201, message: "Folder created", data: { item } });
|
|
584
584
|
return;
|
|
585
585
|
}
|
|
@@ -587,9 +587,9 @@ var handleDriveAction = async (ctx) => {
|
|
|
587
587
|
const deleteData = deleteQuerySchema.safeParse(req.query);
|
|
588
588
|
if (!deleteData.success) return void res.status(400).json({ status: 400, message: "Could not move to trash: invalid ID" });
|
|
589
589
|
const { id } = deleteData.data;
|
|
590
|
-
const drive = await
|
|
590
|
+
const drive = await chunkDHIHCER6_cjs.drive_default.findById(id);
|
|
591
591
|
if (!drive) return void res.status(404).json({ status: 404, message: "Could not move to trash: item not found" });
|
|
592
|
-
const itemProvider = drive.provider?.type === "GOOGLE" ?
|
|
592
|
+
const itemProvider = drive.provider?.type === "GOOGLE" ? chunkDHIHCER6_cjs.GoogleDriveProvider : chunkDHIHCER6_cjs.LocalStorageProvider;
|
|
593
593
|
const itemAccountId = drive.storageAccountId ? drive.storageAccountId.toString() : void 0;
|
|
594
594
|
try {
|
|
595
595
|
await itemProvider.trash([id], owner, itemAccountId);
|
|
@@ -627,7 +627,7 @@ var handleDriveAction = async (ctx) => {
|
|
|
627
627
|
}
|
|
628
628
|
case "trash": {
|
|
629
629
|
try {
|
|
630
|
-
const { provider: trashProvider, accountId: trashAccountId } = await
|
|
630
|
+
const { provider: trashProvider, accountId: trashAccountId } = await chunkDHIHCER6_cjs.resolveProvider(req, owner);
|
|
631
631
|
await trashProvider.syncTrash(owner, trashAccountId);
|
|
632
632
|
} catch (e) {
|
|
633
633
|
console.error("Trash sync failed", e);
|
|
@@ -638,8 +638,8 @@ var handleDriveAction = async (ctx) => {
|
|
|
638
638
|
storageAccountId: accountId || null,
|
|
639
639
|
trashedAt: { $ne: null }
|
|
640
640
|
};
|
|
641
|
-
const items = await
|
|
642
|
-
const plainItems =
|
|
641
|
+
const items = await chunkDHIHCER6_cjs.drive_default.find(query, {}, { sort: { trashedAt: -1 } });
|
|
642
|
+
const plainItems = chunkDHIHCER6_cjs.withSignedUrls(await Promise.all(items.map((item) => item.toClient())), config);
|
|
643
643
|
res.status(200).json({ status: 200, message: "Trash items", data: { items: plainItems, hasMore: false } });
|
|
644
644
|
return;
|
|
645
645
|
}
|
|
@@ -647,16 +647,16 @@ var handleDriveAction = async (ctx) => {
|
|
|
647
647
|
const restoreData = deleteQuerySchema.safeParse(req.query);
|
|
648
648
|
if (!restoreData.success) return void res.status(400).json({ status: 400, message: "Could not restore: invalid ID" });
|
|
649
649
|
const { id } = restoreData.data;
|
|
650
|
-
const drive = await
|
|
650
|
+
const drive = await chunkDHIHCER6_cjs.drive_default.findById(id);
|
|
651
651
|
if (!drive) return void res.status(404).json({ status: 404, message: "Could not restore: item not found" });
|
|
652
652
|
let targetParentId = drive.parentId;
|
|
653
653
|
if (targetParentId) {
|
|
654
|
-
const parent = await
|
|
654
|
+
const parent = await chunkDHIHCER6_cjs.drive_default.findById(targetParentId);
|
|
655
655
|
if (parent?.trashedAt) {
|
|
656
656
|
targetParentId = null;
|
|
657
657
|
}
|
|
658
658
|
}
|
|
659
|
-
const itemProvider = drive.provider?.type === "GOOGLE" ?
|
|
659
|
+
const itemProvider = drive.provider?.type === "GOOGLE" ? chunkDHIHCER6_cjs.GoogleDriveProvider : chunkDHIHCER6_cjs.LocalStorageProvider;
|
|
660
660
|
const itemAccountId = drive.storageAccountId ? drive.storageAccountId.toString() : void 0;
|
|
661
661
|
try {
|
|
662
662
|
await itemProvider.untrash([id], owner, itemAccountId);
|
|
@@ -690,7 +690,7 @@ var handleDriveAction = async (ctx) => {
|
|
|
690
690
|
console.error(`Failed to move item ${id}`, e);
|
|
691
691
|
}
|
|
692
692
|
}
|
|
693
|
-
res.status(200).json({ status: 200, message: "Moved", data: { items:
|
|
693
|
+
res.status(200).json({ status: 200, message: "Moved", data: { items: chunkDHIHCER6_cjs.withSignedUrls(items, config) } });
|
|
694
694
|
return;
|
|
695
695
|
}
|
|
696
696
|
case "reorder": {
|
|
@@ -711,7 +711,7 @@ var handleDriveAction = async (ctx) => {
|
|
|
711
711
|
if (!isRootMode) {
|
|
712
712
|
query.owner = owner;
|
|
713
713
|
}
|
|
714
|
-
const existingItems = await
|
|
714
|
+
const existingItems = await chunkDHIHCER6_cjs.drive_default.find(query, { _id: 1, parentId: 1 });
|
|
715
715
|
if (existingItems.length !== ids.length) {
|
|
716
716
|
return void res.status(404).json({ status: 404, message: "Could not reorder: one or more items were not found" });
|
|
717
717
|
}
|
|
@@ -731,9 +731,9 @@ var handleDriveAction = async (ctx) => {
|
|
|
731
731
|
update: { $set: { order } }
|
|
732
732
|
}
|
|
733
733
|
}));
|
|
734
|
-
await
|
|
735
|
-
const updatedItems = await
|
|
736
|
-
const plainItems =
|
|
734
|
+
await chunkDHIHCER6_cjs.drive_default.bulkWrite(operations);
|
|
735
|
+
const updatedItems = await chunkDHIHCER6_cjs.drive_default.find(query, {}, { sort: { order: 1 } });
|
|
736
|
+
const plainItems = chunkDHIHCER6_cjs.withSignedUrls(await Promise.all(updatedItems.map((item) => item.toClient())), config);
|
|
737
737
|
res.status(200).json({ status: 200, message: "Reordered", data: { items: plainItems } });
|
|
738
738
|
return;
|
|
739
739
|
}
|
|
@@ -741,7 +741,7 @@ var handleDriveAction = async (ctx) => {
|
|
|
741
741
|
const renameData = renameBodySchema.safeParse({ id: req.query.id, ...req.body });
|
|
742
742
|
if (!renameData.success) return void res.status(400).json({ status: 400, message: "Could not rename: invalid request data" });
|
|
743
743
|
const { id, newName } = renameData.data;
|
|
744
|
-
const item =
|
|
744
|
+
const item = chunkDHIHCER6_cjs.withSignedUrl(await provider.rename(id, newName, owner, accountId), config);
|
|
745
745
|
res.status(200).json({ status: 200, message: "Renamed", data: { item } });
|
|
746
746
|
return;
|
|
747
747
|
}
|
|
@@ -790,7 +790,7 @@ var driveAPIHandler = async (req, res) => {
|
|
|
790
790
|
const action = req.query.action || (req.query.code && req.query.state ? "callback" : void 0);
|
|
791
791
|
let config;
|
|
792
792
|
try {
|
|
793
|
-
config =
|
|
793
|
+
config = chunkDHIHCER6_cjs.getDriveConfig();
|
|
794
794
|
} catch (error) {
|
|
795
795
|
console.error("[next-drive] Configuration error:", error);
|
|
796
796
|
res.status(500).json({ status: 500, message: "Drive is not ready: failed to initialize configuration" });
|
|
@@ -811,7 +811,7 @@ var driveAPIHandler = async (req, res) => {
|
|
|
811
811
|
const googleConfigured = !!(clientId && clientSecret && redirectUri);
|
|
812
812
|
let authenticated2 = false;
|
|
813
813
|
try {
|
|
814
|
-
await
|
|
814
|
+
await chunkDHIHCER6_cjs.getDriveInformation({ method: "REQUEST", req });
|
|
815
815
|
authenticated2 = true;
|
|
816
816
|
} catch {
|
|
817
817
|
authenticated2 = false;
|
|
@@ -834,7 +834,7 @@ var driveAPIHandler = async (req, res) => {
|
|
|
834
834
|
let information;
|
|
835
835
|
let authenticated = true;
|
|
836
836
|
try {
|
|
837
|
-
information = await
|
|
837
|
+
information = await chunkDHIHCER6_cjs.getDriveInformation({ method: "REQUEST", req });
|
|
838
838
|
} catch (err) {
|
|
839
839
|
if (action === "upload" && config.security?.unauthenticated?.enabled) {
|
|
840
840
|
information = { key: null, storage: { quotaInBytes: 0 } };
|
|
@@ -846,7 +846,7 @@ var driveAPIHandler = async (req, res) => {
|
|
|
846
846
|
const { key: owner } = information;
|
|
847
847
|
const wasAuthHandled = await handleAuthAction(req, res, action, config, owner);
|
|
848
848
|
if (wasAuthHandled) return;
|
|
849
|
-
const { provider, accountId } = await
|
|
849
|
+
const { provider, accountId } = await chunkDHIHCER6_cjs.resolveProvider(req, owner);
|
|
850
850
|
await handleDriveAction({
|
|
851
851
|
req,
|
|
852
852
|
res,
|
|
@@ -868,5 +868,5 @@ var driveAPIHandler = async (req, res) => {
|
|
|
868
868
|
|
|
869
869
|
exports.driveAPIHandler = driveAPIHandler;
|
|
870
870
|
exports.driveFileSchemaZod = driveFileSchemaZod;
|
|
871
|
-
//# sourceMappingURL=chunk-
|
|
872
|
-
//# sourceMappingURL=chunk-
|
|
871
|
+
//# sourceMappingURL=chunk-PKNXKHGS.cjs.map
|
|
872
|
+
//# sourceMappingURL=chunk-PKNXKHGS.cjs.map
|