Initial release of Web Tools 0.0.5

This commit is contained in:
mid
2026-08-07 21:51:15 +08:00
commit fa14e9e5b9
71 changed files with 6365 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
import { calculateCrcReport, type CrcWorkerRequest, type CrcWorkerResponse } from '@/lib/crcWorker'
import { getFirmwareFormat, MAX_FIRMWARE_FILE_SIZE, parseFirmwareContent } from '@/lib/firmware'
import type { DataBlock } from '@/lib/intelHex'
const workerScope = globalThis as unknown as {
onmessage: ((event: MessageEvent<CrcWorkerRequest>) => void) | null
postMessage(message: CrcWorkerResponse): void
}
let firmwareBlocks: DataBlock[] | undefined
workerScope.onmessage = async (event) => {
const request = event.data
try {
if (request.type === 'parse') {
if (request.file.size === 0) throw new Error('文件为空')
if (request.file.size > MAX_FIRMWARE_FILE_SIZE) throw new Error('文件不能超过 64 MiB')
const format = getFirmwareFormat(request.file.name)
const content = format === 'Intel HEX'
? await request.file.text()
: new Uint8Array(await request.file.arrayBuffer())
const parsed = parseFirmwareContent(request.file.name, content)
firmwareBlocks = parsed.blocks
workerScope.postMessage({
type: 'parsed',
id: request.id,
format: parsed.format,
totalBytes: parsed.totalBytes,
blockCount: parsed.blocks.length,
warnings: parsed.warnings,
})
return
}
if (!firmwareBlocks) throw new Error('请先选择 BIN 或 Intel HEX 文件')
workerScope.postMessage({ type: 'calculated', id: request.id, ...calculateCrcReport(firmwareBlocks, request.parameters) })
} catch (reason) {
workerScope.postMessage({
type: 'error',
id: request.id,
operation: request.type,
error: reason instanceof Error ? reason.message : 'CRC 计算失败',
})
}
}