Compare commits
No commits in common. "6f93326ba00843e98aba61d510c02bfd4a11630b" and "6327c8f8780b21f94371e82c687a310d47428e80" have entirely different histories.
6f93326ba0
...
6327c8f878
Binary file not shown.
Binary file not shown.
|
|
@ -1,34 +1,23 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
def get_pictures_info(directory, page, page_size):
|
def get_pictures_info(directory):
|
||||||
pictures = []
|
pictures = []
|
||||||
start_index = (page - 1) * page_size
|
counter = 1
|
||||||
end_index = start_index + page_size
|
|
||||||
counter = 0
|
|
||||||
|
|
||||||
for filename in os.listdir(directory):
|
for filename in os.listdir(directory):
|
||||||
|
# print(f"directory: {directory}")
|
||||||
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
|
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
|
||||||
if start_index <= counter < end_index:
|
|
||||||
file_path = os.path.join(directory, filename)
|
file_path = os.path.join(directory, filename)
|
||||||
size = os.path.getsize(file_path)
|
size = os.path.getsize(file_path)
|
||||||
size_mb = size / (1024 * 1024)
|
size_mb = size / (1024 * 1024)
|
||||||
|
photo_name = filename
|
||||||
picture_info = {
|
picture_info = {
|
||||||
"id": counter + 1,
|
"id": counter,
|
||||||
"photo_name": filename,
|
"photo_name": photo_name,
|
||||||
"photo_size": round(size_mb, 2),
|
"photo_size": round(size_mb,2),
|
||||||
"photo_url": file_path
|
"photo_url": file_path
|
||||||
}
|
}
|
||||||
pictures.append(picture_info)
|
pictures.append(picture_info)
|
||||||
counter += 1
|
counter += 1
|
||||||
if counter >= end_index:
|
|
||||||
break
|
|
||||||
return pictures
|
return pictures
|
||||||
|
|
||||||
|
|
||||||
def get_total_pages(directory, page_size):
|
|
||||||
total_photos = 0
|
|
||||||
for filename in os.listdir(directory):
|
|
||||||
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
|
|
||||||
total_photos += 1
|
|
||||||
return (total_photos + page_size - 1) // page_size
|
|
||||||
|
|
|
||||||
13
website.py
13
website.py
|
|
@ -2,7 +2,6 @@ from fastapi import FastAPI, HTTPException, Request
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
from utils.pictures_handle import get_pictures_info
|
from utils.pictures_handle import get_pictures_info
|
||||||
from utils.pictures_handle import get_total_pages
|
|
||||||
import os
|
import os
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
||||||
|
|
@ -39,17 +38,17 @@ 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():
|
||||||
dir_path = "pictures"
|
base_url = "http://127.0.0.1:5173/"
|
||||||
total_pages = get_total_pages(dir_path, page_size)
|
dir = "pictures"
|
||||||
photo_list = get_pictures_info(dir_path, page, page_size)
|
photo_list = get_pictures_info(dir)
|
||||||
for photo in photo_list:
|
for photo in photo_list:
|
||||||
photo["photo_url"] = f"http://127.0.0.1:8000/static/{photo['photo_name']}"
|
photo["photo_url"] = f"http://127.0.0.1:8000/static/{photo['photo_name']}"
|
||||||
|
# print(photo_list)
|
||||||
return {
|
return {
|
||||||
"code": 0,
|
"code": 0,
|
||||||
"msg": "ok",
|
"msg": "ok",
|
||||||
"data": photo_list,
|
"data": photo_list
|
||||||
"total_pages": total_pages
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue