Update website.py
parent
152bc9fd83
commit
66078799ff
15
website.py
15
website.py
|
|
@ -1,14 +1,16 @@
|
||||||
from fastapi import FastAPI, HTTPException, Request
|
import os
|
||||||
|
|
||||||
|
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="pictures"), name="static")
|
app.mount("/static", StaticFiles(directory="assets/images/pictures/"), name="static")
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=["http://localhost:5173"], # 允许的源列表
|
allow_origins=["http://localhost:5173"], # 允许的源列表
|
||||||
|
|
@ -40,7 +42,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 = "pictures"
|
dir_path = "assets/images/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:
|
||||||
|
|
@ -56,8 +58,9 @@ 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 = "pictures"
|
dir = "/assets/images/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