@sanvika/cloudinary 0.2.4 → 0.3.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/index.js +31 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -411,6 +411,36 @@ async function deleteImages(urls, options = {}) {
|
|
|
411
411
|
const failed = allResults.filter((r) => !r.success).length;
|
|
412
412
|
return { success: failed === 0, total: urls.length, processed: allResults.length, successful, failed };
|
|
413
413
|
}
|
|
414
|
+
async function renameImage(fromPublicId, toPublicId, options = {}) {
|
|
415
|
+
await ensureConfigured();
|
|
416
|
+
const { overwrite = true, resourceType = "image" } = options;
|
|
417
|
+
if (!fromPublicId || !toPublicId) {
|
|
418
|
+
throw new CloudinaryError("fromPublicId and toPublicId are required", "renameImage");
|
|
419
|
+
}
|
|
420
|
+
if (isProxyMode()) {
|
|
421
|
+
const result2 = await withRetry(
|
|
422
|
+
() => gatewayPost("/api/v1/rename", {
|
|
423
|
+
fromPublicId,
|
|
424
|
+
toPublicId,
|
|
425
|
+
options: { overwrite, resourceType }
|
|
426
|
+
}),
|
|
427
|
+
{ operationName: "renameImage", maxAttempts: 2 }
|
|
428
|
+
);
|
|
429
|
+
return {
|
|
430
|
+
url: (result2 == null ? void 0 : result2.secure_url) || (result2 == null ? void 0 : result2.url) || "",
|
|
431
|
+
publicId: (result2 == null ? void 0 : result2.public_id) || toPublicId
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
const cloudinary = await loadLegacyCloudinary();
|
|
435
|
+
const result = await withRetry(
|
|
436
|
+
() => cloudinary.uploader.rename(fromPublicId, toPublicId, {
|
|
437
|
+
overwrite,
|
|
438
|
+
resource_type: resourceType
|
|
439
|
+
}),
|
|
440
|
+
{ operationName: "renameImage", maxAttempts: 2 }
|
|
441
|
+
);
|
|
442
|
+
return { url: result.secure_url, publicId: result.public_id };
|
|
443
|
+
}
|
|
414
444
|
async function pingCloudinary() {
|
|
415
445
|
await ensureConfigured();
|
|
416
446
|
if (isProxyMode()) return gatewayGet("/api/v1/ping");
|
|
@@ -634,6 +664,7 @@ export {
|
|
|
634
664
|
isRetriableError,
|
|
635
665
|
normalizeFolderPath,
|
|
636
666
|
pingCloudinary,
|
|
667
|
+
renameImage,
|
|
637
668
|
runCloudinaryDiagnostics,
|
|
638
669
|
splitFileName,
|
|
639
670
|
testCloudinaryWebhookSignature,
|
package/package.json
CHANGED