cloudflare-sync
Advanced tools
Comparing version 1.1.1 to 1.2.0
{ | ||
"name": "cloudflare-sync", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "CLI for uploading images to cloudflare.", | ||
@@ -5,0 +5,0 @@ "bin": "dist/src/cli.js", |
@@ -20,2 +20,3 @@ #!/usr/bin/env NODE_OPTIONS=--no-warnings node | ||
.option("--ext <string>", "Comma-separated list of file extensions to process", "jpg,jpeg,png") | ||
.option("--update", "Overwrite existing images on the server", false) | ||
.action(sync); | ||
@@ -25,3 +26,3 @@ async function sync(args) { | ||
const { default: ora } = await import("ora"); | ||
const { source, account, parallel, resize, resizeFit } = args; | ||
const { source, account, parallel, resize, resizeFit, update } = args; | ||
if (source == null) { | ||
@@ -61,3 +62,3 @@ throw new Error("Missing --source argument"); | ||
}); | ||
const filesToSync = srcFiles.filter((file) => file.serverData == null); | ||
const filesToSync = srcFiles.filter((file) => file.serverData == null || update); | ||
if (filesToSync.length === 0) { | ||
@@ -88,3 +89,5 @@ spinner.stopAndPersist({ | ||
} | ||
await client.uploadImage(file.relativePath, imageBuffer); | ||
// It's an update if the serverData is present | ||
const isUpdate = !!file.serverData; | ||
await client.uploadImage(file.relativePath, imageBuffer, isUpdate); | ||
completedCount++; | ||
@@ -91,0 +94,0 @@ updateProgress(); |
@@ -32,3 +32,3 @@ export class CloudflareClient { | ||
} | ||
async uploadImage(pathname, content) { | ||
async uploadImage(pathname, content, isUpdate) { | ||
const formData = new FormData(); | ||
@@ -38,2 +38,7 @@ formData.append("file", new Blob([content]), pathname); | ||
formData.append("id", pathname); | ||
if (isUpdate) { | ||
await this.callJSONAPI(`/images/v1/${encodeURIComponent(pathname)}`, { | ||
method: "DELETE", | ||
}); | ||
} | ||
const result = await this.callJSONAPI("/images/v1", { | ||
@@ -40,0 +45,0 @@ method: "POST", |
{ | ||
"name": "cloudflare-sync", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "CLI for uploading images to cloudflare.", | ||
@@ -5,0 +5,0 @@ "bin": "dist/src/cli.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8366
165