coze-plugin-utils
Version:
Comprehensive utility library for Coze plugins with multimedia processing, browser automation, cloud storage integration, and AI-powered video/audio generation capabilities
81 lines • 2.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.detectMimeType = detectMimeType;
function detectMimeType(buffer) {
const header = new Uint8Array(buffer.slice(0, 20));
function isJpeg() {
return header[0] === 0xFF && header[1] === 0xD8 && header[2] === 0xFF;
}
function isPng() {
return header.slice(0, 8).toString() === '\x89PNG\r\n\x1A\n';
}
function isGif() {
return String.fromCharCode(...header.slice(0, 3)) === 'GIF';
}
function isBmp() {
return header[0] === 0x42 && header[1] === 0x4D; // 'BM'
}
function isWebp() {
const riff = String.fromCharCode(...header.slice(0, 4));
const webp = String.fromCharCode(...header.slice(8, 12));
return riff === 'RIFF' && webp === 'WEBP';
}
function isWav() {
const riff = String.fromCharCode(...header.slice(0, 4));
const wave = String.fromCharCode(...header.slice(8, 12));
return riff === 'RIFF' && wave === 'WAVE';
}
function isMp3() {
return header[0] === 0x49 && header[1] === 0x44 && header[2] === 0x33 // ID3 tag
|| (header[0] === 0xFF && (header[1] & 0xE0) === 0xE0); // Frame sync
}
function isOgg() {
return String.fromCharCode(...header.slice(0, 4)) === 'OggS';
}
function isFlac() {
return String.fromCharCode(...header.slice(0, 4)) === 'fLaC';
}
function isMp4() {
return header.slice(4, 8).toString() === 'ftyp';
}
function isWebm() {
return header[0] === 0x1A && header[1] === 0x45 && header[2] === 0xDF && header[3] === 0xA3;
}
function isMpeg() {
return header[0] === 0x00 && header[1] === 0x00 && header[2] === 0x01
&& (header[3] === 0xBA || header[3] === 0xB3);
}
function isAvi() {
const riff = String.fromCharCode(...header.slice(0, 4));
const avi = String.fromCharCode(...header.slice(8, 11));
return riff === 'RIFF' && avi === 'AVI';
}
if (isJpeg())
return 'image/jpeg';
if (isPng())
return 'image/png';
if (isGif())
return 'image/gif';
if (isBmp())
return 'image/bmp';
if (isWebp())
return 'image/webp';
if (isMp3())
return 'audio/mpeg';
if (isOgg())
return 'audio/ogg';
if (isFlac())
return 'audio/flac';
if (isWav())
return 'audio/wav';
if (isMp4())
return 'video/mp4';
if (isWebm())
return 'video/webm';
if (isMpeg())
return 'video/mpeg';
if (isAvi())
return 'video/avi';
return null;
}
//# sourceMappingURL=utils.js.map