(prefix?: string)
| 101 | // ── Core: List Files in HF Repo ────────────────────────────────────── |
| 102 | |
| 103 | async function fetchFileList(prefix?: string): Promise<HFFileEntry[]> { |
| 104 | const { token, repo, branch } = getConfig() |
| 105 | if (!token || !repo) return [] |
| 106 | |
| 107 | const path = prefix ? `/${prefix}` : '' |
| 108 | const url = `${HF_API}/datasets/${repo}/tree/${branch}${path}` |
| 109 | |
| 110 | try { |
| 111 | const res = await fetch(url, { |
| 112 | headers: { 'Authorization': `Bearer ${token}` }, |
| 113 | }) |
| 114 | |
| 115 | if (!res.ok) { |
| 116 | console.error(`[HF Reader] List failed (${res.status}): ${await res.text().catch(() => '')}`) |
| 117 | return [] |
| 118 | } |
| 119 | |
| 120 | return await res.json() as HFFileEntry[] |
| 121 | } catch (err) { |
| 122 | console.error(`[HF Reader] Network error listing files:`, (err as Error).message) |
| 123 | return [] |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | export async function listBatchFiles(forceRefresh = false): Promise<BatchInfo[]> { |
| 128 | const now = Date.now() |
no test coverage detected