refactor(decrypt/*): change interface
This commit is contained in:
parent
b3c6fe2f24
commit
ca4ed149b2
@ -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;
|
||||
|
@ -1,6 +1,4 @@
|
||||
export interface DecryptResult {
|
||||
status: boolean,//todo: remove & use Exception
|
||||
|
||||
title: string
|
||||
album?: string
|
||||
artist?: string
|
||||
|
@ -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),
|
||||
|
@ -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),
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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"
|
||||
|
@ -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…
Reference in New Issue
Block a user