You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
718 B
JavaScript
21 lines
718 B
JavaScript
const assetVersion = new URL(import.meta.url).searchParams.get('v');
|
|
const moduleUrl = new URL('./template-upload-hash.js', import.meta.url);
|
|
moduleUrl.search = '';
|
|
if (assetVersion) moduleUrl.searchParams.set('v', assetVersion);
|
|
const { hashBlob } = await import(moduleUrl.href);
|
|
|
|
self.addEventListener('message', async event => {
|
|
const file = event.data?.file;
|
|
try {
|
|
const sha256 = await hashBlob(file, (loaded, total) => {
|
|
self.postMessage({ type: 'progress', loaded, total });
|
|
});
|
|
self.postMessage({ type: 'complete', sha256 });
|
|
} catch (error) {
|
|
self.postMessage({
|
|
type: 'error',
|
|
message: error instanceof Error ? error.message : 'SHA-256 计算失败。',
|
|
});
|
|
}
|
|
});
|