mirror of
https://git.um-react.app/um/um-react.git
synced 2025-11-28 03:23:02 +00:00
Merge pull request '为解密文件添加 MIME 类型' (#95) from awalol/um-react:fix-mime into main
Reviewed-on: https://git.unlock-music.dev/um/um-react/pulls/95
This commit is contained in:
@@ -24,3 +24,17 @@ export function isDataLooksLikeAudio(buffer: Uint8Array): boolean {
|
|||||||
detectResult.free();
|
detectResult.free();
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const AudioMimeType: Record<string, string> = {
|
||||||
|
mp3: 'audio/mpeg',
|
||||||
|
flac: 'audio/flac',
|
||||||
|
m4a: 'audio/mp4',
|
||||||
|
ogg: 'audio/ogg',
|
||||||
|
wma: 'audio/x-ms-wma',
|
||||||
|
wav: 'audio/x-wav',
|
||||||
|
dff: 'audio/x-dff',
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getMimeTypeFromExt(ext: string) {
|
||||||
|
return AudioMimeType[ext] || 'application/octet-stream';
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export const toArrayBuffer = async (src: Blob | ArrayBuffer | Uint8Array<ArrayBufferLike>) =>
|
export const toArrayBuffer = async (src: Blob | ArrayBuffer | Uint8Array<ArrayBufferLike>) =>
|
||||||
src instanceof Blob ? await src.arrayBuffer() : src;
|
src instanceof Blob ? await src.arrayBuffer() : src;
|
||||||
export const toBlob = (src: Blob | ArrayBuffer | Uint8Array<ArrayBufferLike>) =>
|
export const toBlob = (src: Blob | ArrayBuffer | Uint8Array<ArrayBufferLike>, mimeType?: string) =>
|
||||||
src instanceof Blob ? src : new Blob([src]);
|
src instanceof Blob ? src : new Blob([src], { type: mimeType ?? 'application/octet-stream' });
|
||||||
|
|
||||||
export function* chunkBuffer(buffer: Uint8Array, blockLen = 4096): Generator<[Uint8Array, number], void> {
|
export function* chunkBuffer(buffer: Uint8Array, blockLen = 4096): Generator<[Uint8Array, number], void> {
|
||||||
const len = buffer.byteLength;
|
const len = buffer.byteLength;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { DecipherFactory, DecipherInstance, Status } from '~/decrypt-worker/Deci
|
|||||||
import { UnsupportedSourceFile } from '~/decrypt-worker/util/DecryptError.ts';
|
import { UnsupportedSourceFile } from '~/decrypt-worker/util/DecryptError.ts';
|
||||||
import { ready as umCryptoReady } from '@unlock-music/crypto';
|
import { ready as umCryptoReady } from '@unlock-music/crypto';
|
||||||
import { go } from '~/util/go.ts';
|
import { go } from '~/util/go.ts';
|
||||||
import { detectAudioExtension } from '~/decrypt-worker/util/audioType.ts';
|
import { getMimeTypeFromExt, detectAudioExtension } from '~/decrypt-worker/util/audioType.ts';
|
||||||
|
|
||||||
class DecryptCommandHandler {
|
class DecryptCommandHandler {
|
||||||
private readonly label: string;
|
private readonly label: string;
|
||||||
@@ -75,7 +75,7 @@ class DecryptCommandHandler {
|
|||||||
audioExt = 'm4a';
|
audioExt = 'm4a';
|
||||||
}
|
}
|
||||||
|
|
||||||
return { decrypted: URL.createObjectURL(toBlob(result.data)), ext: audioExt };
|
return { decrypted: URL.createObjectURL(toBlob(result.data, getMimeTypeFromExt(audioExt))), ext: audioExt };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user