Ver Fonte

fix confift

tomoya há 2 anos atrás
pai
commit
f806a011fc

+ 8 - 1
.env

@@ -1,5 +1,5 @@
 DOMAIN=localhost
-SERVER_ADDRESS=http://172.105.219.42:8080
+SERVER_ADDRESS=http://localhost
 # DOMAIN=local.dockertoolbox.tiangolo.com
 # DOMAIN=localhost.tiangolo.com
 # DOMAIN=dev.ai-anchor.com
@@ -29,6 +29,9 @@ EMAILS_FROM_EMAIL=info@ai-anchor.com
 
 USERS_OPEN_REGISTRATION=True
 
+BACKEND_ZIP_STORAGE=backend_storage/zips
+BACKEND_VIDEO_STORAGE=backend_storage/videos
+
 SENTRY_DSN=
 
 # Flower
@@ -48,3 +51,7 @@ PGADMIN_DEFAULT_PASSWORD=password
 # Initial data
 MEMBERSHIP_TYPES=["normal", "infinite"]
 PROGRESS_TYPES=["waiting", "processing", "completed"]
+
+# celery
+CELERY_ZIP_STORAGE=celery_storage/zips
+CELERY_VIDEO_STORAGE=celery_storage/videos

+ 12 - 13
backend/app/app/api/api_v1/endpoints/videos.py

@@ -1,6 +1,6 @@
-from typing import Any, List
+from typing import Any, List, Optional
 
-from fastapi import UploadFile, File
+from fastapi import UploadFile, File, Form
 from fastapi.responses import FileResponse
 from fastapi import APIRouter, Depends, HTTPException
 from sqlalchemy.orm import Session
@@ -11,11 +11,11 @@ import app.schemas as schemas
 from app.api import deps
 
 from app.core.celery_app import celery_app
-
+from app.core.config import settings
 from pathlib import Path
 
-ZIP_STORAGE = "/app/backend/zips"
-VIDEO_STORAGE = "/app/backend/videos"
+ZIP_STORAGE = Path("/app").joinpath(settings.BACKEND_ZIP_STORAGE)
+VIDEO_STORAGE = Path("/app").joinpath(settings.BACKEND_VIDEO_STORAGE)
 
 
 router = APIRouter()
@@ -38,23 +38,21 @@ def get_video_list(
         )
     return videos
 
-@router.post("/", response_model=schemas.Item)
+@router.post("/", response_model=schemas.Video)
 def upload_plot(
     *,
     db: Session = Depends(deps.get_db),
-    title: str, 
+    title: str=Form(...), 
     upload_file: UploadFile=File(),
     current_user: models.User = Depends(deps.get_current_active_user),
 ) -> Any:
     """
     Create new video.
     """
-    video_create = schemas.VideoCreate
-    video_create.title = title
-    video_create.progress = models.Progress.WAITING
-    video_create.title = title
+    print(title)
+    print(upload_file.filename)
     file_name = crud.video.generate_file_name(db=db, n=20)
-    video_create.stored_file_name = file_name
+    video_create = schemas.VideoCreate(title=title, progress_state="waiting", stored_file_name=file_name)
     video = crud.video.create_with_owner(db=db, obj_in=video_create, owner_id=current_user.id)
 
     try:
@@ -110,7 +108,8 @@ def upload_complete_video(
     *,
     db: Session = Depends(deps.get_db),
     id: int,
-    upload_video: UploadFile=File(),
+    upload_video: Optional[UploadFile]=None,
+    result:int=Form(...)
 ) -> Any:
     
     video = db.query(models.Video).filter(db=db, id=id).first()

+ 7 - 1
backend/app/app/core/config.py

@@ -1,7 +1,7 @@
 import secrets
 from typing import Any, Dict, List, Optional, Union
 
-from pydantic import AnyHttpUrl, BaseSettings, EmailStr, HttpUrl, PostgresDsn, validator
+from pydantic import AnyHttpUrl, BaseSettings, EmailStr, HttpUrl, PostgresDsn, validator, DirectoryPath
 
 
 class Settings(BaseSettings):
@@ -102,6 +102,12 @@ class Settings(BaseSettings):
 
     SERVER_ADDRESS: AnyHttpUrl
 
+    CELERY_ZIP_STORAGE: str
+    CELERY_VIDEO_STORAGE: str
+
+    BACKEND_ZIP_STORAGE: str
+    BACKEND_VIDEO_STORAGE: str
+
     class Config:
         case_sensitive = True
 

+ 7 - 8
backend/app/app/schemas/video.py

@@ -7,17 +7,16 @@ from fastapi import UploadFile, File
 # Shared properties
 class VideoBase(BaseModel):
     title: Optional[str] = None
+    progress_state: Optional[str] = None
+    stored_file_name: Optional[str] = None
 
-# Properties to receive on item upload
-class VideoUpload(VideoBase):
-    title: str
-    stored_file_name: str
-
-# Properties to receive on item creation
+# Properties to receive on video creation
 class VideoCreate(VideoBase):
     title: str
+    progress_state: str
+    stored_file_name: str
 
-# Properties to receive on item update
+# Properties to receive on video update
 class VideoUpdate(VideoBase):
     pass
 
@@ -25,7 +24,7 @@ class VideoUpdate(VideoBase):
 class VideoInDBBase(VideoBase):
     id: int
     title: str
