Skip to content

Commit

Permalink
fix: file content-type
Browse files Browse the repository at this point in the history
  • Loading branch information
beilunyang committed Oct 13, 2024
1 parent cc111c5 commit ade1a69
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 8 deletions.
135 changes: 133 additions & 2 deletions package-lock.json

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

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "img-mom",
"version": "0.1.0",
"private": true,
"engines": {
"node": ">=20.0.0"
},
"engines": {
"node": ">=20.0.0"
},
"scripts": {
"dev": "wrangler dev src/index.ts",
"tunnel": "cloudflared tunnel --url http://127.0.0.1:8787",
Expand All @@ -18,6 +18,7 @@
},
"dependencies": {
"@aws-sdk/client-s3": "^3.627.0",
"file-type": "^19.5.0",
"grammy": "^1.28.0",
"hono": "^4.5.4"
}
Expand Down
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Hono } from 'hono';
import { webhookCallback } from 'grammy/web';
import bot from './bot';
import { fileTypeFromBuffer } from 'file-type'

const app = new Hono();

Expand Down Expand Up @@ -37,10 +38,12 @@ app.get('/img/:fileId', async (ctx) => {
return ctx.text('404 Not Found. Please visit ImgMom docs (https://github.com/beilunyang/img-mom)', 404);
}

const fileType = file.file_path?.split('.').pop() ?? '';
const bf = await res.arrayBuffer()

return ctx.body(await res.arrayBuffer(), 200, {
'Content-Type': `image/${fileType}`
const fileType = await fileTypeFromBuffer(bf)

return ctx.body(bf, 200, {
'Content-Type': fileType?.mime ?? '',
});
});

Expand Down

0 comments on commit ade1a69

Please sign in to comment.