diff --git a/server/database.py b/server/database.py index 861bddf..c6f5c78 100644 --- a/server/database.py +++ b/server/database.py @@ -7,8 +7,6 @@ from datetime import datetime DATABASE_URL = "mysql+pymysql://wind:wind@193.124.203.110:3306/wind_towers" - - engine = create_engine(DATABASE_URL) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) diff --git a/server/main.py b/server/main.py index afca163..d523ca6 100644 --- a/server/main.py +++ b/server/main.py @@ -1,13 +1,23 @@ -from fastapi import FastAPI, Depends -from fastapi.responses import RedirectResponse +from fastapi import FastAPI, Depends, Request +from fastapi.responses import RedirectResponse, HTMLResponse from sqlalchemy.orm import Session from sqlalchemy.future import select from database import SessionLocal, User, Base, engine +from fastapi.templating import Jinja2Templates +from fastapi.staticfiles import StaticFiles +from src.floris_router import router as floris_router +from src.floris_router import get_images Base.metadata.create_all(bind=engine) app = FastAPI() +templates = Jinja2Templates(directory="templates") + +app.mount("/static", StaticFiles(directory="static"), name="static") +app.mount("/public", StaticFiles(directory="public"), name="public") + +app.include_router(floris_router) def get_db(): @@ -27,12 +37,22 @@ async def hello(): async def redirect_to_docs(): return RedirectResponse(url="/docs") + @app.get("/users") def read_users(db: Session = Depends(get_db)): result = db.execute(select(User)) users = result.scalars().all() # Получаем всех пользователей return users + +@app.get("/main", response_class=HTMLResponse) +async def main(request: Request): + params = {"request": request} + params.update(await get_images()) + + return templates.TemplateResponse("main.html", params) + + if __name__ == "__main__": import uvicorn uvicorn.run(app, host="localhost", port=8080) # Изменено на localhost diff --git a/server/public/floris/Yaw_example.png b/server/public/floris/Yaw_example.png new file mode 100644 index 0000000..7b4d7b5 Binary files /dev/null and b/server/public/floris/Yaw_example.png differ diff --git a/server/src/floris_router.py b/server/src/floris_router.py new file mode 100644 index 0000000..906d32d --- /dev/null +++ b/server/src/floris_router.py @@ -0,0 +1,36 @@ +from pathlib import Path +from fastapi import APIRouter, Depends, HTTPException +from fastapi.responses import FileResponse + + +STATIC_DIR = Path("public/floris") + +router = APIRouter( + prefix="/floris", + tags=["Static Files from Floris"], +) + + +@router.get("/get_images") +async def get_images(): + try: + images = [file.name for file in STATIC_DIR.iterdir() if file.is_file()] + return {"images": images} + except Exception as e: + raise HTTPException( + status_code=500, + detail=str(e) + ) + + +@router.get("/download_image/{image_name}") +async def download_image( + image_name: str +): + image_path = STATIC_DIR / image_name + if not image_path.exists() or not image_path.is_file(): + raise HTTPException(status_code=404, detail="Image not found") + return FileResponse(image_path, media_type="image/jpeg", filename=image_name) + + + diff --git a/server/src/router.py b/server/src/router.py index e69de29..8013b0a 100644 --- a/server/src/router.py +++ b/server/src/router.py @@ -0,0 +1 @@ +st \ No newline at end of file diff --git a/server/static/style.css b/server/static/style.css new file mode 100644 index 0000000..23851ec --- /dev/null +++ b/server/static/style.css @@ -0,0 +1,67 @@ +body { + font-family: Arial, sans-serif; + background-color: #f3f4f6; + color: #333; +} + +.container { + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + padding: 20px; +} + +.image-viewer { + background-color: #fff5e6; + border-radius: 8px; + padding: 20px; + margin-right: 20px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); +} + +.image-viewer img { + max-width: 400px; + max-height: 400px; + display: block; + margin-bottom: 10px; +} + +.image-list { + background-color: #e6f7ff; + padding: 20px; + border-radius: 8px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); +} + +.image-list ul { + list-style-type: none; + padding: 0; +} + +.image-list li { + margin: 5px 0; + padding: 5px; + cursor: pointer; + background-color: #fff; + border-radius: 4px; + transition: background-color 0.3s; +} + +.image-list li:hover { + background-color: #cceeff; +} + +button { + background-color: #82b1ff; + border: none; + color: white; + padding: 10px 15px; + border-radius: 5px; + cursor: pointer; + margin-top: 10px; +} + +button:hover { + background-color: #6699ff; +} diff --git a/server/templates/main.html b/server/templates/main.html new file mode 100644 index 0000000..01e50b9 --- /dev/null +++ b/server/templates/main.html @@ -0,0 +1,43 @@ + + +
+ + +