Browse Source

refactor(decrypt/*): change interface

20230320
Emmm Monster 4 years ago
parent
commit
ca4ed149b2
No known key found for this signature in database GPG Key ID: C98279C83FB50DB9
  1. 6
      src/decrypt/common.ts
  2. 2
      src/decrypt/entity.ts
  3. 1
      src/decrypt/kgm.ts
  4. 1
      src/decrypt/kwm.ts
  5. 1
      src/decrypt/ncm.ts
  6. 4
      src/decrypt/qmc.ts
  7. 1
      src/decrypt/raw.ts
  8. 6
      src/decrypt/utils.ts
  9. 1
      src/decrypt/xm.ts

6
src/decrypt/common.ts

@ -18,10 +18,10 @@ interface FileInfo {
}
export async function CommonDecrypt(file: FileInfo) {
export async function CommonDecrypt(file: FileInfo): Promise<DecryptResult> {
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<DecryptResult>;
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;

2
src/decrypt/entity.ts

@ -1,6 +1,4 @@
export interface DecryptResult {
status: boolean,//todo: remove & use Exception
title: string
album?: string
artist?: string

1
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),

1
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),

1
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,

4
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<DecryptResult> {
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,

1
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,

6
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"

1
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,

Loading…
Cancel
Save