mirror of
https://git.um-react.app/um/um-react.git
synced 2025-11-28 03:23:02 +00:00
fix: add MIME type for the decrypted file
This commit is contained in:
@@ -24,3 +24,13 @@ export function isDataLooksLikeAudio(buffer: Uint8Array): boolean {
|
|||||||
detectResult.free();
|
detectResult.free();
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const AudioMimeType: { [key: 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',
|
||||||
|
};
|
||||||
|
|||||||
@@ -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 { AudioMimeType, 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, AudioMimeType[audioExt])), ext: audioExt };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user