@pelatform/storage 1.0.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/LICENSE +21 -0
- package/README.md +10 -0
- package/dist/chunk-GV7GMZP2.cjs +413 -0
- package/dist/chunk-I3ME6WAG.cjs +169 -0
- package/dist/chunk-KJMGBTTL.js +413 -0
- package/dist/chunk-ZTZZCC52.js +169 -0
- package/dist/cloudinary.cjs +496 -0
- package/dist/cloudinary.d.cts +93 -0
- package/dist/cloudinary.d.ts +93 -0
- package/dist/cloudinary.js +496 -0
- package/dist/helpers.cjs +68 -0
- package/dist/helpers.d.cts +762 -0
- package/dist/helpers.d.ts +762 -0
- package/dist/helpers.js +68 -0
- package/dist/index.cjs +24 -0
- package/dist/index.d.cts +281 -0
- package/dist/index.d.ts +281 -0
- package/dist/index.js +24 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/s3.cjs +799 -0
- package/dist/s3.d.cts +108 -0
- package/dist/s3.d.ts +108 -0
- package/dist/s3.js +799 -0
- package/dist/storage-interface-BKeDAlGP.d.cts +316 -0
- package/dist/storage-interface-BKeDAlGP.d.ts +316 -0
- package/package.json +103 -0
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkI3ME6WAGcjs = require('./chunk-I3ME6WAG.cjs');
|
|
4
|
+
|
|
5
|
+
// src/providers/cloudinary.ts
|
|
6
|
+
var _cloudinary = require('cloudinary');
|
|
7
|
+
var CloudinaryProvider = class {
|
|
8
|
+
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
_cloudinary.v2.config({
|
|
12
|
+
cloud_name: config.cloudName,
|
|
13
|
+
api_key: config.apiKey,
|
|
14
|
+
api_secret: config.apiSecret,
|
|
15
|
+
secure: config.secure !== false
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
// File operations
|
|
19
|
+
async upload(options) {
|
|
20
|
+
try {
|
|
21
|
+
let fileData;
|
|
22
|
+
if (typeof options.file === "string") {
|
|
23
|
+
fileData = options.file;
|
|
24
|
+
} else {
|
|
25
|
+
fileData = `data:${options.contentType || "application/octet-stream"};base64,${Buffer.from(options.file).toString("base64")}`;
|
|
26
|
+
}
|
|
27
|
+
let resourceType = "raw";
|
|
28
|
+
if (_optionalChain([options, 'access', _ => _.contentType, 'optionalAccess', _2 => _2.startsWith, 'call', _3 => _3("image/")])) {
|
|
29
|
+
resourceType = "image";
|
|
30
|
+
} else if (_optionalChain([options, 'access', _4 => _4.contentType, 'optionalAccess', _5 => _5.startsWith, 'call', _6 => _6("video/")])) {
|
|
31
|
+
resourceType = "video";
|
|
32
|
+
}
|
|
33
|
+
const keyParts = options.key.split("/");
|
|
34
|
+
let folder = "";
|
|
35
|
+
let publicId = options.key;
|
|
36
|
+
if (keyParts.length > 1) {
|
|
37
|
+
folder = keyParts.slice(0, -1).join("/");
|
|
38
|
+
publicId = keyParts[keyParts.length - 1];
|
|
39
|
+
}
|
|
40
|
+
const uploadOptions = {
|
|
41
|
+
public_id: publicId,
|
|
42
|
+
resource_type: resourceType,
|
|
43
|
+
overwrite: true,
|
|
44
|
+
invalidate: true,
|
|
45
|
+
...options.metadata
|
|
46
|
+
};
|
|
47
|
+
if (folder) {
|
|
48
|
+
uploadOptions.folder = folder;
|
|
49
|
+
}
|
|
50
|
+
const result = await _cloudinary.v2.uploader.upload(fileData, uploadOptions);
|
|
51
|
+
const publicUrl = this.getPublicUrl(result.public_id);
|
|
52
|
+
return {
|
|
53
|
+
success: true,
|
|
54
|
+
key: result.public_id,
|
|
55
|
+
url: result.secure_url,
|
|
56
|
+
publicUrl,
|
|
57
|
+
etag: result.etag,
|
|
58
|
+
size: result.bytes
|
|
59
|
+
};
|
|
60
|
+
} catch (error) {
|
|
61
|
+
return {
|
|
62
|
+
success: false,
|
|
63
|
+
error: error instanceof Error ? error.message : "Upload failed"
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async download(options) {
|
|
68
|
+
try {
|
|
69
|
+
const publicUrl = this.getPublicUrl(options.key);
|
|
70
|
+
const response = await fetch(publicUrl);
|
|
71
|
+
if (!response.ok) {
|
|
72
|
+
return {
|
|
73
|
+
success: false,
|
|
74
|
+
error: `Failed to download: ${response.status} ${response.statusText}`
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
78
|
+
const content = Buffer.from(arrayBuffer);
|
|
79
|
+
return {
|
|
80
|
+
success: true,
|
|
81
|
+
content,
|
|
82
|
+
// Main content field
|
|
83
|
+
data: content,
|
|
84
|
+
// Alias for backward compatibility
|
|
85
|
+
contentType: response.headers.get("content-type") || void 0,
|
|
86
|
+
contentLength: content.length,
|
|
87
|
+
lastModified: response.headers.get("last-modified") ? new Date(response.headers.get("last-modified")) : /* @__PURE__ */ new Date()
|
|
88
|
+
};
|
|
89
|
+
} catch (error) {
|
|
90
|
+
return {
|
|
91
|
+
success: false,
|
|
92
|
+
error: error instanceof Error ? error.message : "Download failed"
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async delete(options) {
|
|
97
|
+
try {
|
|
98
|
+
const keyParts = options.key.split("/");
|
|
99
|
+
let publicId = options.key;
|
|
100
|
+
if (keyParts.length > 1) {
|
|
101
|
+
const folder = keyParts.slice(0, -1).join("/");
|
|
102
|
+
const filename = keyParts[keyParts.length - 1];
|
|
103
|
+
publicId = `${folder}/${filename}`;
|
|
104
|
+
}
|
|
105
|
+
let resourceType = "raw";
|
|
106
|
+
try {
|
|
107
|
+
await _cloudinary.v2.api.resource(publicId, { resource_type: "image" });
|
|
108
|
+
resourceType = "image";
|
|
109
|
+
} catch (e) {
|
|
110
|
+
try {
|
|
111
|
+
await _cloudinary.v2.api.resource(publicId, { resource_type: "video" });
|
|
112
|
+
resourceType = "video";
|
|
113
|
+
} catch (e2) {
|
|
114
|
+
resourceType = "raw";
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
await _cloudinary.v2.uploader.destroy(publicId, {
|
|
118
|
+
resource_type: resourceType,
|
|
119
|
+
invalidate: true
|
|
120
|
+
});
|
|
121
|
+
return {
|
|
122
|
+
success: true
|
|
123
|
+
};
|
|
124
|
+
} catch (error) {
|
|
125
|
+
return {
|
|
126
|
+
success: false,
|
|
127
|
+
error: error instanceof Error ? error.message : "Delete failed"
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async batchDelete(options) {
|
|
132
|
+
try {
|
|
133
|
+
return {
|
|
134
|
+
success: false,
|
|
135
|
+
errors: options.keys.map((key) => ({
|
|
136
|
+
key,
|
|
137
|
+
error: "Cloudinary batch delete not implemented yet"
|
|
138
|
+
}))
|
|
139
|
+
};
|
|
140
|
+
} catch (error) {
|
|
141
|
+
return {
|
|
142
|
+
success: false,
|
|
143
|
+
errors: options.keys.map((key) => ({
|
|
144
|
+
key,
|
|
145
|
+
error: error instanceof Error ? error.message : "Batch delete failed"
|
|
146
|
+
}))
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async list(options = {}) {
|
|
151
|
+
try {
|
|
152
|
+
const prefix = options.prefix || "";
|
|
153
|
+
const maxResults = options.maxKeys || 50;
|
|
154
|
+
const [images, videos, rawFiles] = await Promise.all([
|
|
155
|
+
_cloudinary.v2.api.resources({
|
|
156
|
+
type: "upload",
|
|
157
|
+
resource_type: "image",
|
|
158
|
+
prefix,
|
|
159
|
+
max_results: maxResults,
|
|
160
|
+
next_cursor: options.continuationToken
|
|
161
|
+
}).catch(() => ({ resources: [], next_cursor: void 0 })),
|
|
162
|
+
_cloudinary.v2.api.resources({
|
|
163
|
+
type: "upload",
|
|
164
|
+
resource_type: "video",
|
|
165
|
+
prefix,
|
|
166
|
+
max_results: maxResults,
|
|
167
|
+
next_cursor: options.continuationToken
|
|
168
|
+
}).catch(() => ({ resources: [], next_cursor: void 0 })),
|
|
169
|
+
_cloudinary.v2.api.resources({
|
|
170
|
+
type: "upload",
|
|
171
|
+
resource_type: "raw",
|
|
172
|
+
prefix,
|
|
173
|
+
max_results: maxResults,
|
|
174
|
+
next_cursor: options.continuationToken
|
|
175
|
+
}).catch(() => ({ resources: [], next_cursor: void 0 }))
|
|
176
|
+
]);
|
|
177
|
+
const allResources = [
|
|
178
|
+
...images.resources || [],
|
|
179
|
+
...videos.resources || [],
|
|
180
|
+
...rawFiles.resources || []
|
|
181
|
+
];
|
|
182
|
+
const files = allResources.map((resource) => ({
|
|
183
|
+
key: String(resource.public_id || ""),
|
|
184
|
+
size: Number(resource.bytes) || 0,
|
|
185
|
+
lastModified: new Date(String(resource.created_at || /* @__PURE__ */ new Date())),
|
|
186
|
+
etag: String(resource.etag || ""),
|
|
187
|
+
contentType: resource.format ? `${resource.resource_type}/${resource.format}` : "application/octet-stream"
|
|
188
|
+
}));
|
|
189
|
+
return {
|
|
190
|
+
success: true,
|
|
191
|
+
files,
|
|
192
|
+
isTruncated: !!(images.next_cursor || videos.next_cursor || rawFiles.next_cursor),
|
|
193
|
+
nextContinuationToken: images.next_cursor || videos.next_cursor || rawFiles.next_cursor
|
|
194
|
+
};
|
|
195
|
+
} catch (error) {
|
|
196
|
+
return {
|
|
197
|
+
success: false,
|
|
198
|
+
error: error instanceof Error ? error.message : "List failed"
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
async exists(_key) {
|
|
203
|
+
try {
|
|
204
|
+
return {
|
|
205
|
+
exists: false,
|
|
206
|
+
error: "Cloudinary exists check not implemented yet"
|
|
207
|
+
};
|
|
208
|
+
} catch (error) {
|
|
209
|
+
return {
|
|
210
|
+
exists: false,
|
|
211
|
+
error: error instanceof Error ? error.message : "Check existence failed"
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
async copy(_options) {
|
|
216
|
+
try {
|
|
217
|
+
return {
|
|
218
|
+
success: false,
|
|
219
|
+
error: "Cloudinary copy not implemented yet"
|
|
220
|
+
};
|
|
221
|
+
} catch (error) {
|
|
222
|
+
return {
|
|
223
|
+
success: false,
|
|
224
|
+
error: error instanceof Error ? error.message : "Copy failed"
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
async move(_options) {
|
|
229
|
+
try {
|
|
230
|
+
return {
|
|
231
|
+
success: false,
|
|
232
|
+
error: "Cloudinary move not implemented yet"
|
|
233
|
+
};
|
|
234
|
+
} catch (error) {
|
|
235
|
+
return {
|
|
236
|
+
success: false,
|
|
237
|
+
error: error instanceof Error ? error.message : "Move failed"
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
async duplicate(options) {
|
|
242
|
+
return this.copy(options);
|
|
243
|
+
}
|
|
244
|
+
async getPresignedUrl(_options) {
|
|
245
|
+
try {
|
|
246
|
+
return {
|
|
247
|
+
success: false,
|
|
248
|
+
error: "Cloudinary presigned URL not implemented yet"
|
|
249
|
+
};
|
|
250
|
+
} catch (error) {
|
|
251
|
+
return {
|
|
252
|
+
success: false,
|
|
253
|
+
error: error instanceof Error ? error.message : "Presigned URL generation failed"
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
getPublicUrl(key) {
|
|
258
|
+
const protocol = this.config.secure !== false ? "https" : "http";
|
|
259
|
+
const baseUrl = `${protocol}://res.cloudinary.com/${this.config.cloudName}`;
|
|
260
|
+
const publicId = key;
|
|
261
|
+
return `${baseUrl}/image/upload/${publicId}`;
|
|
262
|
+
}
|
|
263
|
+
// Folder operations
|
|
264
|
+
async createFolder(options) {
|
|
265
|
+
try {
|
|
266
|
+
return {
|
|
267
|
+
success: true,
|
|
268
|
+
path: options.path
|
|
269
|
+
};
|
|
270
|
+
} catch (error) {
|
|
271
|
+
return {
|
|
272
|
+
success: false,
|
|
273
|
+
error: error instanceof Error ? error.message : "Create folder failed"
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
async deleteFolder(options) {
|
|
278
|
+
try {
|
|
279
|
+
const folderPath = options.path.endsWith("/") ? options.path.slice(0, -1) : options.path;
|
|
280
|
+
if (options.recursive) {
|
|
281
|
+
await _cloudinary.v2.api.delete_resources_by_prefix(folderPath);
|
|
282
|
+
}
|
|
283
|
+
await _cloudinary.v2.api.delete_folder(folderPath);
|
|
284
|
+
return {
|
|
285
|
+
success: true
|
|
286
|
+
};
|
|
287
|
+
} catch (error) {
|
|
288
|
+
return {
|
|
289
|
+
success: false,
|
|
290
|
+
error: error instanceof Error ? error.message : "Delete folder failed"
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
async listFolders(_options) {
|
|
295
|
+
try {
|
|
296
|
+
const result = await _cloudinary.v2.api.root_folders();
|
|
297
|
+
const folders = (result.folders || []).map((folder) => ({
|
|
298
|
+
name: folder.name,
|
|
299
|
+
path: folder.path
|
|
300
|
+
}));
|
|
301
|
+
return {
|
|
302
|
+
success: true,
|
|
303
|
+
folders,
|
|
304
|
+
isTruncated: false,
|
|
305
|
+
nextContinuationToken: void 0
|
|
306
|
+
};
|
|
307
|
+
} catch (error) {
|
|
308
|
+
return {
|
|
309
|
+
success: false,
|
|
310
|
+
error: error instanceof Error ? error.message : "List folders failed"
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
async folderExists(_path) {
|
|
315
|
+
try {
|
|
316
|
+
return {
|
|
317
|
+
exists: false,
|
|
318
|
+
error: "Cloudinary folder exists check not implemented yet"
|
|
319
|
+
};
|
|
320
|
+
} catch (error) {
|
|
321
|
+
return {
|
|
322
|
+
exists: false,
|
|
323
|
+
error: error instanceof Error ? error.message : "Check folder existence failed"
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
async renameFolder(_options) {
|
|
328
|
+
try {
|
|
329
|
+
return {
|
|
330
|
+
success: false,
|
|
331
|
+
error: "Cloudinary rename folder not implemented yet"
|
|
332
|
+
};
|
|
333
|
+
} catch (error) {
|
|
334
|
+
return {
|
|
335
|
+
success: false,
|
|
336
|
+
error: error instanceof Error ? error.message : "Rename folder failed"
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
async copyFolder(_options) {
|
|
341
|
+
try {
|
|
342
|
+
return {
|
|
343
|
+
success: false,
|
|
344
|
+
error: "Cloudinary copy folder not implemented yet"
|
|
345
|
+
};
|
|
346
|
+
} catch (error) {
|
|
347
|
+
return {
|
|
348
|
+
success: false,
|
|
349
|
+
error: error instanceof Error ? error.message : "Copy folder failed"
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
// src/services/cloudinary.ts
|
|
356
|
+
var CloudinaryService = class {
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
constructor(config) {
|
|
360
|
+
this.config = config || _chunkI3ME6WAGcjs.loadCloudinaryConfig.call(void 0, );
|
|
361
|
+
this.provider = new CloudinaryProvider(this.config);
|
|
362
|
+
}
|
|
363
|
+
// Utility methods
|
|
364
|
+
getConfig() {
|
|
365
|
+
return { ...this.config };
|
|
366
|
+
}
|
|
367
|
+
getProvider() {
|
|
368
|
+
return this.config.provider;
|
|
369
|
+
}
|
|
370
|
+
getPublicUrl(key) {
|
|
371
|
+
return this.provider.getPublicUrl(key);
|
|
372
|
+
}
|
|
373
|
+
// File operations
|
|
374
|
+
async upload(options) {
|
|
375
|
+
return this.provider.upload(options);
|
|
376
|
+
}
|
|
377
|
+
async download(options) {
|
|
378
|
+
return this.provider.download(options);
|
|
379
|
+
}
|
|
380
|
+
async delete(options) {
|
|
381
|
+
return this.provider.delete(options);
|
|
382
|
+
}
|
|
383
|
+
async batchDelete(options) {
|
|
384
|
+
return this.provider.batchDelete(options);
|
|
385
|
+
}
|
|
386
|
+
async list(options) {
|
|
387
|
+
return this.provider.list(options);
|
|
388
|
+
}
|
|
389
|
+
async exists(key) {
|
|
390
|
+
return this.provider.exists(key);
|
|
391
|
+
}
|
|
392
|
+
async copy(options) {
|
|
393
|
+
return this.provider.copy(options);
|
|
394
|
+
}
|
|
395
|
+
async move(options) {
|
|
396
|
+
return this.provider.move(options);
|
|
397
|
+
}
|
|
398
|
+
async duplicate(options) {
|
|
399
|
+
return this.provider.duplicate(options);
|
|
400
|
+
}
|
|
401
|
+
async getPresignedUrl(options) {
|
|
402
|
+
return this.provider.getPresignedUrl(options);
|
|
403
|
+
}
|
|
404
|
+
// Folder operations
|
|
405
|
+
async createFolder(options) {
|
|
406
|
+
return this.provider.createFolder(options);
|
|
407
|
+
}
|
|
408
|
+
async deleteFolder(options) {
|
|
409
|
+
return this.provider.deleteFolder(options);
|
|
410
|
+
}
|
|
411
|
+
async listFolders(options) {
|
|
412
|
+
return this.provider.listFolders(options);
|
|
413
|
+
}
|
|
414
|
+
async folderExists(path) {
|
|
415
|
+
return this.provider.folderExists(path);
|
|
416
|
+
}
|
|
417
|
+
async renameFolder(options) {
|
|
418
|
+
return this.provider.renameFolder(options);
|
|
419
|
+
}
|
|
420
|
+
async copyFolder(options) {
|
|
421
|
+
return this.provider.copyFolder(options);
|
|
422
|
+
}
|
|
423
|
+
// Convenience methods
|
|
424
|
+
async uploadFile(key, file, contentType, metadata) {
|
|
425
|
+
return this.upload({ key, file, contentType, metadata });
|
|
426
|
+
}
|
|
427
|
+
async downloadFile(key) {
|
|
428
|
+
return this.download({ key });
|
|
429
|
+
}
|
|
430
|
+
async deleteFile(key) {
|
|
431
|
+
return this.delete({ key });
|
|
432
|
+
}
|
|
433
|
+
async deleteFiles(keys) {
|
|
434
|
+
return this.batchDelete({ keys });
|
|
435
|
+
}
|
|
436
|
+
async fileExists(key) {
|
|
437
|
+
const result = await this.exists(key);
|
|
438
|
+
return result.exists;
|
|
439
|
+
}
|
|
440
|
+
async copyFile(sourceKey, destinationKey, metadata) {
|
|
441
|
+
return this.copy({ sourceKey, destinationKey, metadata });
|
|
442
|
+
}
|
|
443
|
+
async moveFile(sourceKey, destinationKey, metadata) {
|
|
444
|
+
return this.move({ sourceKey, destinationKey, metadata });
|
|
445
|
+
}
|
|
446
|
+
async duplicateFile(sourceKey, destinationKey, metadata) {
|
|
447
|
+
return this.duplicate({ sourceKey, destinationKey, metadata });
|
|
448
|
+
}
|
|
449
|
+
async renameFile(sourceKey, destinationKey, metadata) {
|
|
450
|
+
return this.moveFile(sourceKey, destinationKey, metadata);
|
|
451
|
+
}
|
|
452
|
+
async listFiles(prefix, maxKeys) {
|
|
453
|
+
return this.list({ prefix, maxKeys });
|
|
454
|
+
}
|
|
455
|
+
async getDownloadUrl(key, expiresIn) {
|
|
456
|
+
return this.getPresignedUrl({ key, operation: "get", expiresIn });
|
|
457
|
+
}
|
|
458
|
+
async getUploadUrl(key, contentType, expiresIn) {
|
|
459
|
+
return this.getPresignedUrl({
|
|
460
|
+
key,
|
|
461
|
+
operation: "put",
|
|
462
|
+
contentType,
|
|
463
|
+
expiresIn
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
// Folder convenience methods
|
|
467
|
+
async createFolderPath(path) {
|
|
468
|
+
return this.createFolder({ path });
|
|
469
|
+
}
|
|
470
|
+
async deleteFolderPath(path, recursive = false) {
|
|
471
|
+
return this.deleteFolder({ path, recursive });
|
|
472
|
+
}
|
|
473
|
+
async folderPathExists(path) {
|
|
474
|
+
const result = await this.folderExists(path);
|
|
475
|
+
return result.exists;
|
|
476
|
+
}
|
|
477
|
+
async renameFolderPath(oldPath, newPath) {
|
|
478
|
+
return this.renameFolder({ oldPath, newPath });
|
|
479
|
+
}
|
|
480
|
+
async copyFolderPath(sourcePath, destinationPath, recursive = true) {
|
|
481
|
+
return this.copyFolder({ sourcePath, destinationPath, recursive });
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
// src/cloudinary.ts
|
|
486
|
+
function createCloudinary(config) {
|
|
487
|
+
if (config) {
|
|
488
|
+
return new CloudinaryService(config);
|
|
489
|
+
}
|
|
490
|
+
const envConfig = _chunkI3ME6WAGcjs.loadCloudinaryConfig.call(void 0, );
|
|
491
|
+
return new CloudinaryService(envConfig);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
exports.CloudinaryService = CloudinaryService; exports.createCloudinary = createCloudinary;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { S as StorageInterface, C as CloudinaryConfig, U as UploadOptions, a as UploadResult, D as DownloadOptions, b as DownloadResult, c as DeleteOptions, d as DeleteResult, B as BatchDeleteOptions, e as BatchDeleteResult, L as ListOptions, f as ListResult, E as ExistsResult, g as CopyOptions, h as CopyResult, M as MoveOptions, i as MoveResult, j as DuplicateOptions, k as DuplicateResult, P as PresignedUrlOptions, l as PresignedUrlResult, m as CreateFolderOptions, n as CreateFolderResult, o as DeleteFolderOptions, p as DeleteFolderResult, q as ListFoldersOptions, r as ListFoldersResult, F as FolderExistsResult, R as RenameFolderOptions, s as RenameFolderResult, t as CopyFolderOptions, u as CopyFolderResult } from './storage-interface-BKeDAlGP.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cloudinary storage service implementation
|
|
5
|
+
* High-level service wrapper for Cloudinary storage operations with convenience methods
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Cloudinary storage service
|
|
10
|
+
* High-level service for Cloudinary storage operations with convenience methods
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
declare class CloudinaryService implements StorageInterface {
|
|
14
|
+
private provider;
|
|
15
|
+
private config;
|
|
16
|
+
constructor();
|
|
17
|
+
constructor(config: CloudinaryConfig);
|
|
18
|
+
getConfig(): CloudinaryConfig;
|
|
19
|
+
getProvider(): string;
|
|
20
|
+
getPublicUrl(key: string): string;
|
|
21
|
+
upload(options: UploadOptions): Promise<UploadResult>;
|
|
22
|
+
download(options: DownloadOptions): Promise<DownloadResult>;
|
|
23
|
+
delete(options: DeleteOptions): Promise<DeleteResult>;
|
|
24
|
+
batchDelete(options: BatchDeleteOptions): Promise<BatchDeleteResult>;
|
|
25
|
+
list(options?: ListOptions): Promise<ListResult>;
|
|
26
|
+
exists(key: string): Promise<ExistsResult>;
|
|
27
|
+
copy(options: CopyOptions): Promise<CopyResult>;
|
|
28
|
+
move(options: MoveOptions): Promise<MoveResult>;
|
|
29
|
+
duplicate(options: DuplicateOptions): Promise<DuplicateResult>;
|
|
30
|
+
getPresignedUrl(options: PresignedUrlOptions): Promise<PresignedUrlResult>;
|
|
31
|
+
createFolder(options: CreateFolderOptions): Promise<CreateFolderResult>;
|
|
32
|
+
deleteFolder(options: DeleteFolderOptions): Promise<DeleteFolderResult>;
|
|
33
|
+
listFolders(options?: ListFoldersOptions): Promise<ListFoldersResult>;
|
|
34
|
+
folderExists(path: string): Promise<FolderExistsResult>;
|
|
35
|
+
renameFolder(options: RenameFolderOptions): Promise<RenameFolderResult>;
|
|
36
|
+
copyFolder(options: CopyFolderOptions): Promise<CopyFolderResult>;
|
|
37
|
+
uploadFile(key: string, file: Buffer | Uint8Array | string, contentType?: string, metadata?: Record<string, string>): Promise<UploadResult>;
|
|
38
|
+
downloadFile(key: string): Promise<DownloadResult>;
|
|
39
|
+
deleteFile(key: string): Promise<DeleteResult>;
|
|
40
|
+
deleteFiles(keys: string[]): Promise<BatchDeleteResult>;
|
|
41
|
+
fileExists(key: string): Promise<boolean>;
|
|
42
|
+
copyFile(sourceKey: string, destinationKey: string, metadata?: Record<string, string>): Promise<CopyResult>;
|
|
43
|
+
moveFile(sourceKey: string, destinationKey: string, metadata?: Record<string, string>): Promise<MoveResult>;
|
|
44
|
+
duplicateFile(sourceKey: string, destinationKey: string, metadata?: Record<string, string>): Promise<DuplicateResult>;
|
|
45
|
+
renameFile(sourceKey: string, destinationKey: string, metadata?: Record<string, string>): Promise<MoveResult>;
|
|
46
|
+
listFiles(prefix?: string, maxKeys?: number): Promise<ListResult>;
|
|
47
|
+
getDownloadUrl(key: string, expiresIn?: number): Promise<PresignedUrlResult>;
|
|
48
|
+
getUploadUrl(key: string, contentType?: string, expiresIn?: number): Promise<PresignedUrlResult>;
|
|
49
|
+
createFolderPath(path: string): Promise<CreateFolderResult>;
|
|
50
|
+
deleteFolderPath(path: string, recursive?: boolean): Promise<DeleteFolderResult>;
|
|
51
|
+
folderPathExists(path: string): Promise<boolean>;
|
|
52
|
+
renameFolderPath(oldPath: string, newPath: string): Promise<RenameFolderResult>;
|
|
53
|
+
copyFolderPath(sourcePath: string, destinationPath: string, recursive?: boolean): Promise<CopyFolderResult>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Create Cloudinary service using environment variables or manual configuration
|
|
58
|
+
* @param config Optional Cloudinary configuration. If not provided, loads from environment variables
|
|
59
|
+
* @returns CloudinaryService instance
|
|
60
|
+
* @throws Error if configuration is invalid or environment variables are missing
|
|
61
|
+
* @public
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* import { createCloudinary } from '@pelatform/storage/cloudinary';
|
|
66
|
+
*
|
|
67
|
+
* // Using environment variables
|
|
68
|
+
* // Set: PELATFORM_CLOUDINARY_CLOUD_NAME=my-cloud, PELATFORM_CLOUDINARY_API_KEY=123..., etc.
|
|
69
|
+
* const cloudinaryFromEnv = createCloudinary();
|
|
70
|
+
* await cloudinaryFromEnv.uploadFile('photo.jpg', imageBuffer);
|
|
71
|
+
*
|
|
72
|
+
* // Using manual configuration
|
|
73
|
+
* const cloudinary = createCloudinary({
|
|
74
|
+
* provider: 'cloudinary',
|
|
75
|
+
* cloudName: 'my-cloud-name',
|
|
76
|
+
* apiKey: '123456789012345',
|
|
77
|
+
* apiSecret: 'your-api-secret',
|
|
78
|
+
* secure: true,
|
|
79
|
+
* folder: 'uploads'
|
|
80
|
+
* });
|
|
81
|
+
*
|
|
82
|
+
* // Upload with transformations
|
|
83
|
+
* await cloudinary.uploadFile('profile-pic.jpg', imageBuffer);
|
|
84
|
+
*
|
|
85
|
+
* // Get optimized URL
|
|
86
|
+
* const publicUrl = cloudinary.getPublicUrl('profile-pic.jpg');
|
|
87
|
+
* console.log(publicUrl); // Cloudinary optimized URL
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
declare function createCloudinary(): CloudinaryService;
|
|
91
|
+
declare function createCloudinary(config: CloudinaryConfig): CloudinaryService;
|
|
92
|
+
|
|
93
|
+
export { CloudinaryService, createCloudinary };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { S as StorageInterface, C as CloudinaryConfig, U as UploadOptions, a as UploadResult, D as DownloadOptions, b as DownloadResult, c as DeleteOptions, d as DeleteResult, B as BatchDeleteOptions, e as BatchDeleteResult, L as ListOptions, f as ListResult, E as ExistsResult, g as CopyOptions, h as CopyResult, M as MoveOptions, i as MoveResult, j as DuplicateOptions, k as DuplicateResult, P as PresignedUrlOptions, l as PresignedUrlResult, m as CreateFolderOptions, n as CreateFolderResult, o as DeleteFolderOptions, p as DeleteFolderResult, q as ListFoldersOptions, r as ListFoldersResult, F as FolderExistsResult, R as RenameFolderOptions, s as RenameFolderResult, t as CopyFolderOptions, u as CopyFolderResult } from './storage-interface-BKeDAlGP.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cloudinary storage service implementation
|
|
5
|
+
* High-level service wrapper for Cloudinary storage operations with convenience methods
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Cloudinary storage service
|
|
10
|
+
* High-level service for Cloudinary storage operations with convenience methods
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
declare class CloudinaryService implements StorageInterface {
|
|
14
|
+
private provider;
|
|
15
|
+
private config;
|
|
16
|
+
constructor();
|
|
17
|
+
constructor(config: CloudinaryConfig);
|
|
18
|
+
getConfig(): CloudinaryConfig;
|
|
19
|
+
getProvider(): string;
|
|
20
|
+
getPublicUrl(key: string): string;
|
|
21
|
+
upload(options: UploadOptions): Promise<UploadResult>;
|
|
22
|
+
download(options: DownloadOptions): Promise<DownloadResult>;
|
|
23
|
+
delete(options: DeleteOptions): Promise<DeleteResult>;
|
|
24
|
+
batchDelete(options: BatchDeleteOptions): Promise<BatchDeleteResult>;
|
|
25
|
+
list(options?: ListOptions): Promise<ListResult>;
|
|
26
|
+
exists(key: string): Promise<ExistsResult>;
|
|
27
|
+
copy(options: CopyOptions): Promise<CopyResult>;
|
|
28
|
+
move(options: MoveOptions): Promise<MoveResult>;
|
|
29
|
+
duplicate(options: DuplicateOptions): Promise<DuplicateResult>;
|
|
30
|
+
getPresignedUrl(options: PresignedUrlOptions): Promise<PresignedUrlResult>;
|
|
31
|
+
createFolder(options: CreateFolderOptions): Promise<CreateFolderResult>;
|
|
32
|
+
deleteFolder(options: DeleteFolderOptions): Promise<DeleteFolderResult>;
|
|
33
|
+
listFolders(options?: ListFoldersOptions): Promise<ListFoldersResult>;
|
|
34
|
+
folderExists(path: string): Promise<FolderExistsResult>;
|
|
35
|
+
renameFolder(options: RenameFolderOptions): Promise<RenameFolderResult>;
|
|
36
|
+
copyFolder(options: CopyFolderOptions): Promise<CopyFolderResult>;
|
|
37
|
+
uploadFile(key: string, file: Buffer | Uint8Array | string, contentType?: string, metadata?: Record<string, string>): Promise<UploadResult>;
|
|
38
|
+
downloadFile(key: string): Promise<DownloadResult>;
|
|
39
|
+
deleteFile(key: string): Promise<DeleteResult>;
|
|
40
|
+
deleteFiles(keys: string[]): Promise<BatchDeleteResult>;
|
|
41
|
+
fileExists(key: string): Promise<boolean>;
|
|
42
|
+
copyFile(sourceKey: string, destinationKey: string, metadata?: Record<string, string>): Promise<CopyResult>;
|
|
43
|
+
moveFile(sourceKey: string, destinationKey: string, metadata?: Record<string, string>): Promise<MoveResult>;
|
|
44
|
+
duplicateFile(sourceKey: string, destinationKey: string, metadata?: Record<string, string>): Promise<DuplicateResult>;
|
|
45
|
+
renameFile(sourceKey: string, destinationKey: string, metadata?: Record<string, string>): Promise<MoveResult>;
|
|
46
|
+
listFiles(prefix?: string, maxKeys?: number): Promise<ListResult>;
|
|
47
|
+
getDownloadUrl(key: string, expiresIn?: number): Promise<PresignedUrlResult>;
|
|
48
|
+
getUploadUrl(key: string, contentType?: string, expiresIn?: number): Promise<PresignedUrlResult>;
|
|
49
|
+
createFolderPath(path: string): Promise<CreateFolderResult>;
|
|
50
|
+
deleteFolderPath(path: string, recursive?: boolean): Promise<DeleteFolderResult>;
|
|
51
|
+
folderPathExists(path: string): Promise<boolean>;
|
|
52
|
+
renameFolderPath(oldPath: string, newPath: string): Promise<RenameFolderResult>;
|
|
53
|
+
copyFolderPath(sourcePath: string, destinationPath: string, recursive?: boolean): Promise<CopyFolderResult>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Create Cloudinary service using environment variables or manual configuration
|
|
58
|
+
* @param config Optional Cloudinary configuration. If not provided, loads from environment variables
|
|
59
|
+
* @returns CloudinaryService instance
|
|
60
|
+
* @throws Error if configuration is invalid or environment variables are missing
|
|
61
|
+
* @public
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* import { createCloudinary } from '@pelatform/storage/cloudinary';
|
|
66
|
+
*
|
|
67
|
+
* // Using environment variables
|
|
68
|
+
* // Set: PELATFORM_CLOUDINARY_CLOUD_NAME=my-cloud, PELATFORM_CLOUDINARY_API_KEY=123..., etc.
|
|
69
|
+
* const cloudinaryFromEnv = createCloudinary();
|
|
70
|
+
* await cloudinaryFromEnv.uploadFile('photo.jpg', imageBuffer);
|
|
71
|
+
*
|
|
72
|
+
* // Using manual configuration
|
|
73
|
+
* const cloudinary = createCloudinary({
|
|
74
|
+
* provider: 'cloudinary',
|
|
75
|
+
* cloudName: 'my-cloud-name',
|
|
76
|
+
* apiKey: '123456789012345',
|
|
77
|
+
* apiSecret: 'your-api-secret',
|
|
78
|
+
* secure: true,
|
|
79
|
+
* folder: 'uploads'
|
|
80
|
+
* });
|
|
81
|
+
*
|
|
82
|
+
* // Upload with transformations
|
|
83
|
+
* await cloudinary.uploadFile('profile-pic.jpg', imageBuffer);
|
|
84
|
+
*
|
|
85
|
+
* // Get optimized URL
|
|
86
|
+
* const publicUrl = cloudinary.getPublicUrl('profile-pic.jpg');
|
|
87
|
+
* console.log(publicUrl); // Cloudinary optimized URL
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
declare function createCloudinary(): CloudinaryService;
|
|
91
|
+
declare function createCloudinary(config: CloudinaryConfig): CloudinaryService;
|
|
92
|
+
|
|
93
|
+
export { CloudinaryService, createCloudinary };
|