refactor: achieve 100% biome compliance with comprehensive code quality improvements

- Fix all cognitive complexity violations (63→0 errors)
- Replace 'any' types with proper TypeScript interfaces and generics
- Extract helper functions and custom hooks to reduce complexity
- Fix React hook dependency arrays and useCallback patterns
- Remove unused imports, variables, and functions
- Implement proper formatting across all files
- Add type safety with interfaces like AIProcessingRequestWithSession
- Fix circuit breaker implementation with proper reset() method
- Resolve all accessibility and form labeling issues
- Clean up mysterious './0' file containing biome output

Total: 63 errors → 0 errors, 42 warnings → 0 warnings
This commit is contained in:
2025-07-11 23:49:45 +02:00
committed by Kaj Kowalski
parent 1eea2cc3e4
commit 314326400e
42 changed files with 3171 additions and 2781 deletions

View File

@ -7,6 +7,46 @@ export interface TranscriptFetchResult {
error?: string;
}
/**
* Helper function to prepare request headers
*/
function prepareRequestHeaders(
username?: string,
password?: string
): Record<string, string> {
const headers: Record<string, string> = {
"User-Agent": "LiveDash-Transcript-Fetcher/1.0",
};
if (username && password) {
const authHeader = `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`;
headers.Authorization = authHeader;
}
return headers;
}
/**
* Helper function to handle network errors
*/
function handleNetworkError(error: unknown): TranscriptFetchResult {
const errorMessage = error instanceof Error ? error.message : String(error);
if (errorMessage.includes("ENOTFOUND")) {
return { success: false, error: "Domain not found" };
}
if (errorMessage.includes("ECONNREFUSED")) {
return { success: false, error: "Connection refused" };
}
if (errorMessage.includes("timeout")) {
return { success: false, error: "Request timeout" };
}
return { success: false, error: errorMessage };
}
/**
* Fetch transcript content from a URL
* @param url The transcript URL
@ -21,29 +61,14 @@ export async function fetchTranscriptContent(
): Promise<TranscriptFetchResult> {
try {
if (!url || !url.trim()) {
return {
success: false,
error: "No transcript URL provided",
};
return { success: false, error: "No transcript URL provided" };
}
// Prepare authentication header if credentials provided
const authHeader =
username && password
? `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`
: undefined;
const headers: Record<string, string> = {
"User-Agent": "LiveDash-Transcript-Fetcher/1.0",
};
if (authHeader) {
headers.Authorization = authHeader;
}
const headers = prepareRequestHeaders(username, password);
// Fetch the transcript with timeout
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 second timeout
const timeoutId = setTimeout(() => controller.abort(), 30000);
const response = await fetch(url, {
method: "GET",
@ -63,45 +88,12 @@ export async function fetchTranscriptContent(
const content = await response.text();
if (!content || content.trim().length === 0) {
return {
success: false,
error: "Empty transcript content",
};
return { success: false, error: "Empty transcript content" };
}
return {
success: true,
content: content.trim(),
};
return { success: true, content: content.trim() };
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
// Handle common network errors
if (errorMessage.includes("ENOTFOUND")) {
return {
success: false,
error: "Domain not found",
};
}
if (errorMessage.includes("ECONNREFUSED")) {
return {
success: false,
error: "Connection refused",
};
}
if (errorMessage.includes("timeout")) {
return {
success: false,
error: "Request timeout",
};
}
return {
success: false,
error: errorMessage,
};
return handleNetworkError(error);
}
}