-    progress: str
+    progress_state: str
     owner_id: int
 
     class Config:

+ 2 - 2
backend/app/app/worker.py

@@ -11,8 +11,8 @@ client_sentry = Client(settings.SENTRY_DSN)
 download_to_local_url = urljoin(settings.SERVER_ADDRESS, settings.API_V1_STR, "/videos/worker")
 upload_to_server_url = urljoin(settings.SERVER_ADDRESS, settings.API_V1_STR, "/videos/worker")
 
-ZIP_STORAGE = "/app/celery/zips"
-VIDEO_STORAGE = "app/celery/videos"
+ZIP_STORAGE = Path("/app").joinpath(settings.CELERY_ZIP_STORAGE)
+VIDEO_STORAGE = Path("/app").joinpath(settings.CELERY_VIDEO_STORAGE)
 
 
 @celery_app.task(acks_late=True)

+ 8 - 0
backend/app/prestart.sh

@@ -8,3 +8,11 @@ python /app/app/backend_pre_start.py
 
 # Create initial data in DB
 python /app/app/initial_data.py
+
+if [ ! -e BACKEND_ZIP_STORAGE ]; then
+    mkdir BACKEND_ZIP_STORAGE
+fi
+
+if [ ! -e BACKEND_VIDEOS_STORAGE ]; then
+    mkdir BACKEND_VIDEOS_STORAGE
+fi

+ 9 - 1
backend/app/worker-start.sh

@@ -5,4 +5,12 @@ python /app/app/celeryworker_pre_start.py
 
 celery -A app.worker worker -l info -Q main-queue -c 1
 
-celery -A app.wo
+celery -A app.wo
+
+if [ ! -e ZIP_ZIP_STORAGE ]; then
+    mkdir ZIP_ZIP_STORAGE
+fi
+
+if [ ! -e ZIP_VIDEOS_STORAGE ]; then
+    mkdir ZIP_VIDEOS_STORAGE
+fi

+ 2 - 0
backend/backend.dockerfile

@@ -22,4 +22,6 @@ ARG INSTALL_JUPYTER=false
 RUN bash -c "if [ $INSTALL_JUPYTER == 'true' ] ; then pip install jupyterlab ; fi"
 
 COPY ./app /app
+COPY /${BACKEND_ZIP_STORAGE} /app/${BACKEND_ZIP_STORAGE}
+COPY /${BACKEND_VIDEO_STORAGE} /app/${BACKEND_VIDEO_STORAGE}
 ENV PYTHONPATH=/app

+ 4 - 1
backend/celeryworker.dockerfile

@@ -25,9 +25,12 @@ ENV C_FORCE_ROOT=1
 
 COPY ./app /app
 WORKDIR /app
-
+COPY /${CELERY_ZIP_STORAGE} /app/${CELERY_ZIP_STORAGE}
+COPY /${CELERY_ZIP_STORAGE} /app/${CELERY_ZIP_STORAGE}
 ENV PYTHONPATH=/app
 
+
+
 COPY ./app/worker-start.sh /worker-start.sh
 
 RUN chmod +x /worker-start.sh

+ 4 - 1
frontend/src/api.ts

@@ -1,6 +1,6 @@
 import axios from "axios";
 import { apiUrl } from "@/env";
-import type { IUserProfile, IUserProfileUpdate, IUserProfileCreate} from "@/interfaces";
+import type { IUserProfile, IUserProfileUpdate, IUserProfileCreate, Video} from "@/interfaces";
 
 function authHeaders(token: string) {
   return {
@@ -62,5 +62,8 @@ export const api = {
     formData.append("title", title)
     formData.append("upload_file", file)
     return axios.post<{msg:string}>(`${apiUrl}/api/v1/videos`, formData, authHeaders(token));
+  },
+  async getVideos(token: string) {
+    return axios.get<Video[]>(`${apiUrl}/api/v1/videos/`, authHeaders(token));
   }
 };

+ 7 - 2
local-docker-compose.override.yml

@@ -3,8 +3,7 @@ services:
 
   proxy:
     ports:
-      - "80:80"
-      - "8090:8080"
+      - "10000:80"
     command:
       # Enable Docker in Traefik, so that it reads labels from Docker services
       - --providers.docker
@@ -35,6 +34,10 @@ services:
   backend:
     volumes:
       - ./backend/app:/app
+      - /${BACKEND_ZIP_STORAGE}:/app/${BACKEND_ZIP_STORAGE}
+      - /${BACKEND_VIDEO_STORAGE}:/app/${BACKEND_VIDEO_STORAGE}
+    environment:
+      - SERVER_HOST=http://${DOMAIN?Variable not set}
     build:
       context: ./backend
       dockerfile: backend.dockerfile
@@ -52,6 +55,8 @@ services:
   celeryworker:
     volumes:
       - ./backend/app:/app
+      - /${CELERY_ZIP_STORAGE}:/app/${CELERY_ZIP_STORAGE}
+      - /${CELERY_VIDEO_STORAGE}:/app${CELERY_VIDEO_STORAGE}
     environment:
       - RUN=celery worker -A app.worker -l info -Q main-queue -c 1
       - JUPYTER=jupyter lab --ip=0.0.0.0 --allow-root --NotebookApp.custom_display_url=http://127.0.0.1:8888