|
import { NextApiRequest, NextApiResponse } from "next"; |
|
|
|
import { load } from 'cheerio'; |
|
import axios from 'axios'; |
|
import { HFRes } from "@/types"; |
|
|
|
async function get_file_list(base: string, dir: string) { |
|
const html = ( |
|
await axios.get(base + "/" + dir) |
|
).data; |
|
const $ = load(html); |
|
const res = $("[data-target=ViewerIndexTreeList]").attr( |
|
"data-props" |
|
) as string; |
|
return JSON.parse(res) as HFRes; |
|
} |
|
|
|
export default async function handler( |
|
request: NextApiRequest, |
|
response: NextApiResponse |
|
) { |
|
const repo = request.query['repo'] as string; |
|
const path = request.query['path'] as string; |
|
return response.status(200).json(await get_file_list( |
|
repo, |
|
path, |
|
)); |
|
} |
|
|