Handle malformed article URLs

This commit is contained in:
Anthony
2025-11-27 21:18:43 +08:00
parent 7f75b44af1
commit 061474c574
6 changed files with 3030 additions and 19 deletions

View File

@@ -1,5 +1,6 @@
import { GoogleGenAI, Modality } from '@google/genai';
import { VoiceName } from '../types';
import { normalizeUrl } from '../utils/url';
const getAiClient = () => {
const apiKey = process.env.API_KEY;
@@ -9,18 +10,6 @@ const getAiClient = () => {
return new GoogleGenAI({ apiKey });
};
/**
* Helper to ensure URL has protocol.
* Proxies often fail if 'http/https' is missing.
*/
const normalizeUrl = (url: string) => {
let cleanUrl = url.trim();
if (!cleanUrl.startsWith('http://') && !cleanUrl.startsWith('https://')) {
return `https://${cleanUrl}`;
}
return cleanUrl;
};
/**
* List of CORS proxies to try in order.
* This improves reliability if one service is down or blocked.