From d603e52c69c92ef12823bacbc5e72a4c11f0624b Mon Sep 17 00:00:00 2001 From: Gabriel Simmer Date: Sat, 3 Aug 2024 21:33:32 +0100 Subject: [PATCH] Skip uploading duplicate files to R2 --- worker/src/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/worker/src/index.js b/worker/src/index.js index 8865ee2..b0a74e5 100644 --- a/worker/src/index.js +++ b/worker/src/index.js @@ -107,7 +107,13 @@ export default { hash, file } = Object.fromEntries(body) - await bucket.put(`${hash}.png`, file); + + // Don't bother uploading to R2 if the hashes match. + let latest = kv.get("LATEST"); + if (latest != hash) { + await bucket.put(`${hash}.png`, file); + } + await kv.put("LATEST", hash, { metadata: { date: date } });