From 55f01abd7483b06e0aa081590a945ad701797c7d Mon Sep 17 00:00:00 2001 From: skimrme Date: Thu, 21 May 2026 00:31:30 +0000 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=B5=84=E6=BA=90=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- var/main.py | 26 +++++++++++++++------- var/routers/api.py | 37 ++++++++++++++++++++++++++++++- var/templates/resources.html | 16 ------------- var/templates/resources/home.html | 30 +++++++++++++++++++++++++ var/templates/resources/test.html | 29 ++++++++++++++++++++++++ 5 files changed, 113 insertions(+), 25 deletions(-) delete mode 100644 var/templates/resources.html create mode 100644 var/templates/resources/home.html create mode 100644 var/templates/resources/test.html diff --git a/var/main.py b/var/main.py index 5852acd..7a20102 100644 --- a/var/main.py +++ b/var/main.py @@ -44,14 +44,24 @@ async def home(request: Request): ) @app.get("/resources/") -async def resources(request: Request): - return templates.TemplateResponse( - "resources.html", - { - "request": request, - "title": "resources" - } - ) +@app.get("/resources/{name}") +async def resources(request: Request, name: str = None): + if not name: + return templates.TemplateResponse( + "resources/home.html", + { + "request": request, + "title": "resources" + } + ) + else: + return templates.TemplateResponse( + "resources/test.html", + { + "request": request, + "name": f"{name}" + } + ) @app.get("/bbs/") async def bbs(request: Request): diff --git a/var/routers/api.py b/var/routers/api.py index c874a80..c6925ec 100644 --- a/var/routers/api.py +++ b/var/routers/api.py @@ -1,5 +1,5 @@ from fastapi import APIRouter -import json +import json, os root_url = "greendam.ww3.tw" @@ -16,3 +16,38 @@ def 用于测试(): "code": "200 ok!", "msg": "Hello, World!!" } + +########### +@router.get('/files/list/') +@router.get('/files/list/{name}/') +async def 根据文件夹列出文件(name: str = None): + if not name: + files_path = "../../var/static/resources/greendam" + files_name = os.listdir(files_path) + files_files = [f for f in files_name if f.lower().endswith((""))] + rule_list = [] + url = f"https://{root_url}/static/resources/greendam" + for id, filename in enumerate(files_files, start=1): + url_path = f"{url}/{filename}/" + rule_list.append({ + "id": id, + "filename": filename, + "url_path": url_path + }) + return (rule_list) + else: + files_path = f"../../var/static/resources/greendam/{name}" + files_name = os.listdir(files_path) + files_files = [f for f in files_name if f.lower().endswith((""))] + rule_list = [] + url = f"https://{root_url}/static/resources/greendam/{name}" + for id, filename in enumerate(files_files, start=1): + url_path = f"{url}/{filename}/" + rule_list.append({ + "id": id, + "filename": filename, + "url_path": url_path + }) + return (rule_list) + +########### \ No newline at end of file diff --git a/var/templates/resources.html b/var/templates/resources.html deleted file mode 100644 index ae141fa..0000000 --- a/var/templates/resources.html +++ /dev/null @@ -1,16 +0,0 @@ - - - 绿坝娘资源小站 (仮) | {{ title }} - - - - 返回主页 -
-

Index of /

-
-
-
-        
-
- - \ No newline at end of file diff --git a/var/templates/resources/home.html b/var/templates/resources/home.html new file mode 100644 index 0000000..120474c --- /dev/null +++ b/var/templates/resources/home.html @@ -0,0 +1,30 @@ + + + 绿坝娘资源小站 (仮) | {{ title }} + + + + 返回主页 +
+

Index of /

+
+
+
+
+ + + + \ No newline at end of file diff --git a/var/templates/resources/test.html b/var/templates/resources/test.html new file mode 100644 index 0000000..59ad66a --- /dev/null +++ b/var/templates/resources/test.html @@ -0,0 +1,29 @@ + + + 绿坝娘资源小站 (仮) | {{ name }} + + + 返回上级 +
+

Index of /{{ name }}

+
+
+
+
+ + + + \ No newline at end of file