modmapper-web/workers/PluginsLoader.worker.ts

31 lines
1020 B
TypeScript
Raw Normal View History

2022-02-27 06:17:52 +00:00
import { hash_plugin, parse_plugin } from "skyrim-cell-dump-wasm";
self.postMessage("ready");
2022-03-05 04:55:06 +00:00
self.addEventListener("message", async (event: MessageEvent<{ skipParsing?: boolean; filename: string; lastModified: number; contents: Uint8Array }>) => {
2022-02-27 06:17:52 +00:00
const { skipParsing, filename, lastModified, contents } = event.data;
let parsed = undefined;
let parseError = undefined;
try {
if (!skipParsing) {
try {
parsed = parse_plugin(contents);
} catch (e) {
if (e instanceof Error) {
parseError = e.message;
} else {
parseError = "unknown error";
}
}
}
const hash = hash_plugin(contents).toString(36);
self.postMessage({ filename, lastModified, parsed, hash, parseError, enabled: parsed && !parseError, timeHashEnd: Date.now() });
2022-02-27 06:17:52 +00:00
} catch (error) {
console.error(error);
self.postMessage(error);
}
});
//! To avoid isolatedModules error
// eslint-disable-next-line import/no-anonymous-default-export
export default {};