Skip uploading duplicate files to R2

This commit is contained in:
Gabriel Simmer 2024-08-03 21:33:32 +01:00
parent 566a4a4a38
commit d603e52c69
Signed by: arch
SSH key fingerprint: SHA256:m3OEcdtrnBpMX+2BDGh/byv3hrCekCLzDYMdvGEKPPQ

View file

@ -107,7 +107,13 @@ export default {
hash,
file
} = Object.fromEntries(body)
// 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 }
});