Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma strängvärde byggs med konkatenering i stället för att matcha mönstret.
33 lines
851 B
TypeScript
33 lines
851 B
TypeScript
export type InvoiceFontFileFormat = 'ttf' | 'woff'
|
|
|
|
export function detectInvoiceFontFileFormat(
|
|
bytes: Uint8Array,
|
|
): InvoiceFontFileFormat | null {
|
|
if (bytes.byteLength < 4) return null
|
|
|
|
if (
|
|
bytes[0] === 0x00 &&
|
|
bytes[1] === 0x01 &&
|
|
bytes[2] === 0x00 &&
|
|
bytes[3] === 0x00
|
|
) {
|
|
return 'ttf'
|
|
}
|
|
|
|
const signature = String.fromCharCode(bytes[0], bytes[1], bytes[2], bytes[3])
|
|
if (signature === 'true') return 'ttf'
|
|
if (signature === 'wOFF') return 'woff'
|
|
return null
|
|
}
|
|
|
|
export function getInvoiceFontContentType(format: InvoiceFontFileFormat): string {
|
|
return format === 'ttf' ? 'font/ttf' : 'font/woff'
|
|
}
|
|
|
|
export function toInvoiceFontDataUrl(
|
|
bytes: Uint8Array,
|
|
format: InvoiceFontFileFormat,
|
|
): string {
|
|
return `data:${getInvoiceFontContentType(format)};base64,${Buffer.from(bytes).toString('base64')}`
|
|
}
|