完成资源页面

This commit is contained in:
2026-05-21 00:31:30 +00:00
parent 78557a6ffa
commit 55f01abd74
5 changed files with 113 additions and 25 deletions

View File

@@ -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)
###########