Compare commits
6 Commits
59d569dca9
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| dfd630fa2b | |||
| 55f01abd74 | |||
| 78557a6ffa | |||
| 7a37c73a85 | |||
| a06a0cead0 | |||
| cf6910c72c |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +1,6 @@
|
||||
**/__pycache__/**
|
||||
**/venv/**
|
||||
databases/**
|
||||
json/**
|
||||
static/**
|
||||
**/static/resources/**
|
||||
**/test/**
|
||||
@@ -1,2 +1,2 @@
|
||||
#!/bin/sh
|
||||
docker run -it -d --name greendam_website -v $(pwd)/var:/var -w /var -p 0.0.0.0:8088:8084 skimrme/python:fastapi2 uvicorn main:app --host 0.0.0.0 --port 8084 --reload
|
||||
docker run -it -d --name greendam_website -v $(pwd)/var:/var -w /var -p 0.0.0.0:8088:8084 skimrme/python:fastapi2 /var/venv/bin/uvicorn main:app --host 0.0.0.0 --port 8084 --reload
|
||||
17
requirements.txt
Normal file
17
requirements.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
annotated-doc==0.0.4
|
||||
annotated-types==0.7.0
|
||||
anyio==4.12.0
|
||||
certifi==2025.11.12
|
||||
charset-normalizer==3.4.4
|
||||
click==8.3.1
|
||||
fastapi==0.124.4
|
||||
h11==0.16.0
|
||||
idna==3.11
|
||||
pydantic==2.12.5
|
||||
pydantic_core==2.41.5
|
||||
requests==2.32.5
|
||||
starlette==0.50.0
|
||||
typing-inspection==0.4.2
|
||||
typing_extensions==4.15.0
|
||||
urllib3==2.6.2
|
||||
uvicorn==0.38.0
|
||||
108
var/main.py
108
var/main.py
@@ -1,20 +1,114 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi import APIRouter # 引入模板
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi import APIRouter # 引入路由表
|
||||
from fastapi.staticfiles import StaticFiles # 设定静态文件夹
|
||||
from fastapi.templating import Jinja2Templates # 引入jinja模板
|
||||
from fastapi.responses import RedirectResponse # 重定向工具
|
||||
|
||||
|
||||
# 初始化程序
|
||||
app = FastAPI()
|
||||
app = FastAPI(
|
||||
docs_url=None,
|
||||
redoc_url=None
|
||||
)
|
||||
root_url = "greendam.ww3.tw"
|
||||
|
||||
# 设定静态文件夹 包括挂载位置
|
||||
app.mount("/static", StaticFiles(directory="/var/static"), name="static")
|
||||
|
||||
# 模板文件
|
||||
# 设定jinja模板位置
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
|
||||
# 路由表文件
|
||||
from routers import api
|
||||
app.include_router(api.router)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
def home():
|
||||
return "Hello, World!!!"
|
||||
async def reload_301_home():
|
||||
return RedirectResponse(url="https://greendam.ww3.tw/home/")
|
||||
|
||||
@app.get("/docs")
|
||||
@app.get("/docs/")
|
||||
@app.get("/redoc")
|
||||
@app.get("/redoc/")
|
||||
async def reload_301():
|
||||
return RedirectResponse(url="https://greendam.ww3.tw/home/")
|
||||
|
||||
@app.get("/home/")
|
||||
async def home(request: Request):
|
||||
return templates.TemplateResponse(
|
||||
"home.html",
|
||||
{
|
||||
"request": request,
|
||||
"title": "home"
|
||||
}
|
||||
)
|
||||
|
||||
@app.get("/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):
|
||||
return templates.TemplateResponse(
|
||||
"bbs.html",
|
||||
{
|
||||
"request": request,
|
||||
"title": "bbs"
|
||||
},
|
||||
)
|
||||
|
||||
@app.get("/image/")
|
||||
@app.get("/image/{name}/")
|
||||
async def image(request: Request, name: str = None):
|
||||
if not name:
|
||||
return templates.TemplateResponse(
|
||||
"image/home.html",
|
||||
{
|
||||
"request": request,
|
||||
"title": "image"
|
||||
}
|
||||
)
|
||||
else:
|
||||
return templates.TemplateResponse(
|
||||
"image/test.html",
|
||||
{
|
||||
"request": request,
|
||||
"name": f"{name}"
|
||||
}
|
||||
)
|
||||
|
||||
@app.get("/video/")
|
||||
@app.get("/video/{name}/")
|
||||
async def video(request: Request, name: str = None):
|
||||
if not name:
|
||||
return templates.TemplateResponse(
|
||||
"video/home.html",
|
||||
{
|
||||
"request": request,
|
||||
"title": "video"
|
||||
}
|
||||
)
|
||||
else:
|
||||
return templates.TemplateResponse(
|
||||
"video/test.html",
|
||||
{
|
||||
"request": request,
|
||||
"name": f"{name}"
|
||||
}
|
||||
)
|
||||
@@ -1,5 +1,5 @@
|
||||
from fastapi import APIRouter
|
||||
import json
|
||||
import json, os, datetime
|
||||
|
||||
|
||||
root_url = "greendam.ww3.tw"
|
||||
@@ -16,3 +16,111 @@ 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)
|
||||
###########
|
||||
|
||||
# 展示不同版本的小绿图片
|
||||
###########
|
||||
@router.get("/image/list/")
|
||||
@router.get("/image/list/{name}/")
|
||||
async def 展示不同版本的小绿图片(name: str = None):
|
||||
if not name:
|
||||
image_path = "../../var/static/resources/other/image"
|
||||
image_name = os.listdir(image_path)
|
||||
image_files = [f for f in image_name if f.lower().endswith((""))]
|
||||
rule_list = []
|
||||
url = f"https://{root_url}/static/resources/other/image"
|
||||
for id, filename in enumerate(image_files, start=1):
|
||||
url_path = f"{url}/{filename}"
|
||||
rule_list.append({
|
||||
"id": id,
|
||||
"filename": filename,
|
||||
"url_path": url_path
|
||||
})
|
||||
return (rule_list)
|
||||
else:
|
||||
image_path = f"../../var/static/resources/other/image/{name}"
|
||||
image_name = os.listdir(image_path)
|
||||
image_files = [f for f in image_name if f.lower().endswith((""))]
|
||||
rule_list = []
|
||||
url = f"https://{root_url}/static/resources/other/image/{name}"
|
||||
for id, filename in enumerate(image_files, start=1):
|
||||
url_path = f"{url}/{filename}"
|
||||
rule_list.append({
|
||||
"id": id,
|
||||
"filename": filename,
|
||||
"url_path": url_path
|
||||
})
|
||||
return (rule_list)
|
||||
|
||||
###########
|
||||
|
||||
|
||||
# 展示不同版本的小绿视频合集
|
||||
###########
|
||||
@router.get("/video/list/")
|
||||
@router.get("/video/list/{name}/")
|
||||
def 展示不同版本的小绿视频合集(name: str = None):
|
||||
if not name:
|
||||
video_path = "../../var/static/resources/other/video"
|
||||
video_name = os.listdir(video_path)
|
||||
video_files = [f for f in video_name if f.lower().endswith((""))]
|
||||
rule_list = []
|
||||
url = f"https://{root_url}/static/resources/other/video"
|
||||
for id, filename in enumerate(video_files, start=1):
|
||||
url_path = f"{url}/{filename}"
|
||||
rule_list.append({
|
||||
"id": id,
|
||||
"filename": filename,
|
||||
"url_path": url_path
|
||||
})
|
||||
return (rule_list)
|
||||
else:
|
||||
video_path = f"../../var/static/resources/other/video/{name}"
|
||||
video_name = os.listdir(video_path)
|
||||
video_files = [f for f in video_name if f.lower().endswith((""))]
|
||||
rule_list = []
|
||||
url = f"https://{root_url}/static/resources/other/video/{name}"
|
||||
for id,filename in enumerate(video_files, start=1):
|
||||
url_path = f"{url}/{filename}"
|
||||
rule_list.append({
|
||||
"id": id,
|
||||
"filename": filename,
|
||||
"url_path": url_path
|
||||
})
|
||||
return (rule_list)
|
||||
###########
|
||||
7
var/static/src/css/home/main.css
Normal file
7
var/static/src/css/home/main.css
Normal file
@@ -0,0 +1,7 @@
|
||||
#home_wallpaper {
|
||||
background: linear-gradient(to top, #228C23 50%, #53A14E 50%);
|
||||
}
|
||||
|
||||
#thanks {
|
||||
font-size: 175%;
|
||||
}
|
||||
BIN
var/static/src/img/logo.png
Normal file
BIN
var/static/src/img/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 360 KiB |
0
var/static/src/js/resources/main.js
Normal file
0
var/static/src/js/resources/main.js
Normal file
11
var/templates/bbs.html
Normal file
11
var/templates/bbs.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>绿坝娘资源小站 (仮) | {{ title }}</title>
|
||||
<link rel="icon" type="image/png" sizes="128x128" href="/static/src/img/logo.png">
|
||||
</head>
|
||||
<body>
|
||||
<a href="/">返回主页</a>
|
||||
<br>
|
||||
搭建中......
|
||||
</body>
|
||||
</html>
|
||||
57
var/templates/home.html
Normal file
57
var/templates/home.html
Normal file
@@ -0,0 +1,57 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>绿坝娘资源小站 (仮) | {{ title }}</title>
|
||||
<link rel="stylesheet" href="/static/src/css/home/main.css">
|
||||
<link rel="icon" type="image/png" sizes="128x128" href="/static/src/img/logo.png">
|
||||
</head>
|
||||
<body id="home_wallpaper">
|
||||
<!-- <div style="height: 20%; width: 200px; background-color: aqua;">
|
||||
<img src="/static/src/img/logo.png" alt="logo" style="width: 20%;">
|
||||
</div> -->
|
||||
<div style="width: 100%; height: 100%;">
|
||||
<div style="width: 60%; text-align: right;">
|
||||
<h1>绿坝娘资源小站 (<a style="color: white;">仮</a>)</h1>
|
||||
</div>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<div style="width: 100%;">
|
||||
<table border="0" style="width: 100%;">
|
||||
<th style="width: 20%;"></th>
|
||||
<th style="color: rgb(43, 43, 43); font-size: 120%; text-align: left;">
|
||||
这是一个文件下载地址
|
||||
<br>
|
||||
我会在这里提供一些,关于绿坝娘的文件
|
||||
<br>
|
||||
来提供大家下载
|
||||
<br>
|
||||
在此特别感谢荧瞳大大的提供
|
||||
</th>
|
||||
</table>
|
||||
</div>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<li style="font-size: 600%; width: 65%; height: 25%; text-align: right; list-style: none;">
|
||||
<a href="/">主页</a>
|
||||
<a href="/resources/">资源</a>
|
||||
<a href="/bbs/">论坛</a>
|
||||
</li>
|
||||
<br>
|
||||
<br>
|
||||
<del>看来我的野心还不小啊!上来就作这么多功能!!</del>
|
||||
<br>
|
||||
目前firefox是有问题的,但是我个人并不在windows使用firefox,故而不考虑适配
|
||||
<br>
|
||||
还差一个图片导览暂,做好之后再重定向
|
||||
<br>
|
||||
<br>
|
||||
随机绿坝娘网站
|
||||
<br>
|
||||
<a href="https://greendam.icu/">https://greendam.icu/</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
22
var/templates/image/home.html
Normal file
22
var/templates/image/home.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>选择不同版本的小绿</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>选择不同版本的小绿<a href="/image">__>重新刷新</h2>
|
||||
<div id="list"></div>
|
||||
</body>
|
||||
</html>
|
||||
<script>
|
||||
fetch('https://greendam.ww3.tw/api/image/list/')
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
data.forEach(item => {
|
||||
console.log('ID', item.id);
|
||||
console.log('Name', item.filename);
|
||||
console.log('URL', item.url_path);
|
||||
|
||||
document.getElementById('list').innerHTML += `<a href="/image/${item.filename}"><b>${item.filename}</b></a>___`
|
||||
})
|
||||
})
|
||||
</script>
|
||||
24
var/templates/image/test.html
Normal file
24
var/templates/image/test.html
Normal file
@@ -0,0 +1,24 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>{{ name }}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>图片预览_{{ name }}<a href="../">返回上级../</a></h2>
|
||||
<div id="content"></div>
|
||||
</body>
|
||||
<script>
|
||||
fetch('https://greendam.ww3.tw/api/image/list/{{ name }}/')
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
data.forEach(item => {
|
||||
console.log("ID", item.id)
|
||||
console.log("Name", item.filename)
|
||||
console.log("Url", item.url_path)
|
||||
|
||||
let content_Document = `<img src="${item.url_path}" alt="${item.filename}" style="width: 10%;" loading="lazy">${item.id}`
|
||||
document.getElementById('content').innerHTML += content_Document
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
</html>
|
||||
34
var/templates/resources/home.html
Normal file
34
var/templates/resources/home.html
Normal file
@@ -0,0 +1,34 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>绿坝娘资源小站 (仮) | {{ title }}</title>
|
||||
<link rel="icon" type="image/png" sizes="128x128" href="/static/src/img/logo.png">
|
||||
</head>
|
||||
<body>
|
||||
<a href="/">返回主页</a>
|
||||
<br>
|
||||
<h1>Index of /</h1>
|
||||
<hr>
|
||||
<div id="content">
|
||||
</div>
|
||||
<hr>
|
||||
<br>
|
||||
以下还可以预览小绿的图片(本来想做预览图的,结果能力有限,现在正在努力学习javascript)
|
||||
<br>
|
||||
<a href="/image">图片导览</a>_<a href="/video">视频导览</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<script>
|
||||
fetch("https://greendam.ww3.tw/api/files/list/")
|
||||
.then(res => res.json())
|
||||
.then (data => {
|
||||
data.forEach(item => {
|
||||
console.log('ID', item.id);
|
||||
console.log('Name', item.filename);
|
||||
console.log('URL', item.url_path);
|
||||
|
||||
let contentDocment = `<a href="https://greendam.ww3.tw/resources/${item.filename}">${item.filename}</a><br>`
|
||||
document.getElementById("content").innerHTML += contentDocment
|
||||
})
|
||||
})
|
||||
</script>
|
||||
30
var/templates/resources/test.html
Normal file
30
var/templates/resources/test.html
Normal file
@@ -0,0 +1,30 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>绿坝娘资源小站 (仮) | {{ name }}</title>
|
||||
<link rel="icon" type="image/png" sizes="128x128" href="/static/src/img/logo.png">
|
||||
</head>
|
||||
<body>
|
||||
<a href="/resources">返回上级</a>
|
||||
<br>
|
||||
<h1>Index of /{{ name }}</h1>
|
||||
<hr>
|
||||
<div id="content">
|
||||
</div>
|
||||
<hr>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<script>
|
||||
fetch("https://greendam.ww3.tw/api/files/list/{{ name }}/")
|
||||
.then(res => res.json())
|
||||
.then (data => {
|
||||
data.forEach(item => {
|
||||
console.log('ID', item.id);
|
||||
console.log('Name', item.filename);
|
||||
console.log('URL', item.url_path);
|
||||
|
||||
let contentDocment = `<a href="${item.url_path}">${item.filename}</a><br>`
|
||||
document.getElementById("content").innerHTML += contentDocment
|
||||
})
|
||||
})
|
||||
</script>
|
||||
25
var/templates/video/home.html
Normal file
25
var/templates/video/home.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>绿坝娘资源小站 (仮) | {{ title }}</title>
|
||||
<link rel="icon" type="image/png" sizes="128x128" href="/static/src/img/logo.png">
|
||||
</head>
|
||||
<body>
|
||||
<h2>视频导览<a href="/resources">../返回上级</a></h2>
|
||||
<br>
|
||||
<div id="list"></div>
|
||||
</body>
|
||||
<script>
|
||||
fetch('https://greendam.ww3.tw/api/video/list/')
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
data.forEach(item => {
|
||||
console.log("ID", item.id)
|
||||
console.log("Name", item.filename)
|
||||
console.log("Url", item.url_path)
|
||||
|
||||
let list_Document = `<a href="./${item.filename}">${item.filename}</a>__`
|
||||
document.getElementById('list').innerHTML += list_Document
|
||||
})
|
||||
})
|
||||
</script>
|
||||
</html>
|
||||
24
var/templates/video/test.html
Normal file
24
var/templates/video/test.html
Normal file
@@ -0,0 +1,24 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>绿坝娘资源小站 (仮) | {{ name }}</title>
|
||||
<link rel="icon" type="image/png" sizes="128x128" href="/static/src/img/logo.png">
|
||||
</head>
|
||||
<body>
|
||||
{{ name }}
|
||||
<div id="content"></div>
|
||||
</body>
|
||||
<script>
|
||||
fetch('https://greendam.ww3.tw/api/video/list/{{ name }}/')
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
data.forEach(itme => {
|
||||
console.log("ID", itme.id)
|
||||
console.log("Name", itme.filename)
|
||||
console.log("Url", itme.url_path)
|
||||
|
||||
let video_Document = `<br><br><b>${itme.filename}</b><br><br><hr><video width="25%" controls><source src=${itme.url_path} type="video/mp4"></video><br>`
|
||||
document.getElementById('content').innerHTML += video_Document
|
||||
})
|
||||
})
|
||||
</script>
|
||||
</html>
|
||||
Reference in New Issue
Block a user