From de59ad40d12a5150ca969c868b6c40fcb47ca104 Mon Sep 17 00:00:00 2001 From: Yo-han Date: Tue, 17 Sep 2024 14:06:21 +0200 Subject: [PATCH] UPLOAD_FROM_SOURCE setting --- init-config.js | 7 +++++-- package.json | 2 +- src/index.ts | 9 ++++----- src/types.ts | 3 ++- update-config.js | 3 ++- wrangler.toml.tpl | 3 ++- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/init-config.js b/init-config.js index 5c773f7..c02f12b 100644 --- a/init-config.js +++ b/init-config.js @@ -16,7 +16,9 @@ const envVariables = [ { name: 'LIVE_SOURCE_URL', description: 'The live source URL (e.g., https://cdn.example.com/path/)' }, { name: 'LIVE_PUBLIC_DOMAIN', description: 'The live public domain (e.g., https://cf.example.com)' }, { name: 'KV_NAMESPACE_ID', description: 'Your KV namespace ID' }, - { name: 'CACHE_KEY_PREFIX', description: 'Cache key prefix' } + { name: 'CACHE_KEY_PREFIX', description: 'Cache key prefix' }, + { name: 'UPLOAD_FROM_SOURCE', description: 'Upload from source (true/false)' }, + { name: 'RATELIMIT_ENABLED', description: 'Rate limiting enabled (true/false)' } ]; const envValues = {}; @@ -69,7 +71,8 @@ function updateWranglerToml() { '': envValues.API_TOKEN, '': envValues.ACCOUNT_ID, '': envValues.ACCOUNT_HASH, - '': process.env.RATELIMIT_ENABLED === 'true' ? 'true' : 'false', + '': envValues.RATELIMIT_ENABLED === 'true' ? 'true' : 'false', + '': envValues.UPLOAD_FROM_SOURCE === 'true' ? 'true' : 'false', 'https://cdn.example.com/path/': envValues.LIVE_SOURCE_URL, 'https://cf.example.com': envValues.LIVE_PUBLIC_DOMAIN }; diff --git a/package.json b/package.json index 82b2312..68f93c6 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "init": "node init-config.js", "update-config": "node update-config.js", - "build": "npm run update-config && wrangler build", + "build": "npm run update-config && wrangler deploy --dry-run --outdir=dist", "deploy": "npm run build && wrangler deploy", "test": "jest", "test:watch": "jest --watch", diff --git a/src/index.ts b/src/index.ts index 9826a96..e16f927 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,10 +44,9 @@ async function fetchOriginalCloudflareImage(env: Env, id: string): Promise': process.env.BUCKET, '': process.env.CACHE_KEY_PREFIX, '': process.env.KV_NAMESPACE_ID, - '': process.env.RATELIMIT_ENABLED === 'true' ? 'true' : 'false' + '': process.env.RATELIMIT_ENABLED === 'true' ? 'true' : 'false', + '': process.env.UPLOAD_FROM_SOURCE === 'true' ? 'true' : 'false' }; for (const [placeholder, envValue] of Object.entries(replacements)) { diff --git a/wrangler.toml.tpl b/wrangler.toml.tpl index a09deda..686701c 100644 --- a/wrangler.toml.tpl +++ b/wrangler.toml.tpl @@ -13,7 +13,8 @@ ACCOUNT_HASH = "" LIVE_SOURCE_URL = "https://cdn.example.com/path/" LIVE_PUBLIC_DOMAIN = "https://cf.example.com" CACHE_KEY_PREFIX = "" -RATELIMIT_ENABLED = "" +RATELIMIT_ENABLED = +UPLOAD_FROM_SOURCE = [[ r2_buckets ]] binding = "R2_IMAGES_BUCKET"