mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 08:32:43 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -53,13 +53,17 @@ const AUDIO_FILE_EXTENSIONS = new Set([
|
||||
]);
|
||||
|
||||
function normalizeHeaderMime(mime?: string | null): string | undefined {
|
||||
if (!mime) return undefined;
|
||||
if (!mime) {
|
||||
return undefined;
|
||||
}
|
||||
const cleaned = mime.split(";")[0]?.trim().toLowerCase();
|
||||
return cleaned || undefined;
|
||||
}
|
||||
|
||||
async function sniffMime(buffer?: Buffer): Promise<string | undefined> {
|
||||
if (!buffer) return undefined;
|
||||
if (!buffer) {
|
||||
return undefined;
|
||||
}
|
||||
try {
|
||||
const type = await fileTypeFromBuffer(buffer);
|
||||
return type?.mime ?? undefined;
|
||||
@@ -69,7 +73,9 @@ async function sniffMime(buffer?: Buffer): Promise<string | undefined> {
|
||||
}
|
||||
|
||||
export function getFileExtension(filePath?: string | null): string | undefined {
|
||||
if (!filePath) return undefined;
|
||||
if (!filePath) {
|
||||
return undefined;
|
||||
}
|
||||
try {
|
||||
if (/^https?:\/\//i.test(filePath)) {
|
||||
const url = new URL(filePath);
|
||||
@@ -84,7 +90,9 @@ export function getFileExtension(filePath?: string | null): string | undefined {
|
||||
|
||||
export function isAudioFileName(fileName?: string | null): boolean {
|
||||
const ext = getFileExtension(fileName);
|
||||
if (!ext) return false;
|
||||
if (!ext) {
|
||||
return false;
|
||||
}
|
||||
return AUDIO_FILE_EXTENSIONS.has(ext);
|
||||
}
|
||||
|
||||
@@ -97,7 +105,9 @@ export function detectMime(opts: {
|
||||
}
|
||||
|
||||
function isGenericMime(mime?: string): boolean {
|
||||
if (!mime) return true;
|
||||
if (!mime) {
|
||||
return true;
|
||||
}
|
||||
const m = mime.toLowerCase();
|
||||
return m === "application/octet-stream" || m === "application/zip";
|
||||
}
|
||||
@@ -115,17 +125,29 @@ async function detectMimeImpl(opts: {
|
||||
|
||||
// Prefer sniffed types, but don't let generic container types override a more
|
||||
// specific extension mapping (e.g. XLSX vs ZIP).
|
||||
if (sniffed && (!isGenericMime(sniffed) || !extMime)) return sniffed;
|
||||
if (extMime) return extMime;
|
||||
if (headerMime && !isGenericMime(headerMime)) return headerMime;
|
||||
if (sniffed) return sniffed;
|
||||
if (headerMime) return headerMime;
|
||||
if (sniffed && (!isGenericMime(sniffed) || !extMime)) {
|
||||
return sniffed;
|
||||
}
|
||||
if (extMime) {
|
||||
return extMime;
|
||||
}
|
||||
if (headerMime && !isGenericMime(headerMime)) {
|
||||
return headerMime;
|
||||
}
|
||||
if (sniffed) {
|
||||
return sniffed;
|
||||
}
|
||||
if (headerMime) {
|
||||
return headerMime;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function extensionForMime(mime?: string | null): string | undefined {
|
||||
if (!mime) return undefined;
|
||||
if (!mime) {
|
||||
return undefined;
|
||||
}
|
||||
return EXT_BY_MIME[mime.toLowerCase()];
|
||||
}
|
||||
|
||||
@@ -133,13 +155,17 @@ export function isGifMedia(opts: {
|
||||
contentType?: string | null;
|
||||
fileName?: string | null;
|
||||
}): boolean {
|
||||
if (opts.contentType?.toLowerCase() === "image/gif") return true;
|
||||
if (opts.contentType?.toLowerCase() === "image/gif") {
|
||||
return true;
|
||||
}
|
||||
const ext = getFileExtension(opts.fileName);
|
||||
return ext === ".gif";
|
||||
}
|
||||
|
||||
export function imageMimeFromFormat(format?: string | null): string | undefined {
|
||||
if (!format) return undefined;
|
||||
if (!format) {
|
||||
return undefined;
|
||||
}
|
||||
switch (format.toLowerCase()) {
|
||||
case "jpg":
|
||||
case "jpeg":
|
||||
|
||||
Reference in New Issue
Block a user