import { finalizer } from 'abslink' import { expose } from 'abslink/worker' import type { SearchFunction, TorrentSource } from 'hayase-extensions' export default expose({ mod: null as unknown as Promise, construct (code: string) { this.mod = this.load(code) }, async load (code: string): Promise { // WARN: unsafe eval const url = URL.createObjectURL(new Blob([code], { type: 'application/javascript' })) const module = await import(/* @vite-ignore */url) URL.revokeObjectURL(url) return module.default }, [finalizer] () { console.log('destroyed worker') }, async single (...args: Parameters): ReturnType { return await ((await this.mod)).single(...args) }, async batch (...args: Parameters): ReturnType { return await ((await this.mod)).batch(...args) }, async movie (...args: Parameters): ReturnType { return await ((await this.mod)).movie(...args) }, async test () { return await (await this.mod).test() } })