Spaces:
Paused
Paused
Download server/utils/fetch_external.ts from asemxin1976/wechat-article: direct link, hf CLI and curl.
- Browser
- Download file 525 Bytes
-
https://huggingface.co/spaces/asemxin1976/wechat-article/resolve/main/server/utils/fetch_external.ts
- Command line
-
hf download hf://spaces/asemxin1976/wechat-article/server/utils/fetch_external.ts
-
curl -L -o fetch_external.ts https://huggingface.co/spaces/asemxin1976/wechat-article/resolve/main/server/utils/fetch_external.ts
525 Bytes
| interface FetchExternalOption { | |
| label: string; | |
| default: any; | |
| } | |
| export async function fetchExternal(url: string, option: FetchExternalOption): Promise<any> { | |
| try { | |
| const resp = await fetch(url, { | |
| signal: AbortSignal.timeout(30_000), | |
| }); | |
| if (!resp.ok) { | |
| throw new Error(`${option.label}失败: ${resp.status}`); | |
| } | |
| return await resp.json(); | |
| } catch (error) { | |
| // 记录日志,便于后期排查 | |
| console.error(`${option.label}失败:`, error); | |
| return option.default; | |
| } | |
| } | |