Compare commits
No commits in common. "66078799fffe41b2404a00ee11afe15335b62899" and "1a7828a850e5d0da71a6c0bba8dd839eee120790" have entirely different histories.
66078799ff
...
1a7828a850
|
|
@ -14,5 +14,6 @@ sniffio==1.3.0
|
||||||
starlette==0.32.0.post1
|
starlette==0.32.0.post1
|
||||||
typing_extensions==4.9.0
|
typing_extensions==4.9.0
|
||||||
uvicorn==0.25.0
|
uvicorn==0.25.0
|
||||||
|
uvloop==0.19.0
|
||||||
watchfiles==0.21.0
|
watchfiles==0.21.0
|
||||||
websockets==12.0
|
websockets==12.0
|
||||||
|
|
|
||||||
15
website.py
15
website.py
|
|
@ -1,16 +1,14 @@
|
||||||
import os
|
from fastapi import FastAPI, HTTPException, Request
|
||||||
|
|
||||||
from fastapi import FastAPI, Request
|
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
from fastapi.staticfiles import StaticFiles
|
|
||||||
|
|
||||||
from utils.pictures_handle import get_pictures_info
|
from utils.pictures_handle import get_pictures_info
|
||||||
from utils.pictures_handle import get_total_pages
|
from utils.pictures_handle import get_total_pages
|
||||||
|
import os
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
app.mount("/static", StaticFiles(directory="assets/images/pictures/"), name="static")
|
app.mount("/static", StaticFiles(directory="pictures"), name="static")
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=["http://localhost:5173"], # 允许的源列表
|
allow_origins=["http://localhost:5173"], # 允许的源列表
|
||||||
|
|
@ -42,7 +40,7 @@ async def get_menu():
|
||||||
|
|
||||||
@app.get("/api/get-photo-list")
|
@app.get("/api/get-photo-list")
|
||||||
async def get_photo_list(page: int = 1, page_size: int = 10):
|
async def get_photo_list(page: int = 1, page_size: int = 10):
|
||||||
dir_path = "assets/images/pictures"
|
dir_path = "pictures"
|
||||||
total_pages = get_total_pages(dir_path, page_size)
|
total_pages = get_total_pages(dir_path, page_size)
|
||||||
photo_list = get_pictures_info(dir_path, page, page_size)
|
photo_list = get_pictures_info(dir_path, page, page_size)
|
||||||
for photo in photo_list:
|
for photo in photo_list:
|
||||||
|
|
@ -58,9 +56,8 @@ async def get_photo_list(page: int = 1, page_size: int = 10):
|
||||||
@app.get("/static/{photo_name}")
|
@app.get("/static/{photo_name}")
|
||||||
async def get_photo(photo_name: str,request: Request):
|
async def get_photo(photo_name: str,request: Request):
|
||||||
request_path = str(request.url)
|
request_path = str(request.url)
|
||||||
dir = "/assets/images/pictures"
|
dir = "pictures"
|
||||||
file_path = os.path.join(dir, photo_name)
|
file_path = os.path.join(dir, photo_name)
|
||||||
print(file_path)
|
|
||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
return FileResponse(file_path)
|
return FileResponse(file_path)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue