tomoya преди 2 години
родител
ревизия
dfa9c498f9

+ 19 - 8
backend/app/app/api/api_v1/endpoints/videos.py

@@ -1,6 +1,8 @@
 from typing import Any, List
 
+from fastapi import UploadFile, File
 from fastapi import APIRouter, Depends, HTTPException
+from fastapi.responses import FileResponse
 from sqlalchemy.orm import Session
 
 import app.crud as crud
@@ -32,24 +34,33 @@ def get_video_list(
 def upload_plot(
     *,
     db: Session = Depends(deps.get_db),
-    video_upload: schemas.VideoUpload,
+    title: str,
+    zip_file: UploadFile=File(),
     current_user: models.User = Depends(deps.get_current_active_user),
 ) -> Any:
     """
     Create new video.
     """
     video_create = schemas.VideoCreate
-    video_create.title = video_upload.title
-    video_create.progress = models.Progress.WAITING
-    video = crud.item.create_with_owner(db=db, obj_in=video_create, owner_id=current_user.id)
+    video_create.title = title
+    file_name = crud.video.generate_file_name(db=db, n=20)
+    video_create.stored_file_name = file_name
+    video = crud.video.create_with_owner(db=db, obj_in=video_create, owner_id=current_user.id)
     return video
 
-@router.get("/{id}")
+@router.get("/{id}", response_model=FileResponse)
 def download_video(
-
+    *,
+    db: Session = Depends(deps.get_db),
+    id: int,
+    current_user: models.User = Depends(deps.get_current_active_user),
 ) -> Any:
-    pass
-
+    video = crud.video.get(db=db, id=id)
+    if video:
+      pass
+        #return FileResponse(path=str(USER_FILE.joinpath(str(id), "output.mp4")), filename=video['filename']+".mp4")
+    else:
+        pass
 @router.get("/worker/{id}")
 def download_plot(
 

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

@@ -14,7 +14,7 @@ class Settings(BaseSettings):
     # BACKEND_CORS_ORIGINS is a JSON-formatted list of origins
     # e.g: '["http://localhost", "http://localhost:4200", "http://localhost:3000", \
     # "http://localhost:8080", "http://local.dockertoolbox.tiangolo.com"]'
-    BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
+    BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = ["*"]
 
     @validator("BACKEND_CORS_ORIGINS", pre=True)
     def assemble_cors_origins(cls, v: Union[str, List[str]]) -> Union[List[str], str]:

+ 9 - 0
backend/app/app/crud/crud_video.py

@@ -7,6 +7,7 @@ from app.crud.base import CRUDBase
 from app.models.video import Video
 from app.schemas.video import VideoCreate, VideoUpdate
 
+from app.utils import random_name
 
 class CRUDVideo(CRUDBase[Video, VideoCreate, VideoUpdate]):
     def create_with_owner(
@@ -30,5 +31,13 @@ class CRUDVideo(CRUDBase[Video, VideoCreate, VideoUpdate]):
             .all()
         )
 
+    def generate_file_name(
+      self, db: Session, *, n:int
+    ) -> bool:
+        while True:
+            file_name = random_name(n)
+            if not db.query(self.model).filter(Video.stored_file_name==file_name).first():
+              return file_name
+
 
 video = CRUDVideo(Video)

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

@@ -8,16 +8,12 @@ from fastapi import UploadFile, File
 class VideoBase(BaseModel):
     title: Optional[str] = None
 
-# Properties to receive on item upload
-class VideoUpload(VideoBase):
-    title: str
-    zip_file: UploadFile=File()
-
-# Properties to receive on item creation
+# Properties to receive on video creation
 class VideoCreate(VideoBase):
     title: str
+    stored_file_name: str
 
-# Properties to receive on item update
+# Properties to receive on video update
 class VideoUpdate(VideoBase):
     pass
 

+ 6 - 0
backend/app/app/utils.py

@@ -7,6 +7,8 @@ import emails
 from emails.template import JinjaTemplate
 from jose import jwt
 
+import random, string
+
 from app.core.config import settings
 
 
@@ -104,3 +106,7 @@ def verify_password_reset_token(token: str) -> Optional[str]:
         return decoded_token["email"]
     except jwt.JWTError:
         return None
+
+def random_name(n):
+   randlst = [random.choice(string.ascii_letters + string.digits) for i in range(n)]
+   return ''.join(randlst)

+ 1 - 1
backend/app/prestart.sh

@@ -7,4 +7,4 @@ python /app/app/backend_pre_start.py
 alembic upgrade head
 
 # Create initial data in DB
-python /app/app/initial_data.py
+python /app/app/initial_data.py       

+ 0 - 12
frontend/src/views/Login.vue

@@ -86,19 +86,11 @@ onMounted(() => {});
           ></v-text-field>
 
           <p class="text-center">
-<<<<<<< HEAD
             還沒有帳號?
             <router-link to="/signup">註冊</router-link> / <router-link
               to="/recover-password"
               >忘記密碼</router-link
             >
-=======
-            {{ t("haventAccount") }}
-            <router-link to="/signup">{{ t("register") }}</router-link
-            >/<router-link to="/recover-password">{{
-              t("forgotPsd")
-            }}</router-link>
->>>>>>> choozmo/front-dev
           </p>
 
           <v-btn
@@ -113,8 +105,4 @@ onMounted(() => {});
       </v-col>
     </v-row>
   </v-container>
-<<<<<<< HEAD
-
-=======
->>>>>>> choozmo/front-dev
 </template>