Skip to content

Commit

Permalink
[Seed] Create upload script for KV & R2
Browse files Browse the repository at this point in the history
closes: 32
  • Loading branch information
MNThomson committed Jun 7, 2024
1 parent 261ce4d commit 1ccf3bb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- markdownlint-disable MD033 MD013 -->
<h1 align="center">
<a href="https://github.com/MNThomson/containerflare">
<img src=src/public/favicon.svg alt="Containerflare Logo" width="200">
<img src="src/public/favicon.svg" alt="Containerflare Logo" width="100">
</a>
<br>
ContainerFlare
Expand Down
34 changes: 34 additions & 0 deletions dev/upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
rm -f upload.kv
touch upload.kv
echo "[" >> upload.kv

echo " {" >> upload.kv
echo " \"key\": \"hello-world:latest\"," >> upload.kv

echo " \"value\": \"$(cat ./.mf/kv/hello-world/latest)\"" >> upload.kv
echo " }," >> upload.kv

# https://developers.cloudflare.com/workers/wrangler/commands/#kvbulk
for file in ./.mf/kv/sha256/*; do
if [[ -f "$file" && ! "$(basename $file)" == *.* ]]; then
file=$(basename $file)
echo "KV: $file"
echo " {" >> upload.kv
echo " \"key\": \"sha256:$file\"," >> upload.kv
contents=$(jq -Rs . < ./.mf/kv/sha256/$file)
echo " \"value\": \"${contents}\"" >> upload.kv
echo " }," >> upload.kv
fi
done

echo "]" >> upload.kv

npx wrangler kv:bulk put upload.kv --namespace-id=$INSERT_NAMESPACE_HERE

for file in ./.mf/r2/sha256/*; do
if [[ -f "$file" && ! "$(basename $file)" == *.* ]]; then
file=$(basename $file)
echo "R2: $file"
npx wrangler r2 object put "containerflarer2/sha256:$file" --file "./.mf/r2/sha256/$file"
fi
done
4 changes: 2 additions & 2 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export const onRequest = defineMiddleware(async (context, next) => {
if (import.meta.env.DEV) {
context.locals.runtime = {
env: {
kv: await createKV({ type: "file", path: ".mf/kv-counter" }),
r2: await createR2({ type: "file", path: ".mf/r2-bucket" }),
kv: await createKV({ type: "file", path: ".mf/kv" }),
r2: await createR2({ type: "file", path: ".mf/r2" }),
},
};
}
Expand Down

0 comments on commit 1ccf3bb

Please sign in to comment.