mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 08:57:18 +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 {
|
||||
try {
|
||||
const buffer = fs.readFileSync(filePath)
|
||||
const detected = detectSupportedMimeType(new Uint8Array(buffer))
|
||||
if (detected) return detected
|
||||
const fd = fs.openSync(filePath, 'r')
|
||||
try {
|
||||
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 {
|
||||
/* Ignore S3 detection errors and fallback to extension mapping */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user