next-file-manager 0.1.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/README.md +230 -0
- package/dist/client/index.css +48 -0
- package/dist/client/index.css.map +1 -0
- package/dist/client/index.d.ts +128 -0
- package/dist/client/index.js +2863 -0
- package/dist/client/index.js.map +1 -0
- package/dist/index-DE7-rwJm.d.ts +87 -0
- package/dist/server/index.d.ts +115 -0
- package/dist/server/index.js +1413 -0
- package/dist/server/index.js.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
type TDatabaseDriveStatus = "READY" | "PROCESSING" | "UPLOADING" | "FAILED";
|
|
2
|
+
type TDatabaseDriveMetadataFile = {
|
|
3
|
+
type: "FILE";
|
|
4
|
+
sizeInBytes: number;
|
|
5
|
+
mime: string;
|
|
6
|
+
path: string;
|
|
7
|
+
width?: number;
|
|
8
|
+
height?: number;
|
|
9
|
+
duration?: number;
|
|
10
|
+
hash?: string;
|
|
11
|
+
};
|
|
12
|
+
type TDatabaseDriveMetadataFolder = {
|
|
13
|
+
type: "FOLDER";
|
|
14
|
+
};
|
|
15
|
+
type TDatabaseDriveInformation = TDatabaseDriveMetadataFile | TDatabaseDriveMetadataFolder;
|
|
16
|
+
type TDatabaseDriveProvider = {
|
|
17
|
+
type: 'LOCAL' | 'GOOGLE';
|
|
18
|
+
google?: {
|
|
19
|
+
id: string;
|
|
20
|
+
webViewLink?: string;
|
|
21
|
+
iconLink?: string;
|
|
22
|
+
thumbnailLink?: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
type TDatabaseDriveMetadata = {
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
};
|
|
28
|
+
type TDatabaseDrive = {
|
|
29
|
+
id: string;
|
|
30
|
+
name: string;
|
|
31
|
+
parentId: string | null;
|
|
32
|
+
order: number;
|
|
33
|
+
provider: TDatabaseDriveProvider;
|
|
34
|
+
metadata: TDatabaseDriveMetadata;
|
|
35
|
+
information: TDatabaseDriveInformation;
|
|
36
|
+
status: TDatabaseDriveStatus;
|
|
37
|
+
trashedAt: Date | null;
|
|
38
|
+
createdAt: Date;
|
|
39
|
+
token?: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type TDriveAction = 'upload' | 'list' | 'serve' | 'thumbnail' | 'rename' | 'delete' | 'deleteMany' | 'deletePermanent' | 'cancel' | 'createFolder' | 'move' | 'reorder' | 'trash' | 'restore' | 'emptyTrash' | 'purgeTrash' | 'search' | 'duplicates' | 'quota';
|
|
43
|
+
interface TDriveAPIResponse<T = unknown> {
|
|
44
|
+
status: number;
|
|
45
|
+
message: string;
|
|
46
|
+
data?: T;
|
|
47
|
+
statistic?: {
|
|
48
|
+
storage?: {
|
|
49
|
+
usedInBytes: number;
|
|
50
|
+
quotaInBytes: number;
|
|
51
|
+
};
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
type TDriveThumbnailSize = 'small' | 'medium' | 'large';
|
|
56
|
+
type TDriveImageQuality = 'ultralow' | 'low' | 'medium' | 'high' | 'normal';
|
|
57
|
+
|
|
58
|
+
type TDriveFile = {
|
|
59
|
+
id: string;
|
|
60
|
+
file: {
|
|
61
|
+
name: string;
|
|
62
|
+
mime: string;
|
|
63
|
+
size: number;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
type TDrivePathItem = {
|
|
67
|
+
id: string | null;
|
|
68
|
+
name: string;
|
|
69
|
+
};
|
|
70
|
+
type TDriveQuota = {
|
|
71
|
+
usedInBytes: number;
|
|
72
|
+
totalInBytes: number;
|
|
73
|
+
availableInBytes: number;
|
|
74
|
+
percentage: number;
|
|
75
|
+
};
|
|
76
|
+
type TDriveUploadState = {
|
|
77
|
+
id: string;
|
|
78
|
+
name: string;
|
|
79
|
+
size: number;
|
|
80
|
+
status: 'pending' | 'queued' | 'uploading' | 'complete' | 'error' | 'cancelled';
|
|
81
|
+
currentChunk: number;
|
|
82
|
+
totalChunks: number;
|
|
83
|
+
driveId?: string;
|
|
84
|
+
error?: string;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export type { TDatabaseDriveProvider as T, TDatabaseDriveMetadata as a, TDatabaseDriveInformation as b, TDatabaseDriveStatus as c, TDatabaseDrive as d, TDriveFile as e, TDatabaseDriveMetadataFile as f, TDatabaseDriveMetadataFolder as g, TDriveAction as h, TDriveAPIResponse as i, TDriveThumbnailSize as j, TDriveImageQuality as k, TDrivePathItem as l, TDriveQuota as m, TDriveUploadState as n };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
+
import { Readable } from 'stream';
|
|
3
|
+
import { T as TDatabaseDriveProvider, a as TDatabaseDriveMetadata, b as TDatabaseDriveInformation, c as TDatabaseDriveStatus, d as TDatabaseDrive } from '../index-DE7-rwJm.js';
|
|
4
|
+
export { f as TDatabaseDriveMetadataFile, g as TDatabaseDriveMetadataFolder, i as TDriveAPIResponse, h as TDriveAction, e as TDriveFile, k as TDriveImageQuality, j as TDriveThumbnailSize } from '../index-DE7-rwJm.js';
|
|
5
|
+
import { Document, Types } from 'mongoose';
|
|
6
|
+
|
|
7
|
+
type TDriveDatabase = "MONGOOSE";
|
|
8
|
+
type TDriveConfigInformation = {
|
|
9
|
+
key: Record<string, unknown> | null;
|
|
10
|
+
storage: {
|
|
11
|
+
quotaInBytes: number;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
type TDriveSecurityConfig = {
|
|
15
|
+
maxUploadSizeInBytes: number;
|
|
16
|
+
allowedMimeTypes: string[];
|
|
17
|
+
signedUrls?: {
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
secret: string;
|
|
20
|
+
expiresIn: number;
|
|
21
|
+
};
|
|
22
|
+
trash?: {
|
|
23
|
+
retentionDays: number;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
type TDriveImageConfig = {
|
|
27
|
+
formats: Array<"webp" | "jpeg" | "png">;
|
|
28
|
+
qualities: Array<"ultralow" | "low" | "medium" | "high" | "normal">;
|
|
29
|
+
};
|
|
30
|
+
type TDriveStorageConfig = {
|
|
31
|
+
path: string;
|
|
32
|
+
google?: {
|
|
33
|
+
clientId: string;
|
|
34
|
+
clientSecret: string;
|
|
35
|
+
redirectUri: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
type TDriveConfiguration = {
|
|
39
|
+
database: TDriveDatabase;
|
|
40
|
+
storage: TDriveStorageConfig;
|
|
41
|
+
security: TDriveSecurityConfig;
|
|
42
|
+
image?: TDriveImageConfig;
|
|
43
|
+
information: (request: NextApiRequest) => Promise<TDriveConfigInformation>;
|
|
44
|
+
apiUrl: string;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
declare const driveConfiguration: (config: TDriveConfiguration) => TDriveConfiguration;
|
|
48
|
+
declare const getDriveConfig: () => TDriveConfiguration;
|
|
49
|
+
declare const getDriveInformation: (req: NextApiRequest) => Promise<TDriveConfigInformation>;
|
|
50
|
+
|
|
51
|
+
interface IDatabaseDriveDocument extends Document {
|
|
52
|
+
owner: Record<string, unknown> | null;
|
|
53
|
+
storageAccountId: Types.ObjectId | null;
|
|
54
|
+
name: string;
|
|
55
|
+
parentId: Types.ObjectId | null;
|
|
56
|
+
order: number;
|
|
57
|
+
provider: TDatabaseDriveProvider;
|
|
58
|
+
metadata: TDatabaseDriveMetadata;
|
|
59
|
+
information: TDatabaseDriveInformation;
|
|
60
|
+
status: TDatabaseDriveStatus;
|
|
61
|
+
trashedAt: Date | null;
|
|
62
|
+
createdAt: Date;
|
|
63
|
+
toClient: () => Promise<TDatabaseDrive>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declare const driveGetUrl: (fileId: string, options?: {
|
|
67
|
+
expiry?: number | Date;
|
|
68
|
+
}) => string;
|
|
69
|
+
/**
|
|
70
|
+
* Read a file and return a readable stream.
|
|
71
|
+
* @param file - Either a file ID (string) or a TDatabaseDrive/IDatabaseDriveDocument object
|
|
72
|
+
* @returns Promise with readable stream, mime type, and file size
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* // Using file ID
|
|
76
|
+
* const { stream, mime, size } = await driveReadFile('694f5013226de007be94fcc0');
|
|
77
|
+
* stream.pipe(response);
|
|
78
|
+
*
|
|
79
|
+
* // Using database document
|
|
80
|
+
* const drive = await Drive.findById(fileId);
|
|
81
|
+
* const { stream, mime, size } = await driveReadFile(drive);
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
declare const driveReadFile: (file: string | IDatabaseDriveDocument | TDatabaseDrive) => Promise<{
|
|
85
|
+
stream: Readable;
|
|
86
|
+
mime: string;
|
|
87
|
+
size: number;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Get the local file system path for a file. For Google Drive files, downloads them to a local cache first.
|
|
91
|
+
* @param file - Either a file ID (string) or a TDatabaseDrive/IDatabaseDriveDocument object
|
|
92
|
+
* @returns Promise with readonly object containing the absolute file path and metadata
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* // Using file ID
|
|
96
|
+
* const { path, mime, size } = await driveFilePath('694f5013226de007be94fcc0');
|
|
97
|
+
* const data = fs.readFileSync(path);
|
|
98
|
+
*
|
|
99
|
+
* // Using database document
|
|
100
|
+
* const drive = await Drive.findById(fileId);
|
|
101
|
+
* const { path, name, provider } = await driveFilePath(drive);
|
|
102
|
+
* await processFile(path);
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
declare const driveFilePath: (file: string | IDatabaseDriveDocument | TDatabaseDrive) => Promise<Readonly<{
|
|
106
|
+
path: string;
|
|
107
|
+
name: string;
|
|
108
|
+
mime: string;
|
|
109
|
+
size: number;
|
|
110
|
+
provider: string;
|
|
111
|
+
}>>;
|
|
112
|
+
|
|
113
|
+
declare const driveAPIHandler: (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
114
|
+
|
|
115
|
+
export { TDatabaseDrive, TDatabaseDriveInformation, TDatabaseDriveMetadata, TDatabaseDriveProvider, TDatabaseDriveStatus, type TDriveConfigInformation, type TDriveConfiguration, type TDriveDatabase, type TDriveImageConfig, type TDriveSecurityConfig, type TDriveStorageConfig, driveAPIHandler, driveConfiguration, driveFilePath, driveGetUrl, driveReadFile, getDriveConfig, getDriveInformation };
|