From 1ecab987a645d219b9d678cfccff7d7d5474e75d Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 29 Jul 2026 17:15:07 +0700 Subject: [PATCH] fix: send non-JPEG images as document instead of photo; fix Dockerfile home.html path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - getFileType: only classify image/jpeg as 'photo'; png/gif/webp → 'document' (Telegram Bot API rejects non-JPEG for sendPhoto) - Dockerfile: copy home.html to dist/ instead of root (import.meta.dir = dist/) - Update test assertion for getFileType(image/png) → 'document' --- Dockerfile | 2 +- src/shared/utils/file.ts | 7 ++++++- test/file.test.ts | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 485cfb9..44b9661 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,7 @@ WORKDIR /usr/src/app # Copy built files, schema, and package.json COPY --from=builder /usr/src/app/dist/index.js ./dist/index.js COPY --from=builder /usr/src/app/dist/migrate.js ./dist/migrate.js -COPY --from=builder /usr/src/app/src/home.html ./home.html +COPY --from=builder /usr/src/app/src/home.html ./dist/home.html COPY schema.sql ./ COPY package.json ./ diff --git a/src/shared/utils/file.ts b/src/shared/utils/file.ts index 636f6a4..0749080 100644 --- a/src/shared/utils/file.ts +++ b/src/shared/utils/file.ts @@ -85,7 +85,12 @@ export const getFileType = (mime: string | null, caption?: string): string => { if (mimeUpper === 'video') return 'video'; if (mimeUpper === 'audio') return 'audio'; if (mimeUpper === 'document') return 'document'; - if (mimeUpper === 'image') return captionLower?.includes('gif') ? 'animation' : 'photo'; + // ── Photo (JPEG only; Telegram Bot API rejects non-JPEG for sendPhoto) ── + if (mimeUpper === 'image') { + if (captionLower?.includes('gif')) return 'animation'; + if (mime?.toLowerCase() === 'image/jpeg' || mime?.toLowerCase() === 'image/jpg') return 'photo'; + return 'document'; + } if (captionLower?.includes('voice')) return 'voice'; if (captionLower?.includes('animation')) return 'animation'; diff --git a/test/file.test.ts b/test/file.test.ts index 5e59ad3..dd23ecf 100644 --- a/test/file.test.ts +++ b/test/file.test.ts @@ -21,7 +21,7 @@ describe('File Utilities', () => { it('should classify image mime types based on caption', () => { expect(getFileType('image/jpeg', 'my photo')).toBe('photo'); - expect(getFileType('image/png', 'cool image.png')).toBe('photo'); + expect(getFileType('image/png', 'cool image.png')).toBe('document'); expect(getFileType('image/gif', 'funny.gif')).toBe('animation'); expect(getFileType('image/png', 'funny gif')).toBe('animation'); });