From ca4ed149b222cb0fcfbd4a16bbc76f3c61c27d66 Mon Sep 17 00:00:00 2001 From: Emmm Monster <58943012+emmmx@users.noreply.github.com> Date: Mon, 24 May 2021 15:05:14 +0800 Subject: [PATCH] refactor(decrypt/*): change interface --- src/decrypt/common.ts | 6 +++--- src/decrypt/entity.ts | 2 -- src/decrypt/kgm.ts | 1 - src/decrypt/kwm.ts | 1 - src/decrypt/ncm.ts | 1 - src/decrypt/qmc.ts | 4 ++-- src/decrypt/raw.ts | 1 - src/decrypt/utils.ts | 6 ------ src/decrypt/xm.ts | 1 - 9 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/decrypt/common.ts b/src/decrypt/common.ts index 0081088..f586925 100644 --- a/src/decrypt/common.ts +++ b/src/decrypt/common.ts @@ -18,10 +18,10 @@ interface FileInfo { } -export async function CommonDecrypt(file: FileInfo) { +export async function CommonDecrypt(file: FileInfo): Promise { let raw_ext = file.name.substring(file.name.lastIndexOf(".") + 1, file.name.length).toLowerCase(); let raw_filename = file.name.substring(0, file.name.lastIndexOf(".")); - let rt_data: Partial; + let rt_data: DecryptResult; switch (raw_ext) { case "ncm":// Netease Mp3/Flac rt_data = await NcmDecrypt(file.raw, raw_filename, raw_ext); @@ -70,7 +70,7 @@ export async function CommonDecrypt(file: FileInfo) { rt_data = await KgmDecrypt(file.raw, raw_filename, raw_ext); break default: - rt_data = {status: false, message: "不支持此文件格式",} + throw "不支持此文件格式" } if (!rt_data.rawExt) rt_data.rawExt = raw_ext; diff --git a/src/decrypt/entity.ts b/src/decrypt/entity.ts index a76b9f8..761510d 100644 --- a/src/decrypt/entity.ts +++ b/src/decrypt/entity.ts @@ -1,6 +1,4 @@ export interface DecryptResult { - status: boolean,//todo: remove & use Exception - title: string album?: string artist?: string diff --git a/src/decrypt/kgm.ts b/src/decrypt/kgm.ts index 5e6ace8..45abc59 100644 --- a/src/decrypt/kgm.ts +++ b/src/decrypt/kgm.ts @@ -65,7 +65,6 @@ export async function Decrypt(file: File, raw_filename: string, raw_ext: string) const musicMeta = await metaParseBlob(musicBlob); const {title, artist} = GetMetaFromFile(raw_filename, musicMeta.common.title, musicMeta.common.artist) return { - status: true, album: musicMeta.common.album, picture: GetCoverFromFile(musicMeta), file: URL.createObjectURL(musicBlob), diff --git a/src/decrypt/kwm.ts b/src/decrypt/kwm.ts index 54b52f1..ddcc53c 100644 --- a/src/decrypt/kwm.ts +++ b/src/decrypt/kwm.ts @@ -41,7 +41,6 @@ export async function Decrypt(file: File, raw_filename: string, _: string): Prom const musicMeta = await metaParseBlob(musicBlob); const {title, artist} = GetMetaFromFile(raw_filename, musicMeta.common.title, musicMeta.common.artist) return { - status: true, album: musicMeta.common.album, picture: GetCoverFromFile(musicMeta), file: URL.createObjectURL(musicBlob), diff --git a/src/decrypt/ncm.ts b/src/decrypt/ncm.ts index 88a5350..539f321 100644 --- a/src/decrypt/ncm.ts +++ b/src/decrypt/ncm.ts @@ -203,7 +203,6 @@ class NcmDecrypt { gatherResult(): DecryptResult { if (!this.newMeta) throw Error("bad sequence") return { - status: true, title: this.newMeta.title, artist: this.newMeta.artists?.join("; "), ext: this.format, diff --git a/src/decrypt/qmc.ts b/src/decrypt/qmc.ts index fd8b856..2a4173d 100644 --- a/src/decrypt/qmc.ts +++ b/src/decrypt/qmc.ts @@ -12,6 +12,7 @@ import {parseBlob as metaParseBlob} from "music-metadata-browser"; import iconv from "iconv-lite"; +import {DecryptResult} from "@/decrypt/entity"; interface Handler { ext: string @@ -38,7 +39,7 @@ const HandlerMap: { [key: string]: Handler } = { "776176": {handler: QmcMaskGetDefault, ext: "wav", detect: false} }; -export async function Decrypt(file: File, raw_filename: string, raw_ext: string) { +export async function Decrypt(file: File, raw_filename: string, raw_ext: string): Promise { if (!(raw_ext in HandlerMap)) throw "File type is incorrect!"; const handler = HandlerMap[raw_ext]; @@ -103,7 +104,6 @@ export async function Decrypt(file: File, raw_filename: string, raw_ext: string) } } return { - status: true, title: info.title, artist: info.artist, ext: ext, diff --git a/src/decrypt/raw.ts b/src/decrypt/raw.ts index fa7e0ab..d9980b7 100644 --- a/src/decrypt/raw.ts +++ b/src/decrypt/raw.ts @@ -16,7 +16,6 @@ export async function Decrypt(file: Blob, raw_filename: string, raw_ext: string, const {title, artist} = GetMetaFromFile(raw_filename, tag.common.title, tag.common.artist) return { - status: true, title, artist, ext, diff --git a/src/decrypt/utils.ts b/src/decrypt/utils.ts index c2db07d..4b6314a 100644 --- a/src/decrypt/utils.ts +++ b/src/decrypt/utils.ts @@ -31,12 +31,6 @@ export function BytesHasPrefix(data: Uint8Array, prefix: number[]): boolean { }) } -export function BytesEquals(data: Uint8Array, another: Uint8Array): boolean { - if (another.length != data.length) return false - return data.every((val, idx) => { - return val === another[idx]; - }) -} export function SniffAudioExt(data: Uint8Array, fallback_ext: string = "mp3"): string { if (BytesHasPrefix(data, MP3_HEADER)) return "mp3" diff --git a/src/decrypt/xm.ts b/src/decrypt/xm.ts index b061498..ee2d255 100644 --- a/src/decrypt/xm.ts +++ b/src/decrypt/xm.ts @@ -52,7 +52,6 @@ export async function Decrypt(file: File, raw_filename: string, raw_ext: string) raw_filename.indexOf("_") === -1 ? "-" : "_") return { - status: true, title, artist, ext,