feat(transcode): add Gotenberg support for Office, HTML, CSV, and Markdown PDF proxies (#283)

* feat(transcode): add Gotenberg support for Office, HTML, CSV, and Markdown PDF proxies

* fix(transcode): use Gotenberg chromium markdown endpoint with index.html wrapper for markdown conversion

* test(transcode): add complete unit test coverage for HTML, CSV landscape/portrait, TXT, and Gotenberg fallback branches

* fix(gotenberg): force .md extension for Gotenberg markdown conversion endpoint compatibility

* refactor(gotenberg): standardize basic auth environment variables on GOTENBERG_BASIC_AUTH_USERNAME and GOTENBERG_BASIC_AUTH_PASSWORD

* test(e2e): add real Gotenberg testcontainers workflow E2E test for docx, pptx, and xlsx

* docs: add Gotenberg document PDF conversion documentation and update features in README

* docs(gotenberg): add Docker quickstart commands and remove obsolete GOTENBERG_USERNAME note
This commit is contained in:
Yiling-J
2026-08-09 14:44:13 +08:00
committed by GitHub
parent 283d28bed9
commit aa6d5ed626
17 changed files with 1446 additions and 64 deletions
+46 -8
View File
@@ -1,5 +1,12 @@
import { describe, it, expect } from 'vitest'
import { detectSupportedMimeType, getProxyType } from './mime'
import {
detectSupportedMimeType,
getProxyType,
isOfficeDocument,
isHtmlDocument,
isMarkdownDocument,
isCsvDocument,
} from './mime'
describe('detectSupportedMimeType', () => {
it('should detect JPEG', () => {
@@ -45,6 +52,38 @@ describe('detectSupportedMimeType', () => {
})
})
describe('document helpers', () => {
it('isOfficeDocument should correctly identify office files', () => {
expect(isOfficeDocument('application/msword', 'letter.doc')).toBe(true)
expect(
isOfficeDocument(
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'file.docx',
),
).toBe(true)
expect(isOfficeDocument(null, 'sheet.xlsx')).toBe(true)
expect(isOfficeDocument(null, 'slides.pptx')).toBe(true)
expect(isOfficeDocument(null, 'notes.rtf')).toBe(true)
expect(isOfficeDocument('text/plain', 'notes.txt')).toBe(false)
})
it('isHtmlDocument should correctly identify html files', () => {
expect(isHtmlDocument('text/html', 'page.html')).toBe(true)
expect(isHtmlDocument(null, 'index.htm')).toBe(true)
expect(isHtmlDocument('text/plain', 'notes.txt')).toBe(false)
})
it('isMarkdownDocument should correctly identify markdown files', () => {
expect(isMarkdownDocument('text/markdown', 'README.md')).toBe(true)
expect(isMarkdownDocument(null, 'doc.markdown')).toBe(true)
})
it('isCsvDocument should correctly identify csv files', () => {
expect(isCsvDocument('text/csv', 'data.csv')).toBe(true)
expect(isCsvDocument(null, 'data.csv')).toBe(true)
})
})
describe('getProxyType', () => {
it('should detect image proxyType', () => {
expect(getProxyType('image/png', 'test.png')).toBe('image')
@@ -61,21 +100,20 @@ describe('getProxyType', () => {
expect(getProxyType('audio/mpeg', 'song.mp3')).toBe('audio')
})
it('should detect pdf proxyType only for pdf, csv, txt, and markdown files', () => {
it('should detect pdf proxyType for pdf, csv, txt, markdown, html, and office files', () => {
expect(getProxyType('application/pdf', 'doc.pdf')).toBe('pdf')
expect(getProxyType('text/plain', 'notes.txt')).toBe('pdf')
expect(getProxyType('text/csv', 'data.csv')).toBe('pdf')
expect(getProxyType('text/markdown', 'README.md')).toBe('pdf')
expect(getProxyType('text/x-markdown', 'doc.markdown')).toBe('pdf')
expect(getProxyType(null, 'file.txt')).toBe('pdf')
expect(getProxyType(null, 'README.md')).toBe('pdf')
expect(getProxyType(null, 'doc.markdown')).toBe('pdf')
expect(getProxyType('text/html', 'index.html')).toBe('pdf')
expect(getProxyType('application/msword', 'letter.doc')).toBe('pdf')
expect(getProxyType(null, 'sheet.xlsx')).toBe('pdf')
expect(getProxyType(null, 'slides.pptx')).toBe('pdf')
})
it('should return null for unsupported files including office files', () => {
it('should return null for unsupported files', () => {
expect(getProxyType('application/zip', 'archive.zip')).toBeNull()
expect(getProxyType('application/msword', 'letter.doc')).toBeNull()
expect(getProxyType(null, 'sheet.xlsx')).toBeNull()
expect(getProxyType(null, 'unknown.bin')).toBeNull()
})
})
+70 -6
View File
@@ -1,5 +1,71 @@
export type ProxyType = 'image' | 'video' | 'audio' | 'pdf'
export function isOfficeDocument(mediaType?: string | null, filename?: string | null): boolean {
const lowerMediaType = mediaType?.toLowerCase() || ''
const lowerFilename = filename?.toLowerCase() || ''
if (
lowerMediaType === 'application/msword' ||
lowerMediaType === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' ||
lowerMediaType === 'application/vnd.ms-excel' ||
lowerMediaType === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
lowerMediaType === 'application/vnd.ms-powerpoint' ||
lowerMediaType ===
'application/vnd.openxmlformats-officedocument.presentationml.presentation' ||
lowerMediaType === 'application/vnd.oasis.opendocument.text' ||
lowerMediaType === 'application/vnd.oasis.opendocument.spreadsheet' ||
lowerMediaType === 'application/vnd.oasis.opendocument.presentation' ||
lowerMediaType === 'application/rtf' ||
lowerMediaType === 'text/rtf'
) {
return true
}
const officeExtensions = [
'.doc',
'.docx',
'.xls',
'.xlsx',
'.ppt',
'.pptx',
'.odt',
'.ods',
'.odp',
'.rtf',
]
return officeExtensions.some((ext) => lowerFilename.endsWith(ext))
}
export function isHtmlDocument(mediaType?: string | null, filename?: string | null): boolean {
const lowerMediaType = mediaType?.toLowerCase() || ''
const lowerFilename = filename?.toLowerCase() || ''
return (
lowerMediaType === 'text/html' ||
lowerFilename.endsWith('.html') ||
lowerFilename.endsWith('.htm')
)
}
export function isMarkdownDocument(mediaType?: string | null, filename?: string | null): boolean {
const lowerMediaType = mediaType?.toLowerCase() || ''
const lowerFilename = filename?.toLowerCase() || ''
return (
lowerMediaType === 'text/markdown' ||
lowerMediaType === 'text/x-markdown' ||
lowerFilename.endsWith('.md') ||
lowerFilename.endsWith('.markdown')
)
}
export function isCsvDocument(mediaType?: string | null, filename?: string | null): boolean {
const lowerMediaType = mediaType?.toLowerCase() || ''
const lowerFilename = filename?.toLowerCase() || ''
return lowerMediaType === 'text/csv' || lowerFilename.endsWith('.csv')
}
export function getProxyType(
mediaType?: string | null,
filename?: string | null,
@@ -14,14 +80,12 @@ export function getProxyType(
if (
lowerMediaType === 'application/pdf' ||
lowerMediaType === 'text/plain' ||
lowerMediaType === 'text/csv' ||
lowerMediaType === 'text/markdown' ||
lowerMediaType === 'text/x-markdown' ||
lowerFilename.endsWith('.pdf') ||
lowerFilename.endsWith('.txt') ||
lowerFilename.endsWith('.csv') ||
lowerFilename.endsWith('.md') ||
lowerFilename.endsWith('.markdown')
isCsvDocument(mediaType, filename) ||
isMarkdownDocument(mediaType, filename) ||
isHtmlDocument(mediaType, filename) ||
isOfficeDocument(mediaType, filename)
) {
return 'pdf'
}