Skip to content

Commit

Permalink
Merge pull request #4 from buape/main
Browse files Browse the repository at this point in the history
  • Loading branch information
Codeize authored Aug 5, 2023
2 parents 4729919 + b5c9ad2 commit b8236a4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
wrangler.toml

# Logs

logs
Expand Down
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ app.get("/", async (c) => {
return c.redirect(c.env.REDIRECT_URL, 301);
});

app.get("/:key", cache(), async (c) => {
const key = c.req.param("key");
app.get("/*", async (c) => {
let key = c.req.path

// remove first character from key
if (key.startsWith("/")) key = key.slice(1);

const object = await c.env.CDN_BUCKET.get(key);
if (!object) return c.notFound();
Expand Down Expand Up @@ -42,7 +45,7 @@ app.post("/upload", auth(), async (c) => {

let filename;
if (slug) {
filename = encodeURIComponent(slug as string);
filename = slug
} else {
filename = nanoid(idLength(c.req.header("Name-Length"), 8));
}
Expand Down
4 changes: 4 additions & 0 deletions wrangler.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ account_id = "..."
binding = "CDN_BUCKET"
bucket_name = "cdn-bucket"
preview_bucket_name = "cdn-bucket"

[vars]
ACCESS_TOKEN = ""
REDIRECT_URL = ""

0 comments on commit b8236a4

Please sign in to comment.