optimize: .kgm mask loading

This commit is contained in:
MengYX 2021-08-08 07:46:19 +08:00
parent 71862538b7
commit 6737e8c11b
No known key found for this signature in database
GPG Key ID: E63F9C7303E8F604
2 changed files with 12 additions and 5 deletions

View File

@ -8,6 +8,7 @@ import {
} from "@/decrypt/utils.ts";
import {parseBlob as metaParseBlob} from "music-metadata-browser";
import {DecryptResult} from "@/decrypt/entity";
import config from "@/../package.json"
const VprHeader = [
0x05, 0x28, 0xBC, 0x96, 0xE9, 0xE4, 0x5A, 0x43,
@ -22,9 +23,6 @@ const VprMaskDiff = [
export async function Decrypt(file: File, raw_filename: string, raw_ext: string): Promise<DecryptResult> {
if (self.location.protocol === "file:") {
throw Error("请使用 <a target='_blank' href='https://github.com/unlock-music/cli'>CLI版本</a> 进行解锁")
}
const oriData = new Uint8Array(await GetArrayBuffer(file));
if (raw_ext === "vpr") {
@ -84,8 +82,16 @@ function GetMask(pos: number) {
let MaskV2: Uint8Array = new Uint8Array(0);
async function LoadMaskV2(): Promise<boolean> {
let mask_url = `https://cdn.jsdelivr.net/gh/unlock-music/unlock-music@${config.version}/public/static/kgm.mask`
if (["http:", "https:"].some(v => v == self.location.protocol)) {
if (!!self.document) {// using Web Worker
mask_url = "./static/kgm.mask"
} else {// using Main thread
mask_url = "../static/kgm.mask"
}
}
try {
const resp = await fetch(process.env.NODE_ENV !== 'production'?"./static/kgm.mask":"../static/kgm.mask", {method: "GET"})
const resp = await fetch(mask_url, {method: "GET"})
MaskV2 = new Uint8Array(await resp.arrayBuffer());
return true
} catch (e) {

View File

@ -26,7 +26,8 @@
"dom",
"dom.iterable",
"scripthost"
]
],
"resolveJsonModule": true
},
"include": [
"src/**/*.ts",