3v324v23 commited on
Commit
65d87c5
·
1 Parent(s): 30f44e6
src/pages/api/get_file_list.ts CHANGED
@@ -1,19 +1,14 @@
1
- import process from "node:process";
2
  import { NextApiRequest, NextApiResponse } from "next";
3
 
4
- import cheerio from 'cheerio';
5
  import axios from 'axios';
6
- import { SocksProxyAgent } from 'socks-proxy-agent';
7
  import { HFRes } from "@/types";
8
 
9
- const socksProxyUrl = 'socks5h://localhost:9909';
10
- const agent = new SocksProxyAgent(socksProxyUrl);
11
-
12
  async function get_file_list(base: string, dir: string) {
13
  const html = (
14
  await axios.get(base + "/" + dir)
15
  ).data;
16
- const $ = cheerio.load(html);
17
  const res = $("[data-target=ViewerIndexTreeList]").attr(
18
  "data-props"
19
  ) as string;
@@ -24,8 +19,10 @@ export default async function handler(
24
  request: NextApiRequest,
25
  response: NextApiResponse
26
  ) {
 
 
27
  return response.status(200).json(await get_file_list(
28
- 'https://huggingface.co/datasets/banned-historical-archives/wenhuibao_disk/tree/main',
29
- '1'
30
  ));
31
  }
 
 
1
  import { NextApiRequest, NextApiResponse } from "next";
2
 
3
+ import { load } from 'cheerio';
4
  import axios from 'axios';
 
5
  import { HFRes } from "@/types";
6
 
 
 
 
7
  async function get_file_list(base: string, dir: string) {
8
  const html = (
9
  await axios.get(base + "/" + dir)
10
  ).data;
11
+ const $ = load(html);
12
  const res = $("[data-target=ViewerIndexTreeList]").attr(
13
  "data-props"
14
  ) as string;
 
19
  request: NextApiRequest,
20
  response: NextApiResponse
21
  ) {
22
+ const repo = request.query['repo'] as string;
23
+ const path = request.query['path'] as string;
24
  return response.status(200).json(await get_file_list(
25
+ repo,
26
+ path,
27
  ));
28
  }
src/pages/index.tsx CHANGED
@@ -7,15 +7,16 @@ import { HF_FileEntry, HFRes } from "@/types";
7
  import { basename } from "path";
8
 
9
  export default function Home() {
10
- const [repo, setRepo] = useState('https://huggingface.co/datasets/banned-historical-archives/wenhuibao_disk/tree/main');
 
11
  const [entries, setEntries] = useState<HF_FileEntry[]>([])
12
  const [next, setNext] = useState('')
13
  const update = useCallback(
14
  (async () => {
15
- const res = (await ((await fetch('/api/get_file_list')).json())) as HFRes;
16
  setEntries(res.entries);
17
  setNext(res.nextURL!);
18
- }), []
19
  )
20
  useEffect(() => {
21
  update()
@@ -31,11 +32,20 @@ export default function Home() {
31
  <Container component="main" sx={{ minHeight: "90vh" }}>
32
  <Stack spacing={4} useFlexGap>
33
  <input value={repo} onChange={e => setRepo(e.target.value)}/>
34
- {entries.map(i => <div key={i.path}>
35
- {basename(i.path)}
 
 
 
 
 
 
 
 
36
  </div>)}
 
37
  <button onClick={() => {
38
- }}>more</button>
39
  </Stack>
40
  </Container>
41
 
 
7
  import { basename } from "path";
8
 
9
  export default function Home() {
10
+ const [repo, setRepo] = useState('https://huggingface.co/datasets/banned-historical-archives/cankaoxiaoxi/tree/main');
11
+ const [path, setPath] = useState('1990');
12
  const [entries, setEntries] = useState<HF_FileEntry[]>([])
13
  const [next, setNext] = useState('')
14
  const update = useCallback(
15
  (async () => {
16
+ const res = (await ((await fetch(`/api/get_file_list?repo=${encodeURIComponent(repo)}&path=${encodeURIComponent(path)}`)).json())) as HFRes;
17
  setEntries(res.entries);
18
  setNext(res.nextURL!);
19
+ }), [repo, path]
20
  )
21
  useEffect(() => {
22
  update()
 
32
  <Container component="main" sx={{ minHeight: "90vh" }}>
33
  <Stack spacing={4} useFlexGap>
34
  <input value={repo} onChange={e => setRepo(e.target.value)}/>
35
+ <input value={path} onChange={e => setPath(e.target.value)}/>
36
+ {entries.map(i => <div key={i.path} style={{display: 'flex'}}>
37
+ <div style={{flex: 1}} onClick={() => {
38
+ if (i.type =='directory') {
39
+ setPath(i.path);
40
+ setTimeout(update, 100);
41
+ }
42
+ }}>{basename(i.path)}</div>
43
+ <div style={{flex: 1}}>{i.size}</div>
44
+ <div style={{flex: 1}}>{i.type}</div>
45
  </div>)}
46
+ {next ?
47
  <button onClick={() => {
48
+ }}>more</button> : null}
49
  </Stack>
50
  </Container>
51