@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,542 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.GoogleDriveFileStorage = void 0;
|
|
36
|
+
const googleapis_1 = require("googleapis");
|
|
37
|
+
const global_1 = require("@memberjunction/global");
|
|
38
|
+
const env = __importStar(require("env-var"));
|
|
39
|
+
const mime = __importStar(require("mime-types"));
|
|
40
|
+
const FileStorageBase_1 = require("../generic/FileStorageBase");
|
|
41
|
+
let GoogleDriveFileStorage = class GoogleDriveFileStorage extends FileStorageBase_1.FileStorageBase {
|
|
42
|
+
constructor() {
|
|
43
|
+
super();
|
|
44
|
+
this.providerName = 'Google Drive';
|
|
45
|
+
// Get credentials from environment
|
|
46
|
+
const keyFile = env.get('STORAGE_GDRIVE_KEY_FILE').asString();
|
|
47
|
+
const credentials = env.get('STORAGE_GDRIVE_CREDENTIALS_JSON').asJsonObject();
|
|
48
|
+
// Initialize the Google Drive client
|
|
49
|
+
if (keyFile) {
|
|
50
|
+
// Using key file
|
|
51
|
+
const auth = new googleapis_1.google.auth.GoogleAuth({
|
|
52
|
+
keyFile,
|
|
53
|
+
scopes: ['https://www.googleapis.com/auth/drive']
|
|
54
|
+
});
|
|
55
|
+
this._drive = googleapis_1.google.drive({ version: 'v3', auth });
|
|
56
|
+
}
|
|
57
|
+
else if (credentials) {
|
|
58
|
+
// Using credentials directly
|
|
59
|
+
const auth = new googleapis_1.google.auth.JWT(credentials.client_email, undefined, credentials.private_key, ['https://www.googleapis.com/auth/drive']);
|
|
60
|
+
this._drive = googleapis_1.google.drive({ version: 'v3', auth });
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
throw new Error('Google Drive storage requires either STORAGE_GDRIVE_KEY_FILE or STORAGE_GDRIVE_CREDENTIALS_JSON to be set');
|
|
64
|
+
}
|
|
65
|
+
// Optionally set a root folder ID to restrict operations
|
|
66
|
+
this._rootFolderId = env.get('STORAGE_GDRIVE_ROOT_FOLDER_ID').asString();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Finds a file or folder by path
|
|
70
|
+
*/
|
|
71
|
+
async _getItemByPath(path) {
|
|
72
|
+
if (!path || path === '/' || path === '') {
|
|
73
|
+
// Return the root folder or the specified root folder
|
|
74
|
+
return {
|
|
75
|
+
id: this._rootFolderId || 'root',
|
|
76
|
+
name: 'Root',
|
|
77
|
+
mimeType: 'application/vnd.google-apps.folder'
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// Split path into parts
|
|
81
|
+
const pathParts = path.split('/').filter(p => p);
|
|
82
|
+
// Start with root folder or the specified root folder
|
|
83
|
+
let currentParentId = this._rootFolderId || 'root';
|
|
84
|
+
let currentItem = null;
|
|
85
|
+
// Navigate through path parts
|
|
86
|
+
for (let i = 0; i < pathParts.length; i++) {
|
|
87
|
+
const part = pathParts[i];
|
|
88
|
+
const isLastPart = i === pathParts.length - 1;
|
|
89
|
+
// Query for the item
|
|
90
|
+
const query = isLastPart
|
|
91
|
+
? `name = '${part}' and '${currentParentId}' in parents and trashed = false`
|
|
92
|
+
: `name = '${part}' and '${currentParentId}' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed = false`;
|
|
93
|
+
const response = await this._drive.files.list({
|
|
94
|
+
q: query,
|
|
95
|
+
fields: 'files(id, name, mimeType, size, modifiedTime, parents)',
|
|
96
|
+
spaces: 'drive'
|
|
97
|
+
});
|
|
98
|
+
if (!response.data.files || response.data.files.length === 0) {
|
|
99
|
+
throw new Error(`Path not found: ${path} (at part: ${part})`);
|
|
100
|
+
}
|
|
101
|
+
currentItem = response.data.files[0];
|
|
102
|
+
currentParentId = currentItem.id;
|
|
103
|
+
}
|
|
104
|
+
if (!currentItem) {
|
|
105
|
+
throw new Error(`Path not found: ${path}`);
|
|
106
|
+
}
|
|
107
|
+
return currentItem;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Finds a parent folder by path and creates it if it doesn't exist
|
|
111
|
+
*/
|
|
112
|
+
async _getOrCreateParentFolder(path) {
|
|
113
|
+
if (!path || path === '/' || path === '') {
|
|
114
|
+
return this._rootFolderId || 'root';
|
|
115
|
+
}
|
|
116
|
+
// Split path into parts
|
|
117
|
+
const pathParts = path.split('/').filter(p => p);
|
|
118
|
+
// Start with root folder or the specified root folder
|
|
119
|
+
let currentParentId = this._rootFolderId || 'root';
|
|
120
|
+
// Navigate through path parts, creating folders as needed
|
|
121
|
+
for (const part of pathParts) {
|
|
122
|
+
// Check if folder exists
|
|
123
|
+
const query = `name = '${part}' and '${currentParentId}' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed = false`;
|
|
124
|
+
const response = await this._drive.files.list({
|
|
125
|
+
q: query,
|
|
126
|
+
fields: 'files(id)',
|
|
127
|
+
spaces: 'drive'
|
|
128
|
+
});
|
|
129
|
+
if (response.data.files && response.data.files.length > 0) {
|
|
130
|
+
// Folder exists, use it
|
|
131
|
+
currentParentId = response.data.files[0].id;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
// Create the folder
|
|
135
|
+
const folderMetadata = {
|
|
136
|
+
name: part,
|
|
137
|
+
mimeType: 'application/vnd.google-apps.folder',
|
|
138
|
+
parents: [currentParentId]
|
|
139
|
+
};
|
|
140
|
+
const folder = await this._drive.files.create({
|
|
141
|
+
requestBody: folderMetadata,
|
|
142
|
+
fields: 'id'
|
|
143
|
+
});
|
|
144
|
+
currentParentId = folder.data.id;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return currentParentId;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Helper method to convert Google Drive file to StorageObjectMetadata
|
|
151
|
+
*/
|
|
152
|
+
_fileToMetadata(file, parentPath = '') {
|
|
153
|
+
const isDirectory = file.mimeType === 'application/vnd.google-apps.folder';
|
|
154
|
+
const fullPath = parentPath ? `${parentPath}/${file.name}` : file.name;
|
|
155
|
+
return {
|
|
156
|
+
name: file.name,
|
|
157
|
+
path: parentPath,
|
|
158
|
+
fullPath,
|
|
159
|
+
size: parseInt(file.size || '0'),
|
|
160
|
+
contentType: file.mimeType || mime.lookup(file.name) || 'application/octet-stream',
|
|
161
|
+
lastModified: new Date(file.modifiedTime || Date.now()),
|
|
162
|
+
isDirectory,
|
|
163
|
+
etag: file.etag || undefined,
|
|
164
|
+
customMetadata: {
|
|
165
|
+
fileId: file.id
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* PreAuth upload URLs are not directly supported in Google Drive
|
|
171
|
+
*/
|
|
172
|
+
async CreatePreAuthUploadUrl(objectName) {
|
|
173
|
+
// Google Drive doesn't support pre-signed upload URLs in the same way as S3
|
|
174
|
+
// Instead, use PutObject method for uploads
|
|
175
|
+
this.throwUnsupportedOperationError('CreatePreAuthUploadUrl');
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Create a pre-authenticated download URL
|
|
179
|
+
*/
|
|
180
|
+
async CreatePreAuthDownloadUrl(objectName) {
|
|
181
|
+
try {
|
|
182
|
+
// Get the file by path
|
|
183
|
+
const file = await this._getItemByPath(objectName);
|
|
184
|
+
if (!file.id) {
|
|
185
|
+
throw new Error(`File not found: ${objectName}`);
|
|
186
|
+
}
|
|
187
|
+
// Create a temporary web view link
|
|
188
|
+
const permission = await this._drive.permissions.create({
|
|
189
|
+
fileId: file.id,
|
|
190
|
+
requestBody: {
|
|
191
|
+
role: 'reader',
|
|
192
|
+
type: 'anyone',
|
|
193
|
+
expirationTime: new Date(Date.now() + 10 * 60 * 1000).toISOString() // 10 minutes
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
// Get web view link
|
|
197
|
+
const fileInfo = await this._drive.files.get({
|
|
198
|
+
fileId: file.id,
|
|
199
|
+
fields: 'webViewLink, webContentLink'
|
|
200
|
+
});
|
|
201
|
+
// Prefer direct download link if available
|
|
202
|
+
return fileInfo.data.webContentLink || fileInfo.data.webViewLink;
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
console.error('Error creating pre-auth download URL', { objectName, error });
|
|
206
|
+
throw new Error(`Failed to create download URL for: ${objectName}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Move an object from one location to another
|
|
211
|
+
*/
|
|
212
|
+
async MoveObject(oldObjectName, newObjectName) {
|
|
213
|
+
try {
|
|
214
|
+
// Get the file to move
|
|
215
|
+
const file = await this._getItemByPath(oldObjectName);
|
|
216
|
+
if (!file.id) {
|
|
217
|
+
throw new Error(`File not found: ${oldObjectName}`);
|
|
218
|
+
}
|
|
219
|
+
// Parse new path to get parent folder and new name
|
|
220
|
+
const newPathParts = newObjectName.split('/');
|
|
221
|
+
const newName = newPathParts.pop() || '';
|
|
222
|
+
const newParentPath = newPathParts.join('/');
|
|
223
|
+
// Get or create the destination folder
|
|
224
|
+
const newParentId = await this._getOrCreateParentFolder(newParentPath);
|
|
225
|
+
// Move the file by updating parent and name
|
|
226
|
+
await this._drive.files.update({
|
|
227
|
+
fileId: file.id,
|
|
228
|
+
requestBody: {
|
|
229
|
+
name: newName
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
// Update parents (remove old parents and add new parent)
|
|
233
|
+
await this._drive.files.update({
|
|
234
|
+
fileId: file.id,
|
|
235
|
+
removeParents: file.parents?.join(','),
|
|
236
|
+
addParents: newParentId,
|
|
237
|
+
fields: 'id, parents'
|
|
238
|
+
});
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
console.error('Error moving object', { oldObjectName, newObjectName, error });
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Delete an object
|
|
248
|
+
*/
|
|
249
|
+
async DeleteObject(objectName) {
|
|
250
|
+
try {
|
|
251
|
+
// Get the file to delete
|
|
252
|
+
const file = await this._getItemByPath(objectName);
|
|
253
|
+
if (!file.id) {
|
|
254
|
+
// If file doesn't exist, consider it success for idempotency
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
// Delete the file (move to trash)
|
|
258
|
+
await this._drive.files.delete({
|
|
259
|
+
fileId: file.id
|
|
260
|
+
});
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
// If file not found, consider it success
|
|
265
|
+
if (error.code === 404) {
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
console.error('Error deleting object', { objectName, error });
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* List objects in a directory
|
|
274
|
+
*/
|
|
275
|
+
async ListObjects(prefix, delimiter = '/') {
|
|
276
|
+
try {
|
|
277
|
+
// Get the folder
|
|
278
|
+
const folder = await this._getItemByPath(prefix);
|
|
279
|
+
if (!folder.id) {
|
|
280
|
+
throw new Error(`Folder not found: ${prefix}`);
|
|
281
|
+
}
|
|
282
|
+
// List files in the folder
|
|
283
|
+
const response = await this._drive.files.list({
|
|
284
|
+
q: `'${folder.id}' in parents and trashed = false`,
|
|
285
|
+
fields: 'files(id, name, mimeType, size, modifiedTime, parents)',
|
|
286
|
+
spaces: 'drive'
|
|
287
|
+
});
|
|
288
|
+
const objects = [];
|
|
289
|
+
const prefixes = [];
|
|
290
|
+
if (response.data.files && response.data.files.length > 0) {
|
|
291
|
+
for (const file of response.data.files) {
|
|
292
|
+
// Add to objects list
|
|
293
|
+
objects.push(this._fileToMetadata(file, prefix));
|
|
294
|
+
// If it's a folder, add to prefixes
|
|
295
|
+
if (file.mimeType === 'application/vnd.google-apps.folder') {
|
|
296
|
+
const folderPath = prefix
|
|
297
|
+
? (prefix.endsWith('/') ? `${prefix}${file.name}` : `${prefix}/${file.name}`)
|
|
298
|
+
: file.name;
|
|
299
|
+
prefixes.push(`${folderPath}/`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return { objects, prefixes };
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
console.error('Error listing objects', { prefix, error });
|
|
307
|
+
return { objects: [], prefixes: [] };
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Create a directory
|
|
312
|
+
*/
|
|
313
|
+
async CreateDirectory(directoryPath) {
|
|
314
|
+
try {
|
|
315
|
+
// Remove trailing slash if present
|
|
316
|
+
const normalizedPath = directoryPath.endsWith('/')
|
|
317
|
+
? directoryPath.substring(0, directoryPath.length - 1)
|
|
318
|
+
: directoryPath;
|
|
319
|
+
// Parse path
|
|
320
|
+
const pathParts = normalizedPath.split('/');
|
|
321
|
+
const folderName = pathParts.pop() || '';
|
|
322
|
+
const parentPath = pathParts.join('/');
|
|
323
|
+
// Get parent folder
|
|
324
|
+
const parentId = await this._getOrCreateParentFolder(parentPath);
|
|
325
|
+
// Create the folder
|
|
326
|
+
const folderMetadata = {
|
|
327
|
+
name: folderName,
|
|
328
|
+
mimeType: 'application/vnd.google-apps.folder',
|
|
329
|
+
parents: [parentId]
|
|
330
|
+
};
|
|
331
|
+
await this._drive.files.create({
|
|
332
|
+
requestBody: folderMetadata,
|
|
333
|
+
fields: 'id'
|
|
334
|
+
});
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
catch (error) {
|
|
338
|
+
console.error('Error creating directory', { directoryPath, error });
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Delete a directory and optionally its contents
|
|
344
|
+
*/
|
|
345
|
+
async DeleteDirectory(directoryPath, recursive = false) {
|
|
346
|
+
try {
|
|
347
|
+
// Remove trailing slash if present
|
|
348
|
+
const normalizedPath = directoryPath.endsWith('/')
|
|
349
|
+
? directoryPath.substring(0, directoryPath.length - 1)
|
|
350
|
+
: directoryPath;
|
|
351
|
+
// Get the folder
|
|
352
|
+
const folder = await this._getItemByPath(normalizedPath);
|
|
353
|
+
if (!folder.id) {
|
|
354
|
+
// If folder doesn't exist, consider it success
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
if (!recursive) {
|
|
358
|
+
// Check if folder is empty
|
|
359
|
+
const response = await this._drive.files.list({
|
|
360
|
+
q: `'${folder.id}' in parents and trashed = false`,
|
|
361
|
+
fields: 'files(id)',
|
|
362
|
+
spaces: 'drive'
|
|
363
|
+
});
|
|
364
|
+
if (response.data.files && response.data.files.length > 0) {
|
|
365
|
+
throw new Error('Directory is not empty');
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
// Delete the folder
|
|
369
|
+
await this._drive.files.delete({
|
|
370
|
+
fileId: folder.id
|
|
371
|
+
});
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
catch (error) {
|
|
375
|
+
console.error('Error deleting directory', { directoryPath, recursive, error });
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Get object metadata
|
|
381
|
+
*/
|
|
382
|
+
async GetObjectMetadata(objectName) {
|
|
383
|
+
try {
|
|
384
|
+
// Get the file
|
|
385
|
+
const file = await this._getItemByPath(objectName);
|
|
386
|
+
if (!file.id) {
|
|
387
|
+
throw new Error(`File not found: ${objectName}`);
|
|
388
|
+
}
|
|
389
|
+
// Parse path to get parent path
|
|
390
|
+
const pathParts = objectName.split('/');
|
|
391
|
+
pathParts.pop(); // Remove filename
|
|
392
|
+
const parentPath = pathParts.join('/');
|
|
393
|
+
return this._fileToMetadata(file, parentPath);
|
|
394
|
+
}
|
|
395
|
+
catch (error) {
|
|
396
|
+
console.error('Error getting object metadata', { objectName, error });
|
|
397
|
+
throw new Error(`Object not found: ${objectName}`);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Get object contents
|
|
402
|
+
*/
|
|
403
|
+
async GetObject(objectName) {
|
|
404
|
+
try {
|
|
405
|
+
// Get the file
|
|
406
|
+
const file = await this._getItemByPath(objectName);
|
|
407
|
+
if (!file.id) {
|
|
408
|
+
throw new Error(`File not found: ${objectName}`);
|
|
409
|
+
}
|
|
410
|
+
// Download the file
|
|
411
|
+
const response = await this._drive.files.get({
|
|
412
|
+
fileId: file.id,
|
|
413
|
+
alt: 'media'
|
|
414
|
+
}, {
|
|
415
|
+
responseType: 'arraybuffer'
|
|
416
|
+
});
|
|
417
|
+
return Buffer.from(response.data);
|
|
418
|
+
}
|
|
419
|
+
catch (error) {
|
|
420
|
+
console.error('Error getting object', { objectName, error });
|
|
421
|
+
throw new Error(`Failed to get object: ${objectName}`);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Upload an object
|
|
426
|
+
*/
|
|
427
|
+
async PutObject(objectName, data, contentType, metadata) {
|
|
428
|
+
try {
|
|
429
|
+
// Parse path
|
|
430
|
+
const pathParts = objectName.split('/');
|
|
431
|
+
const fileName = pathParts.pop() || '';
|
|
432
|
+
const parentPath = pathParts.join('/');
|
|
433
|
+
// Get or create parent folder
|
|
434
|
+
const parentId = await this._getOrCreateParentFolder(parentPath);
|
|
435
|
+
// Determine content type
|
|
436
|
+
const effectiveContentType = contentType || mime.lookup(objectName) || 'application/octet-stream';
|
|
437
|
+
// Check if file already exists to decide whether to create or update
|
|
438
|
+
let existingFileId = null;
|
|
439
|
+
try {
|
|
440
|
+
const existingFile = await this._getItemByPath(objectName);
|
|
441
|
+
existingFileId = existingFile.id || null;
|
|
442
|
+
}
|
|
443
|
+
catch (error) {
|
|
444
|
+
// File doesn't exist, will create new
|
|
445
|
+
}
|
|
446
|
+
if (existingFileId) {
|
|
447
|
+
// Update existing file
|
|
448
|
+
await this._drive.files.update({
|
|
449
|
+
fileId: existingFileId,
|
|
450
|
+
media: {
|
|
451
|
+
body: data,
|
|
452
|
+
mimeType: effectiveContentType
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
// Create new file
|
|
458
|
+
await this._drive.files.create({
|
|
459
|
+
requestBody: {
|
|
460
|
+
name: fileName,
|
|
461
|
+
parents: [parentId]
|
|
462
|
+
},
|
|
463
|
+
media: {
|
|
464
|
+
body: data,
|
|
465
|
+
mimeType: effectiveContentType
|
|
466
|
+
},
|
|
467
|
+
fields: 'id'
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
return true;
|
|
471
|
+
}
|
|
472
|
+
catch (error) {
|
|
473
|
+
console.error('Error putting object', { objectName, error });
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Copy an object
|
|
479
|
+
*/
|
|
480
|
+
async CopyObject(sourceObjectName, destinationObjectName) {
|
|
481
|
+
try {
|
|
482
|
+
// Get source file
|
|
483
|
+
const sourceFile = await this._getItemByPath(sourceObjectName);
|
|
484
|
+
if (!sourceFile.id) {
|
|
485
|
+
throw new Error(`Source file not found: ${sourceObjectName}`);
|
|
486
|
+
}
|
|
487
|
+
// Parse destination path
|
|
488
|
+
const destPathParts = destinationObjectName.split('/');
|
|
489
|
+
const destFileName = destPathParts.pop() || '';
|
|
490
|
+
const destParentPath = destPathParts.join('/');
|
|
491
|
+
// Get or create destination parent folder
|
|
492
|
+
const destParentId = await this._getOrCreateParentFolder(destParentPath);
|
|
493
|
+
// Copy the file
|
|
494
|
+
await this._drive.files.copy({
|
|
495
|
+
fileId: sourceFile.id,
|
|
496
|
+
requestBody: {
|
|
497
|
+
name: destFileName,
|
|
498
|
+
parents: [destParentId]
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
return true;
|
|
502
|
+
}
|
|
503
|
+
catch (error) {
|
|
504
|
+
console.error('Error copying object', { sourceObjectName, destinationObjectName, error });
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Check if an object exists
|
|
510
|
+
*/
|
|
511
|
+
async ObjectExists(objectName) {
|
|
512
|
+
try {
|
|
513
|
+
await this._getItemByPath(objectName);
|
|
514
|
+
return true;
|
|
515
|
+
}
|
|
516
|
+
catch (error) {
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Check if a directory exists
|
|
522
|
+
*/
|
|
523
|
+
async DirectoryExists(directoryPath) {
|
|
524
|
+
try {
|
|
525
|
+
// Remove trailing slash if present
|
|
526
|
+
const normalizedPath = directoryPath.endsWith('/')
|
|
527
|
+
? directoryPath.substring(0, directoryPath.length - 1)
|
|
528
|
+
: directoryPath;
|
|
529
|
+
const item = await this._getItemByPath(normalizedPath);
|
|
530
|
+
return item.mimeType === 'application/vnd.google-apps.folder';
|
|
531
|
+
}
|
|
532
|
+
catch (error) {
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
exports.GoogleDriveFileStorage = GoogleDriveFileStorage;
|
|
538
|
+
exports.GoogleDriveFileStorage = GoogleDriveFileStorage = __decorate([
|
|
539
|
+
(0, global_1.RegisterClass)(FileStorageBase_1.FileStorageBase, 'Google Drive Storage'),
|
|
540
|
+
__metadata("design:paramtypes", [])
|
|
541
|
+
], GoogleDriveFileStorage);
|
|
542
|
+
//# sourceMappingURL=GoogleDriveFileStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GoogleDriveFileStorage.js","sourceRoot":"","sources":["../../src/drivers/GoogleDriveFileStorage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA8C;AAC9C,mDAAuD;AACvD,6CAA+B;AAC/B,iDAAmC;AACnC,gEAKoC;AAG7B,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,iCAAe;IAK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,YAAY,CAAC,UAAkB;QAC1C,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;YACtC,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,eAAe,CAAC,aAAqB;QAChD,IAAI,CAAC;YACH,mCAAmC;YACnC,MAAM,cAAc,GAAG,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,QAAQ,KAAK,oCAAoC,CAAC;QAChE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF,CAAA;AAjkBY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,sBAAa,EAAC,iCAAe,EAAE,sBAAsB,CAAC;;GAC1C,sBAAsB,CAikBlC"}
|
|
@@ -1,11 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { CreatePreAuthUploadUrlPayload, FileStorageBase, StorageListResult, StorageObjectMetadata } from '../generic/FileStorageBase';
|
|
2
3
|
export declare class GoogleFileStorage extends FileStorageBase {
|
|
4
|
+
protected readonly providerName = "Google Cloud Storage";
|
|
3
5
|
private _bucket;
|
|
4
6
|
private _client;
|
|
5
7
|
constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Normalizes directory paths to ensure they end with a slash
|
|
10
|
+
*/
|
|
11
|
+
private _normalizeDirectoryPath;
|
|
12
|
+
/**
|
|
13
|
+
* Converts metadata to a string map for consistent handling
|
|
14
|
+
*/
|
|
15
|
+
private _convertMetadataToStringMap;
|
|
6
16
|
CreatePreAuthUploadUrl(objectName: string): Promise<CreatePreAuthUploadUrlPayload>;
|
|
7
17
|
CreatePreAuthDownloadUrl(objectName: string): Promise<string>;
|
|
8
18
|
MoveObject(oldObjectName: string, newObjectName: string): Promise<boolean>;
|
|
9
19
|
DeleteObject(objectName: string): Promise<boolean>;
|
|
20
|
+
ListObjects(prefix: string, delimiter?: string): Promise<StorageListResult>;
|
|
21
|
+
CreateDirectory(directoryPath: string): Promise<boolean>;
|
|
22
|
+
DeleteDirectory(directoryPath: string, recursive?: boolean): Promise<boolean>;
|
|
23
|
+
GetObjectMetadata(objectName: string): Promise<StorageObjectMetadata>;
|
|
24
|
+
GetObject(objectName: string): Promise<Buffer>;
|
|
25
|
+
PutObject(objectName: string, data: Buffer, contentType?: string, metadata?: Record<string, string>): Promise<boolean>;
|
|
26
|
+
CopyObject(sourceObjectName: string, destinationObjectName: string): Promise<boolean>;
|
|
27
|
+
ObjectExists(objectName: string): Promise<boolean>;
|
|
28
|
+
DirectoryExists(directoryPath: string): Promise<boolean>;
|
|
10
29
|
}
|
|
11
30
|
//# sourceMappingURL=GoogleFileStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GoogleFileStorage.d.ts","sourceRoot":"","sources":["../../src/drivers/GoogleFileStorage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GoogleFileStorage.d.ts","sourceRoot":"","sources":["../../src/drivers/GoogleFileStorage.ts"],"names":[],"mappings":";AAIA,OAAO,EACL,6BAA6B,EAC7B,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,4BAA4B,CAAC;AAEpC,qBACa,iBAAkB,SAAQ,eAAe;IACpD,SAAS,CAAC,QAAQ,CAAC,YAAY,0BAA0B;IACzD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAU;;IASzB;;OAEG;IACH,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