mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 23:24:21 +00:00
perf(workflow): optimize getMimeType to read first 4100 bytes instead of whole file
This commit is contained in:
@@ -630,9 +630,15 @@ export async function updateWorkflowTaskActivity(params: UpdateWorkflowTaskParam
|
|||||||
|
|
||||||
function getMimeType(filePath: string): string {
|
function getMimeType(filePath: string): string {
|
||||||
try {
|
try {
|
||||||
const buffer = fs.readFileSync(filePath)
|
const fd = fs.openSync(filePath, 'r')
|
||||||
const detected = detectSupportedMimeType(new Uint8Array(buffer))
|
try {
|
||||||
if (detected) return detected
|
const buffer = Buffer.alloc(4100)
|
||||||
|
const bytesRead = fs.readSync(fd, buffer, 0, 4100, 0)
|
||||||
|
const detected = detectSupportedMimeType(new Uint8Array(buffer.subarray(0, bytesRead)))
|
||||||
|
if (detected) return detected
|
||||||
|
} finally {
|
||||||
|
fs.closeSync(fd)
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
/* Ignore S3 detection errors and fallback to extension mapping */
|
/* Ignore S3 detection errors and fallback to extension mapping */
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user