| 33 | } |
| 34 | |
| 35 | function parseCSV(content: string): ResolvedRow[] { |
| 36 | const lines = content.trim().split("\n"); |
| 37 | if (lines.length < 2) return []; |
| 38 | |
| 39 | const header = lines[0].split(","); |
| 40 | const idx = { |
| 41 | base_id: header.indexOf("base_id"), |
| 42 | original_url: header.indexOf("original_url"), |
| 43 | resolved_url: header.indexOf("resolved_url"), |
| 44 | extension: header.indexOf("extension"), |
| 45 | status: header.indexOf("status"), |
| 46 | }; |
| 47 | |
| 48 | return lines.slice(1).map((line) => { |
| 49 | const cols = line.split(","); |
| 50 | return { |
| 51 | base_id: cols[idx.base_id], |
| 52 | original_url: cols[idx.original_url], |
| 53 | resolved_url: cols[idx.resolved_url], |
| 54 | extension: cols[idx.extension], |
| 55 | status: cols[idx.status], |
| 56 | }; |
| 57 | }); |
| 58 | } |
| 59 | |
| 60 | function extractDataSetId(url: string): number | null { |
| 61 | const match = url.match(/DataSet%20(\d+)\//); |