Skip to content

Commit

Permalink
chore: add cloudflare context types
Browse files Browse the repository at this point in the history
  • Loading branch information
Yizack committed Jul 4, 2024
1 parent 890a3ac commit 9e03d36
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"test:types": "vue-tsc --noEmit"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240620.0",
"@dargmuesli/nuxt-cookie-control": "^8.4.4",
"@iconify-json/solar": "^1.1.9",
"@nuxt/eslint": "^0.3.13",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions server/utils/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ export const uploadImage = async (file: MultiPartData | undefined, outputName: s
}
else if (process.env.CDN) {
const { cloudflare } = event.context;
const headers = new Headers({ "Content-Type": type || "" });
await cloudflare.env.CDN.put(`uploads/${folder}/${finalName}`, data, { httpMetadata: headers });
await cloudflare.env.CDN.put(`uploads/${folder}/${finalName}`, data, { httpMetadata: { contentType: type } });
return finalName;
}
};
Expand Down
16 changes: 16 additions & 0 deletions types/cloudflare.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { CfProperties, Request, ExecutionContext, R2Bucket, D1Database } from "@cloudflare/workers-types";

declare module "h3" {
interface H3EventContext {
cf: CfProperties;
cloudflare: {
request: Request;
env: {
DB: D1Database;
BLOB: R2Bucket;
CDN: R2Bucket;
};
context: ExecutionContext;
};
}
}

0 comments on commit 9e03d36

Please sign in to comment.