@memberjunction/storage 2.30.0 → 2.32.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/drivers/AWSFileStorage.d.ts +26 -1
- package/dist/drivers/AWSFileStorage.d.ts.map +1 -1
- package/dist/drivers/AWSFileStorage.js +287 -13
- package/dist/drivers/AWSFileStorage.js.map +1 -1
- package/dist/drivers/AzureFileStorage.d.ts +22 -1
- package/dist/drivers/AzureFileStorage.d.ts.map +1 -1
- package/dist/drivers/AzureFileStorage.js +264 -20
- package/dist/drivers/AzureFileStorage.js.map +1 -1
- package/dist/drivers/BoxFileStorage.d.ts +73 -0
- package/dist/drivers/BoxFileStorage.d.ts.map +1 -0
- package/dist/drivers/BoxFileStorage.js +517 -0
- package/dist/drivers/BoxFileStorage.js.map +1 -0
- package/dist/drivers/DropboxFileStorage.d.ts +73 -0
- package/dist/drivers/DropboxFileStorage.d.ts.map +1 -0
- package/dist/drivers/DropboxFileStorage.js +463 -0
- package/dist/drivers/DropboxFileStorage.js.map +1 -0
- package/dist/drivers/GoogleDriveFileStorage.d.ts +73 -0
- package/dist/drivers/GoogleDriveFileStorage.d.ts.map +1 -0
- package/dist/drivers/GoogleDriveFileStorage.js +542 -0
- package/dist/drivers/GoogleDriveFileStorage.js.map +1 -0
- package/dist/drivers/GoogleFileStorage.d.ts +20 -1
- package/dist/drivers/GoogleFileStorage.d.ts.map +1 -1
- package/dist/drivers/GoogleFileStorage.js +215 -2
- package/dist/drivers/GoogleFileStorage.js.map +1 -1
- package/dist/drivers/SharePointFileStorage.d.ts +81 -0
- package/dist/drivers/SharePointFileStorage.d.ts.map +1 -0
- package/dist/drivers/SharePointFileStorage.js +490 -0
- package/dist/drivers/SharePointFileStorage.js.map +1 -0
- package/dist/generic/FileStorageBase.d.ts +119 -0
- package/dist/generic/FileStorageBase.d.ts.map +1 -1
- package/dist/generic/FileStorageBase.js +18 -1
- package/dist/generic/FileStorageBase.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +12 -4
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
32
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.BoxFileStorage = void 0;
|
|
39
|
+
const box_node_sdk_1 = __importDefault(require("box-node-sdk"));
|
|
40
|
+
const global_1 = require("@memberjunction/global");
|
|
41
|
+
const env = __importStar(require("env-var"));
|
|
42
|
+
const mime = __importStar(require("mime-types"));
|
|
43
|
+
const FileStorageBase_1 = require("../generic/FileStorageBase");
|
|
44
|
+
let BoxFileStorage = class BoxFileStorage extends FileStorageBase_1.FileStorageBase {
|
|
45
|
+
constructor() {
|
|
46
|
+
super();
|
|
47
|
+
this.providerName = 'Box.com';
|
|
48
|
+
const clientId = env.get('STORAGE_BOX_CLIENT_ID').required().asString();
|
|
49
|
+
const clientSecret = env.get('STORAGE_BOX_CLIENT_SECRET').required().asString();
|
|
50
|
+
const enterpriseId = env.get('STORAGE_BOX_ENTERPRISE_ID').asString();
|
|
51
|
+
const userId = env.get('STORAGE_BOX_USER_ID').asString();
|
|
52
|
+
// Configuration for Box SDK
|
|
53
|
+
const config = {
|
|
54
|
+
boxAppSettings: {
|
|
55
|
+
clientID: clientId,
|
|
56
|
+
clientSecret: clientSecret
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
// Private key auth or app token auth
|
|
60
|
+
if (env.get('STORAGE_BOX_PRIVATE_KEY').asString()) {
|
|
61
|
+
// Using JWT auth
|
|
62
|
+
const privateKey = env.get('STORAGE_BOX_PRIVATE_KEY').required().asString();
|
|
63
|
+
const passphrase = env.get('STORAGE_BOX_PASSPHRASE').asString();
|
|
64
|
+
config.boxAppSettings.appAuth = {
|
|
65
|
+
publicKeyID: env.get('STORAGE_BOX_PUBLIC_KEY_ID').required().asString(),
|
|
66
|
+
privateKey: privateKey,
|
|
67
|
+
passphrase: passphrase
|
|
68
|
+
};
|
|
69
|
+
const sdk = box_node_sdk_1.default.getPreconfiguredInstance(config);
|
|
70
|
+
// Get client using JWT auth
|
|
71
|
+
if (enterpriseId) {
|
|
72
|
+
// Enterprise auth
|
|
73
|
+
this._client = sdk.getAppAuthClient('enterprise', enterpriseId);
|
|
74
|
+
}
|
|
75
|
+
else if (userId) {
|
|
76
|
+
// User auth
|
|
77
|
+
this._client = sdk.getAppAuthClient('user', userId);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
throw new Error('Either STORAGE_BOX_ENTERPRISE_ID or STORAGE_BOX_USER_ID must be provided when using JWT authentication');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
// Using developer token
|
|
85
|
+
const developerToken = env.get('STORAGE_BOX_DEVELOPER_TOKEN').required().asString();
|
|
86
|
+
const sdk = new box_node_sdk_1.default({
|
|
87
|
+
clientID: clientId,
|
|
88
|
+
clientSecret: clientSecret
|
|
89
|
+
});
|
|
90
|
+
this._client = sdk.getBasicClient(developerToken);
|
|
91
|
+
}
|
|
92
|
+
// Set root folder ID, defaults to '0' which is the root of Box
|
|
93
|
+
this._rootFolderId = env.get('STORAGE_BOX_ROOT_FOLDER_ID').default('0').asString();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Find a file or folder by path
|
|
97
|
+
*/
|
|
98
|
+
async _getItemByPath(path) {
|
|
99
|
+
if (!path || path === '/' || path === '') {
|
|
100
|
+
// Return the root folder
|
|
101
|
+
try {
|
|
102
|
+
return await this._client.folders.get(this._rootFolderId);
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
throw new Error(`Root folder not found: ${this._rootFolderId}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Split path into parts
|
|
109
|
+
const pathParts = path.split('/').filter(p => p);
|
|
110
|
+
let currentId = this._rootFolderId;
|
|
111
|
+
let currentItem = null;
|
|
112
|
+
let isFolder = true;
|
|
113
|
+
// Traverse the path
|
|
114
|
+
for (let i = 0; i < pathParts.length; i++) {
|
|
115
|
+
const part = pathParts[i];
|
|
116
|
+
const isLastPart = i === pathParts.length - 1;
|
|
117
|
+
// Get folder items
|
|
118
|
+
const items = await this._client.folders.getItems(currentId, {
|
|
119
|
+
fields: 'name,type,id,size,modified_at,parent'
|
|
120
|
+
});
|
|
121
|
+
// Find the matching item
|
|
122
|
+
const matchingItem = items.entries.find(item => item.name === part);
|
|
123
|
+
if (!matchingItem) {
|
|
124
|
+
throw new Error(`Path not found: ${path} (at part: ${part})`);
|
|
125
|
+
}
|
|
126
|
+
currentItem = matchingItem;
|
|
127
|
+
currentId = matchingItem.id;
|
|
128
|
+
isFolder = matchingItem.type === 'folder';
|
|
129
|
+
// If not the last part, it must be a folder
|
|
130
|
+
if (!isLastPart && !isFolder) {
|
|
131
|
+
throw new Error(`Path not found: ${path} (at part: ${part}, expected folder but got file)`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Return either the file or folder object
|
|
135
|
+
if (isFolder) {
|
|
136
|
+
return await this._client.folders.get(currentId);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
return await this._client.files.get(currentId);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Ensures a folder exists at the given path, creating it if necessary
|
|
144
|
+
*/
|
|
145
|
+
async _getOrCreateFolder(path) {
|
|
146
|
+
if (!path || path === '/' || path === '') {
|
|
147
|
+
return this._rootFolderId;
|
|
148
|
+
}
|
|
149
|
+
// Split path into parts
|
|
150
|
+
const pathParts = path.split('/').filter(p => p);
|
|
151
|
+
let currentId = this._rootFolderId;
|
|
152
|
+
// Traverse/create the path
|
|
153
|
+
for (const part of pathParts) {
|
|
154
|
+
// Check if folder exists
|
|
155
|
+
try {
|
|
156
|
+
const items = await this._client.folders.getItems(currentId, {
|
|
157
|
+
fields: 'name,type,id'
|
|
158
|
+
});
|
|
159
|
+
const matchingFolder = items.entries.find(item => item.name === part && item.type === 'folder');
|
|
160
|
+
if (matchingFolder) {
|
|
161
|
+
currentId = matchingFolder.id;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
// Create the folder
|
|
165
|
+
const newFolder = await this._client.folders.create(currentId, part);
|
|
166
|
+
currentId = newFolder.id;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
throw new Error(`Error creating folder path: ${path} (at part: ${part}): ${error.message}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return currentId;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Converts a Box item to StorageObjectMetadata
|
|
177
|
+
*/
|
|
178
|
+
_convertToMetadata(item, parentPath = '') {
|
|
179
|
+
const isDirectory = item.type === 'folder';
|
|
180
|
+
const fullPath = parentPath ? `${parentPath}/${item.name}` : item.name;
|
|
181
|
+
const modifiedDate = new Date(item.modified_at || Date.now());
|
|
182
|
+
return {
|
|
183
|
+
name: item.name,
|
|
184
|
+
path: parentPath,
|
|
185
|
+
fullPath,
|
|
186
|
+
size: parseInt(item.size || '0'),
|
|
187
|
+
contentType: item.type === 'file' ?
|
|
188
|
+
(mime.lookup(item.name) || 'application/octet-stream') :
|
|
189
|
+
'application/x-directory',
|
|
190
|
+
lastModified: modifiedDate,
|
|
191
|
+
isDirectory,
|
|
192
|
+
etag: item.etag,
|
|
193
|
+
customMetadata: {
|
|
194
|
+
id: item.id
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Box doesn't support pre-auth upload URLs directly
|
|
200
|
+
*/
|
|
201
|
+
async CreatePreAuthUploadUrl(objectName) {
|
|
202
|
+
// Box doesn't support pre-signed URLs for uploads in the same way as S3
|
|
203
|
+
// Instead, use PutObject method for uploads
|
|
204
|
+
this.throwUnsupportedOperationError('CreatePreAuthUploadUrl');
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Create a pre-authenticated download URL
|
|
208
|
+
*/
|
|
209
|
+
async CreatePreAuthDownloadUrl(objectName) {
|
|
210
|
+
try {
|
|
211
|
+
// Get the file
|
|
212
|
+
const file = await this._getItemByPath(objectName);
|
|
213
|
+
if (file.type !== 'file') {
|
|
214
|
+
throw new Error(`Not a file: ${objectName}`);
|
|
215
|
+
}
|
|
216
|
+
// Create a temporary download URL
|
|
217
|
+
const downloadUrl = await this._client.files.getDownloadURL(file.id);
|
|
218
|
+
return downloadUrl;
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
console.error('Error creating pre-auth download URL', { objectName, error });
|
|
222
|
+
throw new Error(`Failed to create download URL for: ${objectName}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Move an object
|
|
227
|
+
*/
|
|
228
|
+
async MoveObject(oldObjectName, newObjectName) {
|
|
229
|
+
try {
|
|
230
|
+
// Get the source file/folder
|
|
231
|
+
const sourceItem = await this._getItemByPath(oldObjectName);
|
|
232
|
+
// Parse destination path
|
|
233
|
+
const destPathParts = newObjectName.split('/');
|
|
234
|
+
const destName = destPathParts.pop() || '';
|
|
235
|
+
const destParentPath = destPathParts.join('/');
|
|
236
|
+
// Get or create destination parent folder
|
|
237
|
+
const destParentId = await this._getOrCreateFolder(destParentPath);
|
|
238
|
+
// Move the item
|
|
239
|
+
if (sourceItem.type === 'file') {
|
|
240
|
+
await this._client.files.move(sourceItem.id, destParentId, { name: destName });
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
await this._client.folders.move(sourceItem.id, destParentId, { name: destName });
|
|
244
|
+
}
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
console.error('Error moving object', { oldObjectName, newObjectName, error });
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Delete an object
|
|
254
|
+
*/
|
|
255
|
+
async DeleteObject(objectName) {
|
|
256
|
+
try {
|
|
257
|
+
// Get the file/folder
|
|
258
|
+
const item = await this._getItemByPath(objectName);
|
|
259
|
+
// Delete the item
|
|
260
|
+
if (item.type === 'file') {
|
|
261
|
+
await this._client.files.delete(item.id);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
// For folders, this will fail if not empty and recursive=false
|
|
265
|
+
await this._client.folders.delete(item.id);
|
|
266
|
+
}
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
// If item not found, consider it success for idempotency
|
|
271
|
+
if (error.statusCode === 404) {
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
console.error('Error deleting object', { objectName, error });
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* List objects in a directory
|
|
280
|
+
*/
|
|
281
|
+
async ListObjects(prefix, delimiter = '/') {
|
|
282
|
+
try {
|
|
283
|
+
// Get the folder
|
|
284
|
+
const folder = await this._getItemByPath(prefix);
|
|
285
|
+
if (folder.type !== 'folder') {
|
|
286
|
+
throw new Error(`Not a folder: ${prefix}`);
|
|
287
|
+
}
|
|
288
|
+
// List items in the folder
|
|
289
|
+
const items = await this._client.folders.getItems(folder.id, {
|
|
290
|
+
fields: 'name,type,id,size,modified_at,parent'
|
|
291
|
+
});
|
|
292
|
+
const objects = [];
|
|
293
|
+
const prefixes = [];
|
|
294
|
+
// Process items
|
|
295
|
+
for (const item of items.entries) {
|
|
296
|
+
// Add to objects list
|
|
297
|
+
objects.push(this._convertToMetadata(item, prefix));
|
|
298
|
+
// If it's a folder, add to prefixes
|
|
299
|
+
if (item.type === 'folder') {
|
|
300
|
+
const folderPath = prefix
|
|
301
|
+
? (prefix.endsWith('/') ? `${prefix}${item.name}` : `${prefix}/${item.name}`)
|
|
302
|
+
: item.name;
|
|
303
|
+
prefixes.push(`${folderPath}/`);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return { objects, prefixes };
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
console.error('Error listing objects', { prefix, error });
|
|
310
|
+
return { objects: [], prefixes: [] };
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Create a directory
|
|
315
|
+
*/
|
|
316
|
+
async CreateDirectory(directoryPath) {
|
|
317
|
+
try {
|
|
318
|
+
// Remove trailing slash if present
|
|
319
|
+
const normalizedPath = directoryPath.endsWith('/')
|
|
320
|
+
? directoryPath.substring(0, directoryPath.length - 1)
|
|
321
|
+
: directoryPath;
|
|
322
|
+
// Parse the path
|
|
323
|
+
const pathParts = normalizedPath.split('/');
|
|
324
|
+
const folderName = pathParts.pop() || '';
|
|
325
|
+
const parentPath = pathParts.join('/');
|
|
326
|
+
// Get the parent folder
|
|
327
|
+
const parentId = await this._getOrCreateFolder(parentPath);
|
|
328
|
+
// Create the folder
|
|
329
|
+
await this._client.folders.create(parentId, folderName);
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
catch (error) {
|
|
333
|
+
console.error('Error creating directory', { directoryPath, error });
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Delete a directory
|
|
339
|
+
*/
|
|
340
|
+
async DeleteDirectory(directoryPath, recursive = false) {
|
|
341
|
+
try {
|
|
342
|
+
// Remove trailing slash if present
|
|
343
|
+
const normalizedPath = directoryPath.endsWith('/')
|
|
344
|
+
? directoryPath.substring(0, directoryPath.length - 1)
|
|
345
|
+
: directoryPath;
|
|
346
|
+
// Get the folder
|
|
347
|
+
const folder = await this._getItemByPath(normalizedPath);
|
|
348
|
+
if (folder.type !== 'folder') {
|
|
349
|
+
throw new Error(`Not a folder: ${normalizedPath}`);
|
|
350
|
+
}
|
|
351
|
+
// Delete the folder
|
|
352
|
+
await this._client.folders.delete(folder.id, {
|
|
353
|
+
recursive: recursive
|
|
354
|
+
});
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
catch (error) {
|
|
358
|
+
// If folder not found, consider it success
|
|
359
|
+
if (error.statusCode === 404) {
|
|
360
|
+
return true;
|
|
361
|
+
}
|
|
362
|
+
// If trying to delete non-empty folder without recursive flag
|
|
363
|
+
if (error.statusCode === 400 && !recursive) {
|
|
364
|
+
throw new Error('Directory is not empty');
|
|
365
|
+
}
|
|
366
|
+
console.error('Error deleting directory', { directoryPath, recursive, error });
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Get object metadata
|
|
372
|
+
*/
|
|
373
|
+
async GetObjectMetadata(objectName) {
|
|
374
|
+
try {
|
|
375
|
+
// Get the file/folder
|
|
376
|
+
const item = await this._getItemByPath(objectName);
|
|
377
|
+
// Parse path to get parent path
|
|
378
|
+
const pathParts = objectName.split('/');
|
|
379
|
+
pathParts.pop(); // Remove filename/foldername
|
|
380
|
+
const parentPath = pathParts.join('/');
|
|
381
|
+
return this._convertToMetadata(item, parentPath);
|
|
382
|
+
}
|
|
383
|
+
catch (error) {
|
|
384
|
+
console.error('Error getting object metadata', { objectName, error });
|
|
385
|
+
throw new Error(`Object not found: ${objectName}`);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Get an object's contents
|
|
390
|
+
*/
|
|
391
|
+
async GetObject(objectName) {
|
|
392
|
+
try {
|
|
393
|
+
// Get the file
|
|
394
|
+
const file = await this._getItemByPath(objectName);
|
|
395
|
+
if (file.type !== 'file') {
|
|
396
|
+
throw new Error(`Not a file: ${objectName}`);
|
|
397
|
+
}
|
|
398
|
+
// Get download stream
|
|
399
|
+
const stream = await this._client.files.getReadStream(file.id);
|
|
400
|
+
// Convert stream to buffer
|
|
401
|
+
return new Promise((resolve, reject) => {
|
|
402
|
+
const chunks = [];
|
|
403
|
+
stream.on('data', (chunk) => {
|
|
404
|
+
chunks.push(chunk);
|
|
405
|
+
});
|
|
406
|
+
stream.on('end', () => {
|
|
407
|
+
resolve(Buffer.concat(chunks));
|
|
408
|
+
});
|
|
409
|
+
stream.on('error', (err) => {
|
|
410
|
+
reject(err);
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
catch (error) {
|
|
415
|
+
console.error('Error getting object', { objectName, error });
|
|
416
|
+
throw new Error(`Failed to get object: ${objectName}`);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Upload an object
|
|
421
|
+
*/
|
|
422
|
+
async PutObject(objectName, data, contentType, metadata) {
|
|
423
|
+
try {
|
|
424
|
+
// Parse path
|
|
425
|
+
const pathParts = objectName.split('/');
|
|
426
|
+
const fileName = pathParts.pop() || '';
|
|
427
|
+
const parentPath = pathParts.join('/');
|
|
428
|
+
// Get or create parent folder
|
|
429
|
+
const parentId = await this._getOrCreateFolder(parentPath);
|
|
430
|
+
// Check if file already exists
|
|
431
|
+
let existingFileId = null;
|
|
432
|
+
try {
|
|
433
|
+
const existingFile = await this._getItemByPath(objectName);
|
|
434
|
+
if (existingFile.type === 'file') {
|
|
435
|
+
existingFileId = existingFile.id;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
catch (error) {
|
|
439
|
+
// File doesn't exist, will create new
|
|
440
|
+
}
|
|
441
|
+
// Determine content type if not provided
|
|
442
|
+
const effectiveContentType = contentType || mime.lookup(objectName) || 'application/octet-stream';
|
|
443
|
+
if (existingFileId) {
|
|
444
|
+
// Update existing file
|
|
445
|
+
await this._client.files.uploadNewFileVersion(existingFileId, data);
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
// Create new file
|
|
449
|
+
await this._client.files.uploadFile(parentId, fileName, data);
|
|
450
|
+
}
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
453
|
+
catch (error) {
|
|
454
|
+
console.error('Error putting object', { objectName, error });
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Copy an object
|
|
460
|
+
*/
|
|
461
|
+
async CopyObject(sourceObjectName, destinationObjectName) {
|
|
462
|
+
try {
|
|
463
|
+
// Get source file
|
|
464
|
+
const sourceFile = await this._getItemByPath(sourceObjectName);
|
|
465
|
+
if (sourceFile.type !== 'file') {
|
|
466
|
+
throw new Error(`Not a file: ${sourceObjectName}`);
|
|
467
|
+
}
|
|
468
|
+
// Parse destination path
|
|
469
|
+
const destPathParts = destinationObjectName.split('/');
|
|
470
|
+
const destFileName = destPathParts.pop() || '';
|
|
471
|
+
const destParentPath = destPathParts.join('/');
|
|
472
|
+
// Get or create destination parent folder
|
|
473
|
+
const destParentId = await this._getOrCreateFolder(destParentPath);
|
|
474
|
+
// Copy the file
|
|
475
|
+
await this._client.files.copy(sourceFile.id, destParentId, { name: destFileName });
|
|
476
|
+
return true;
|
|
477
|
+
}
|
|
478
|
+
catch (error) {
|
|
479
|
+
console.error('Error copying object', { sourceObjectName, destinationObjectName, error });
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Check if an object exists
|
|
485
|
+
*/
|
|
486
|
+
async ObjectExists(objectName) {
|
|
487
|
+
try {
|
|
488
|
+
await this._getItemByPath(objectName);
|
|
489
|
+
return true;
|
|
490
|
+
}
|
|
491
|
+
catch (error) {
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Check if a directory exists
|
|
497
|
+
*/
|
|
498
|
+
async DirectoryExists(directoryPath) {
|
|
499
|
+
try {
|
|
500
|
+
// Remove trailing slash if present
|
|
501
|
+
const normalizedPath = directoryPath.endsWith('/')
|
|
502
|
+
? directoryPath.substring(0, directoryPath.length - 1)
|
|
503
|
+
: directoryPath;
|
|
504
|
+
const item = await this._getItemByPath(normalizedPath);
|
|
505
|
+
return item.type === 'folder';
|
|
506
|
+
}
|
|
507
|
+
catch (error) {
|
|
508
|
+
return false;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
exports.BoxFileStorage = BoxFileStorage;
|
|
513
|
+
exports.BoxFileStorage = BoxFileStorage = __decorate([
|
|
514
|
+
(0, global_1.RegisterClass)(FileStorageBase_1.FileStorageBase, 'Box.com Storage'),
|
|
515
|
+
__metadata("design:paramtypes", [])
|
|
516
|
+
], BoxFileStorage);
|
|
517
|
+
//# sourceMappingURL=BoxFileStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BoxFileStorage.js","sourceRoot":"","sources":["../../src/drivers/BoxFileStorage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAAkC;AAClC,mDAAuD;AACvD,6CAA+B;AAC/B,iDAAmC;AACnC,gEAKoC;AAG7B,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,iCAAe;IAKjD;QACE,KAAK,EAAE,CAAC;QALS,iBAAY,GAAG,SAAS,CAAC;QAO1C,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC;QACxE,MAAM,YAAY,GAAG,GAAG,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC;QAChF,MAAM,YAAY,GAAG,GAAG,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC,QAAQ,EAAE,CAAC;QACrE,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC,QAAQ,EAAE,CAAC;QAEzD,4BAA4B;QAC5B,MAAM,MAAM,GAA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G,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC;gBAChD,CAAC,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,EAAE,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;gBACtD,CAAC,CAAC,aAAa,CAAC;YAElB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;YACvD,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC;QAChC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF,CAAA;AA1hBY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,sBAAa,EAAC,iCAAe,EAAE,iBAAiB,CAAC;;GACrC,cAAc,CA0hB1B"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { CreatePreAuthUploadUrlPayload, FileStorageBase, StorageListResult, StorageObjectMetadata } from '../generic/FileStorageBase';
|
|
3
|
+
export declare class DropboxFileStorage extends FileStorageBase {
|
|
4
|
+
protected readonly providerName = "Dropbox";
|
|
5
|
+
private _client;
|
|
6
|
+
private _rootPath;
|
|
7
|
+
constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Normalize a path to be compatible with Dropbox API
|
|
10
|
+
*/
|
|
11
|
+
private _normalizePath;
|
|
12
|
+
/**
|
|
13
|
+
* Get metadata for a file or folder
|
|
14
|
+
*/
|
|
15
|
+
private _getMetadata;
|
|
16
|
+
/**
|
|
17
|
+
* Converts a Dropbox file/folder to StorageObjectMetadata
|
|
18
|
+
*/
|
|
19
|
+
private _convertToMetadata;
|
|
20
|
+
/**
|
|
21
|
+
* Dropbox doesn't support pre-auth upload URLs directly
|
|
22
|
+
*/
|
|
23
|
+
CreatePreAuthUploadUrl(objectName: string): Promise<CreatePreAuthUploadUrlPayload>;
|
|
24
|
+
/**
|
|
25
|
+
* Create a pre-authenticated download URL
|
|
26
|
+
*/
|
|
27
|
+
CreatePreAuthDownloadUrl(objectName: string): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Move an object
|
|
30
|
+
*/
|
|
31
|
+
MoveObject(oldObjectName: string, newObjectName: string): Promise<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* Delete an object
|
|
34
|
+
*/
|
|
35
|
+
DeleteObject(objectName: string): Promise<boolean>;
|
|
36
|
+
/**
|
|
37
|
+
* List objects in a directory
|
|
38
|
+
*/
|
|
39
|
+
ListObjects(prefix: string, delimiter?: string): Promise<StorageListResult>;
|
|
40
|
+
/**
|
|
41
|
+
* Create a directory
|
|
42
|
+
*/
|
|
43
|
+
CreateDirectory(directoryPath: string): Promise<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* Delete a directory
|
|
46
|
+
*/
|
|
47
|
+
DeleteDirectory(directoryPath: string, recursive?: boolean): Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Get object metadata
|
|
50
|
+
*/
|
|
51
|
+
GetObjectMetadata(objectName: string): Promise<StorageObjectMetadata>;
|
|
52
|
+
/**
|
|
53
|
+
* Get an object's contents
|
|
54
|
+
*/
|
|
55
|
+
GetObject(objectName: string): Promise<Buffer>;
|
|
56
|
+
/**
|
|
57
|
+
* Upload an object
|
|
58
|
+
*/
|
|
59
|
+
PutObject(objectName: string, data: Buffer, contentType?: string, metadata?: Record<string, string>): Promise<boolean>;
|
|
60
|
+
/**
|
|
61
|
+
* Copy an object
|
|
62
|
+
*/
|
|
63
|
+
CopyObject(sourceObjectName: string, destinationObjectName: string): Promise<boolean>;
|
|
64
|
+
/**
|
|
65
|
+
* Check if an object exists
|
|
66
|
+
*/
|
|
67
|
+
ObjectExists(objectName: string): Promise<boolean>;
|
|
68
|
+
/**
|
|
69
|
+
* Check if a directory exists
|
|
70
|
+
*/
|
|
71
|
+
DirectoryExists(directoryPath: string): Promise<boolean>;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=DropboxFileStorage.d.ts.map
|
|
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