mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 01:51:24 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -34,7 +34,9 @@ function stripQuotes(value: string): string {
|
||||
}
|
||||
|
||||
function parseContentDispositionFileName(header?: string | null): string | undefined {
|
||||
if (!header) return undefined;
|
||||
if (!header) {
|
||||
return undefined;
|
||||
}
|
||||
const starMatch = /filename\*\s*=\s*([^;]+)/i.exec(header);
|
||||
if (starMatch?.[1]) {
|
||||
const cleaned = stripQuotes(starMatch[1].trim());
|
||||
@@ -46,17 +48,25 @@ function parseContentDispositionFileName(header?: string | null): string | undef
|
||||
}
|
||||
}
|
||||
const match = /filename\s*=\s*([^;]+)/i.exec(header);
|
||||
if (match?.[1]) return path.basename(stripQuotes(match[1].trim()));
|
||||
if (match?.[1]) {
|
||||
return path.basename(stripQuotes(match[1].trim()));
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async function readErrorBodySnippet(res: Response, maxChars = 200): Promise<string | undefined> {
|
||||
try {
|
||||
const text = await res.text();
|
||||
if (!text) return undefined;
|
||||
if (!text) {
|
||||
return undefined;
|
||||
}
|
||||
const collapsed = text.replace(/\s+/g, " ").trim();
|
||||
if (!collapsed) return undefined;
|
||||
if (collapsed.length <= maxChars) return collapsed;
|
||||
if (!collapsed) {
|
||||
return undefined;
|
||||
}
|
||||
if (collapsed.length <= maxChars) {
|
||||
return collapsed;
|
||||
}
|
||||
return `${collapsed.slice(0, maxChars)}…`;
|
||||
} catch {
|
||||
return undefined;
|
||||
@@ -85,7 +95,9 @@ export async function fetchRemoteMedia(options: FetchMediaOptions): Promise<Fetc
|
||||
detail = `HTTP ${res.status}${statusText}; empty response body`;
|
||||
} else {
|
||||
const snippet = await readErrorBodySnippet(res);
|
||||
if (snippet) detail += `; body: ${snippet}`;
|
||||
if (snippet) {
|
||||
detail += `; body: ${snippet}`;
|
||||
}
|
||||
}
|
||||
throw new MediaFetchError(
|
||||
"http_error",
|
||||
@@ -129,7 +141,9 @@ export async function fetchRemoteMedia(options: FetchMediaOptions): Promise<Fetc
|
||||
});
|
||||
if (fileName && !path.extname(fileName) && contentType) {
|
||||
const ext = extensionForMime(contentType);
|
||||
if (ext) fileName = `${fileName}${ext}`;
|
||||
if (ext) {
|
||||
fileName = `${fileName}${ext}`;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -158,7 +172,9 @@ async function readResponseWithLimit(res: Response, maxBytes: number): Promise<B
|
||||
try {
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
if (done) {
|
||||
break;
|
||||
}
|
||||
if (value?.length) {
|
||||
total += value.length;
|
||||
if (total > maxBytes) {
|
||||
|
||||
Reference in New Issue
Block a user