async def generate_access_token(self, login_user: LoginUser = Body(None, embed=True), grant_type: str = Body(...), refresh_token: str = Body(None)): if grant_type == 'password' and login_user is not None: login_user: dict = login_user.dict() username: str = login_user['username'] password: str = login_user['password'] if not bool(username) and bool(login_user.get('email', None)): user_dict: dict = await self._db.get_user(login_user['email']) if not bool(user_dict): raise HTTPException(status_code=HTTP_400_BAD_REQUEST, detail='Invalid email address', headers={'Authenticate': 'Bearer'}) username = user_dict['username'] response = await self._keycloak_service.generate_tokens( username, password) return await build_response(data=response) if grant_type == 'refresh_token' and refresh_token is not None: response = await self._keycloak_service.refresh_tokens( refresh_token) return await build_response(status_code=HTTP_200_OK, data=response) raise HTTPException(status_code=HTTP_401_UNAUTHORIZED, detail='Invalid grant type or token', headers={'Authenticate': 'Bearer'})
def reset_password( token: str = Body(...), email: str = Body(...), password: str = Body(...), session: Session = Depends(dependencies.get_database_session), ): error = HTTPException(400, "Invalid token") user_with_email: User = ( session.query(User).filter(User.email == email).one_or_none() ) if not user_with_email: raise HTTPException(404, "User not found") try: payload = util.get_payload_from_token(token) token_type = payload["type"] if token_type != PASSWORD_RESET_TOKEN_VALUE: raise error token_email = payload["email"] if token_email != user_with_email.email: raise error user_password = util.hash_password(password) user_with_email.hashed_password = user_password session.commit() except PyJWTError: raise error except KeyError: raise error
async def update_talent(id: int, description: str, name: str, type: str, status: int, profile: str, file_pro: UploadFile = File(...), file_cover: UploadFile = File(...), filename1: str = Body(default=None), filename2: str = Body(default=None), db: Session = Depends(get_db)): if filename1 is None: #filename = generate_png_string() extension_pro = file_pro.filename.split(".")[-1] in ("jpg", "jpeg", "png") if not extension_pro: return "Image must be jpg or png format!" suffix_pro = Path(file_pro.filename).suffix filename = time.strftime( str(uuid.uuid4().hex) + "%Y%m%d-%H%M%S" + suffix_pro) data = file_pro.file._file # Converting tempfile.SpooledTemporaryFile to io.BytesIO uploads31 = await s3_client.upload_fileobj(bucket=S3_Bucket, key=S3_Key + "/" + filename, fileobject=data) if uploads31: url_profile = os.path.join(PUBLIC_DESTINATION, S3_Key + "/" + filename) else: raise HTTPException(status_code=400, detail="Failed to upload in S3") if filename2 is None: #filename = generate_png_string() extension_pro = file_cover.filename.split(".")[-1] in ("jpg", "jpeg", "png") if not extension_pro: return "Image must be jpg or png format!" suffix_pro = Path(file_cover.filename).suffix filename = time.strftime( str(uuid.uuid4().hex) + "%Y%m%d-%H%M%S" + suffix_pro) data = file_cover.file._file # Converting tempfile.SpooledTemporaryFile to io.BytesIO uploads32 = await s3_client.upload_fileobj(bucket=S3_Bucket, key=S3_Key + "/" + filename, fileobject=data) if uploads32: url_cover = os.path.join(PUBLIC_DESTINATION, S3_Key + "/" + filename) subject = crud.get_talent(db, id) if not subject: raise HTTPException(status_code=404, detail="Talents not found") query = "UPDATE talents SET url_profile='" + str( url_profile ) + "' , description='" + str(description) + "' , profile ='" + str( profile) + "', status='" + str(status) + "', url_cover='" + str( url_cover) + "' WHERE id='" + str(id) + "'" db.execute(query) db.commit() return {"Result": "Talent Updated Succesfully"} else: raise HTTPException(status_code=400, detail="Failed to upload in S3")
async def create_talent(description: str, name: str, type: str, status: int, profile: str, file_pro: UploadFile = File(...), file_cover: UploadFile = File(...), filename1: str = Body(default=None), filename2: str = Body(default=None), db: Session = Depends(get_db)): if filename1 is None: #filename = generate_png_string() extension_pro = file_pro.filename.split(".")[-1] in ("jpg", "jpeg", "png") if not extension_pro: return "Image must be jpg or png format!" suffix_pro = Path(file_pro.filename).suffix filename = time.strftime( str(uuid.uuid4().hex) + "%Y%m%d-%H%M%S" + suffix_pro) data = file_pro.file._file # Converting tempfile.SpooledTemporaryFile to io.BytesIO uploads3 = await s3_client.upload_fileobj(bucket=S3_Bucket, key=S3_Key + "/" + filename, fileobject=data) if uploads3: url_profile = os.path.join(PUBLIC_DESTINATION, S3_Key + "/" + filename) else: raise HTTPException(status_code=400, detail="Failed to upload in S3") if filename2 is None: #filename = generate_png_string() extension_pro = file_cover.filename.split(".")[-1] in ("jpg", "jpeg", "png") if not extension_pro: return "Image must be jpg or png format!" suffix_pro = Path(file_cover.filename).suffix filename = time.strftime( str(uuid.uuid4().hex) + "%Y%m%d-%H%M%S" + suffix_pro) data = file_cover.file._file # Converting tempfile.SpooledTemporaryFile to io.BytesIO uploads3 = await s3_client.upload_fileobj(bucket=S3_Bucket, key=S3_Key + "/" + filename, fileobject=data) if uploads3: url_cover = os.path.join(PUBLIC_DESTINATION, S3_Key + "/" + filename) return crud.create_talent(db=db, name=name, description=description, profile=profile, url_profile=url_profile, url_cover=url_cover, type=type, status=status) else: raise HTTPException(status_code=400, detail="Failed to upload in S3")
async def create_lesson(course_id: int, title: str, name: str, description: str, chapter: int, fileobject: UploadFile = File(...), filename: str = Body(default=None), db: Session = Depends(get_db)): if filename is None: #filename = generate_png_string() extension_pro = fileobject.filename.split(".")[-1] in ("mp4", "3gp", "mkv") if not extension_pro: return "video must be jpg or png format!" suffix_pro = Path(fileobject.filename).suffix filename = time.strftime( str(uuid.uuid4().hex) + "%Y%m%d-%H%M%S" + suffix_pro) data = fileobject.file._file # Converting tempfile.SpooledTemporaryFile to io.BytesIO uploads3 = await s3_client.upload_fileobj(bucket=S3_Bucket, key=S3_Key + "/" + filename, fileobject=data) if uploads3: url = os.path.join(PUBLIC_DESTINATION, S3_Key + "/" + filename) return crud.create_lesson(db=db, name=name, title=title, description=description, url=url, course_id=course_id, chapter=chapter) else: raise HTTPException(status_code=400, detail="Failed to upload in S3")
def new_task( request: Request, namespace: str, task: str, node_name: str, json_body: Optional[NewTaskRequest] = Body(...), ): if node_name == "default": amqp_client = get_amqp_client(namespace, request) for i in range(0, 1): amqp_client.send( Task(name=task, arguments=json_body.arguments, tags=json_body.tags).to_json()) amqp_client.close() else: new_task: Task = Task( name=task, arguments=json_body.arguments, node_names=[node_name], tags=json_body.tags, ) print("new_task: " + new_task.to_json()) amqp_client = get_amqp_client(namespace, request) for i in range(0, 20): print(i) amqp_client.send(new_task.to_json()) amqp_client.close() return {"status": "OK"}
async def webhook(payload: dict = Body(...), PAYPAL_TRANSMISSION_ID: str = Header(None), PAYPAL_TRANSMISSION_TIME: str = Header(None), PAYPAL_TRANSMISSION_SIG: str = Header(None), PAYPAL_AUTH_ALGO: str = Header(None), PAYPAL_CERT_URL: str = Header(None)): try: # Verify signature cert = await getPayPalCert(PAYPAL_CERT_URL) if not cert: raise ServiceUnavailableError signature = f'{PAYPAL_TRANSMISSION_ID}|{PAYPAL_TRANSMISSION_TIME}|{PayPalSettings.WEBHOOK_ID}|{crc32(bytes(payload))}' cert = x509.load_pem_x509_certificate( cert.encode('ascii'), backend=backends.default_backend()) public_key = cert.public_key() try: public_key.verify(PAYPAL_TRANSMISSION_SIG, signature, padding.PKCS1v15(), hashes.SHA256()) except Exception: raise UnauthorizedError # Signature verification complete if payload['event_type'] == 'CHECKOUT.ORDER.COMPLETED': pass return 'ok' except ServiceUnavailableError: raise ServiceUnavailableError().http_exception except UnauthorizedError: raise UnauthorizedError().http_exception except Exception as e: raise e
async def create_project(client_id: str, first_name: str, details: str, fileobject: UploadFile = File(...), filename: str = Body(default=None), db: Session = Depends(get_db)): if filename is None: #filename = generate_png_string() extension_pro = fileobject.filename.split(".")[-1] in ("mp4", "3gp", "mkv") if not extension_pro: return "Video must be mp4 or 3gp format!" suffix_pro = Path(fileobject.filename).suffix filename = time.strftime( str(uuid.uuid4().hex) + "%Y%m%d-%H%M%S" + suffix_pro) data = fileobject.file._file # Converting tempfile.SpooledTemporaryFile to io.BytesIO uploads3 = await s3_client1.upload_fileobj(bucket=S3_Bucket, key=S3_Key + "/" + filename, fileobject=data) if uploads3: url = os.path.join(PUBLIC_DESTINATION, S3_Key + "/" + filename) return crud.create_project(db=db, client_id=client_id, first_name=first_name, details=details, url=url)
def delete( self, id: EncodedDatabaseIdField = QuotaIdPathParam, trans: ProvidesUserContext = DependsOnTrans, payload: DeleteQuotaPayload = Body(None), # Optional ) -> str: """Deletes an existing quota.""" return self.service.delete(trans, id, payload)
async def getComment(sno: str = Body(..., embed=True), current_user: Dict = Security( get_current_user, scopes=["user", "administrator", "supervisor"])) -> Dict: cv = await crud_cv.select_one_by(CvInfo.c.sno == sno) commentList = eval(cv["comment"]) return {"code": 0, "data": commentList}
def add_category(*, id: int, c_id: int = Body(...), db: Session = Depends(database.get_db), current_user: User = Depends(auth.get_current_active_user)): db_obj = product_repo.get(db, id=id) if not db_obj: raise PRODUCT_NOT_FOUND_EXCEPTION category = category_repo.get(db, id=c_id) return product_repo.add_category(db, db_obj=db_obj, category=category)
def create_product(*, product_in: ProductCreate, categories: List[str] = Body(None), db: Session = Depends(database.get_db), current_user: User = Depends(auth.get_current_active_user)): product = product_repo.create_with_user(db, obj_in=product_in, owner_id=current_user.id) categories = category_repo.get_with_names(db, names=categories) product_repo.add_categories(db, db_obj=product, categories=categories) return product
def remove_image(*, id: int, image_url: str = Body(...), db: Session = Depends(database.get_db), current_user: User = Depends(auth.get_current_active_user)): product = product_repo.get(db, id=id) if not product: raise PRODUCT_NOT_FOUND_EXCEPTION image = image_repo.get_with_url(db, url=image_url) if image: product_repo.remove_image(db, db_obj=product, image=image)
def subscriptions_by_in_used_by_ids(data: List[UUID] = Body(...)) -> Dict[UUID, SubscriptionSchema]: rows = db.session.execute( select(SubscriptionInstanceTable) .join(SubscriptionTable) .filter(SubscriptionInstanceTable.subscription_instance_id.in_(data)) ).all() result = {row[0].subscription_instance_id: row[0].subscription for row in rows} if len(rows) != len(data): logger.warning( "Not all subscription_instance_id's could be resolved.", unresolved_ids=list(set(data) - set(result.keys())), ) return result
async def update_item(*, item_id: int, item: Item, user: User, importance: int = Body(...)): """ Body 的奇异值 """ result = { "item_id": item_id, "item": item, "user": user, "importance": importance } return result
def new_process( workflow_key: str, request: Request, json_data: Optional[List[Dict[str, Any]]] = Body(...), user: Optional[OIDCUserModel] = Depends(oidc_user), ) -> Dict[str, UUID]: check_global_lock() user_name = user.user_name if user else SYSTEM_USER broadcast_func = api_broadcast_process_data(request) pid = start_process(workflow_key, user_inputs=json_data, user=user_name, broadcast_func=broadcast_func)[0] return {"id": pid}
async def user_login(db: Session = Depends(get_db), user: UserLoginSchema = Body(...)): db_user = UserService.find_user_by_email(db, email=user.email) if not db_user: raise HTTPException( status_code=status.HTTP_404_NOT_FOUND, detail="User not found.", ) if not pwd_context.verify(user.password, db_user.password): raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Wrong password.", ) return signJWT(db_user)
def forgot_password( background: BackgroundTasks, email: str = Body(...), session: Session = Depends(dependencies.get_database_session), ): user_with_email = session.query(User).filter(User.email == email).one_or_none() if user_with_email: password_reset_token = util.create_access_token( {"type": PASSWORD_RESET_TOKEN_VALUE, "email": email} ) url = f"{config.CLIENT_HOST}/forgot-password?token={password_reset_token}" email_str = f"Follow this link to reset password {url}" background.add_task( util.send_email, to=email, subject="Reset Digirent Password", message=email_str, )
def verify_email( token: str = Body(...), session: Session = Depends(dependencies.get_database_session), ): error = HTTPException(400, "Invalid token") try: payload = util.get_payload_from_token(token) token_type = payload["type"] if token_type != EMAIL_VERIFICATION_TOKEN_VALUE: raise error email = payload["email"] user_with_email: User = (session.query(User).filter( User.email == email).one_or_none()) if not user_with_email: raise error user_with_email.email_verified = True session.commit() except PyJWTError: raise error except KeyError: raise error
def log_user_info(user_name: str, message: Dict = Body(...)) -> Dict: """Log frontend messages that are related to user actions. When the frontend finalizes the setup of a login session it will do a HTTP POST to this endpoint. The frontend will also post to this endpoint when it ends a user session. Args: user_name: the username (email) of the user involved message: A log message. Returns: {} """ try: json_dict: Any = json_loads(str(message)) _message = json_dict["message"] except Exception: _message = message logger.info("Client sent user info", message=_message, user_name=user_name) return {}
def resume_process_endpoint( pid: UUID, request: Request, json_data: JSON = Body(...), user: Optional[OIDCUserModel] = Depends(oidc_user) ) -> None: check_global_lock() process = _get_process(pid) if process.last_status == ProcessStatus.RUNNING: raise_status(HTTPStatus.CONFLICT, "Resuming a running workflow is not possible") user_name = user.user_name if user else SYSTEM_USER broadcast_func = api_broadcast_process_data(request) resume_process(process, user=user_name, user_inputs=json_data, broadcast_func=broadcast_func)
async def create_story(story: str, fileobject: UploadFile = File(...), filename: str = Body(default=None), db: Session = Depends(get_db)): if filename is None: #filename = generate_png_string() extension_pro = fileobject.filename.split(".")[-1] in ("jpg", "jpeg", "png") if not extension_pro: return "Image must be jpg or png format!" suffix_pro = Path(fileobject.filename).suffix filename = time.strftime( str(uuid.uuid4().hex) + "%Y%m%d-%H%M%S" + suffix_pro) data = fileobject.file._file # Converting tempfile.SpooledTemporaryFile to io.BytesIO uploads3 = await s3_client.upload_fileobj(bucket=S3_Bucket, key=S3_Key + "/" + filename, fileobject=data) if uploads3: url = os.path.join(PUBLIC_DESTINATION, S3_Key + "/" + filename) return crud.create_story(db=db, story=story, url=url)
async def update_lesson(id: int, course_id: int, title: str, name: str, description: str, chapter: int, fileobject: UploadFile = File(...), filename: str = Body(default=None), db: Session = Depends(get_db)): if filename is None: #filename = generate_png_string() extension_pro = fileobject.filename.split(".")[-1] in ("mp4", "3gp", "mkv") if not extension_pro: return "video must be jpg or png format!" suffix_pro = Path(fileobject.filename).suffix filename = time.strftime( str(uuid.uuid4().hex) + "%Y%m%d-%H%M%S" + suffix_pro) data = fileobject.file._file # Converting tempfile.SpooledTemporaryFile to io.BytesIO uploads3 = await s3_client.upload_fileobj(bucket=S3_Bucket, key=S3_Key + "/" + filename, fileobject=data) if uploads3: url = os.path.join(PUBLIC_DESTINATION, S3_Key + "/" + filename) subject = crud.get_lesson(db, id) if not subject: raise HTTPException(status_code=404, detail="Lesson not found") query = "UPDATE lessons SET title='" + str(title) + "' , name='" + str( name ) + "', description ='" + str(description) + "', COURSE_ID = '" + str( course_id) + "' , chapter='" + str(chapter) + "', url='" + str( url) + "' WHERE id='" + str(id) + "'" db.execute(query) db.commit() return {"Result": "Module Updated Succesfully"} else: raise HTTPException(status_code=400, detail="Failed to upload in S3")
async def update_talent(id: int, talent_id: int, description: str, name: str, status: int, fileobject: UploadFile = File(...), filename: str = Body(default=None), db: Session = Depends(get_db)): if filename is None: #filename = generate_png_string() extension_pro = fileobject.filename.split(".")[-1] in ("jpg", "jpeg", "png") if not extension_pro: return "Image must be jpg or png format!" suffix_pro = Path(fileobject.filename).suffix filename = time.strftime( str(uuid.uuid4().hex) + "%Y%m%d-%H%M%S" + suffix_pro) data = fileobject.file._file # Converting tempfile.SpooledTemporaryFile to io.BytesIO uploads3 = await s3_client.upload_fileobj(bucket=S3_Bucket, key=S3_Key + "/" + filename, fileobject=data) if uploads3: url = os.path.join(PUBLIC_DESTINATION, S3_Key + "/" + filename) subject = crud.get_honour(db, id) if not subject: raise HTTPException(status_code=404, detail="Module not found") #'select * from USERS where email='+"'"+str(username)+"'"+' and PASSWORD='******'"+str(password)+"'" query = "UPDATE honours SET description='" + str( description) + "' , name='" + str(name) + "', talent_id = '" + str( talent_id) + "' , status='" + str(status) + "', url='" + str( url) + "' WHERE id='" + str(id) + "'" db.execute(query) db.commit() return {"Result": "Module Updated Succesfully"} else: raise HTTPException(status_code=400, detail="Failed to upload in S3")
async def update_build_your_talent(client_id: str, id: int, full_name: str, work: str, award: str, portfolio_link: str, profile: str, years_3_5: bool = False, years_5_7: bool = False, years_7_10: bool = False, above_10: bool = False, profile_picture: UploadFile = File(...), filename1: str = Body(default=None), work_picture: UploadFile = File(...), filename2: str = Body(default=None), work_video: UploadFile = File(...), filename3: str = Body(default=None), db: Session = Depends(get_db)): if filename1 is None: #filename = generate_png_string() extension_pro = profile_picture.filename.split(".")[-1] in ("jpg", "jpeg", "png") if not extension_pro: return "Profile picture must be jpg or png format!" suffix_pro = Path(profile_picture.filename).suffix filename1 = time.strftime( str(uuid.uuid4().hex) + "%Y%m%d-%H%M%S" + suffix_pro) data = profile_picture.file._file # Converting tempfile.SpooledTemporaryFile to io.BytesIO uploads3 = await s3_client2.upload_fileobj(bucket=S3_Bucket, key=S3_Key + "/" + filename1, fileobject=data) if uploads3: profile_picture = os.path.join(PUBLIC_DESTINATION, S3_Key + "/" + filename1) else: raise HTTPException(status_code=400, detail="Failed to upload in S3") if filename2 is None: #filename = generate_png_string() extension_pro = work_picture.filename.split(".")[-1] in ("jpg", "jpeg", "png") if not extension_pro: return "work picture must be jpg or png format!" suffix_pro = Path(work_picture.filename).suffix filename2 = time.strftime( str(uuid.uuid4().hex) + "%Y%m%d-%H%M%S" + suffix_pro) data = work_picture.file._file # Converting tempfile.SpooledTemporaryFile to io.BytesIO uploads3 = await s3_client2.upload_fileobj(bucket=S3_Bucket, key=S3_Key + "/" + filename2, fileobject=data) if uploads3: work_picture = os.path.join(PUBLIC_DESTINATION, S3_Key + "/" + filename2) else: raise HTTPException(status_code=400, detail="Failed to upload in S3") if filename3 is None: #filename = generate_png_string() extension_pro = work_video.filename.split(".")[-1] in ("mp4", "3gp", "mkv") if not extension_pro: return "Video must be mp4 or 3gp format!" suffix_pro = Path(work_video.filename).suffix filename3 = time.strftime( str(uuid.uuid4().hex) + "%Y%m%d-%H%M%S" + suffix_pro) data = work_video.file._file # Converting tempfile.SpooledTemporaryFile to io.BytesIO uploads3 = await s3_client1.upload_fileobj(bucket=S3_Bucket, key=S3_Key + "/" + filename3, fileobject=data) if uploads3: work_video = os.path.join(PUBLIC_DESTINATION, S3_Key + "/" + filename3) subject = crud.get_your_talent(db, id) if not subject: raise HTTPException(status_code=404, detail="Talents not found") query = "UPDATE buildtalents SET full_name='" + str( full_name) + "' , work='" + str(work) + "' , award='" + str( award) + "', portfolio_link='" + str( portfolio_link ) + "',years_3_5='" + str(years_3_5) + "' , years_5_7='" + str( years_5_7) + "' , years_7_10='" + str( years_7_10 ) + "', above_10='" + str(above_10) + "',profile='" + str( profile) + "' , profile_picture='" + str( profile_picture) + "' , work_picture='" + str( work_picture) + "', work_video='" + str( work_video) + "', client_id ='" + str( client_id) + "' WHERE id='" + str( id) + "'" db.execute(query) db.commit() return {"Result": "Talent Updated Succesfully"} else: raise HTTPException(status_code=400, detail="Failed to upload in S3")
class AssetUploadModel(BaseModel): fileobject: UploadFile = File(...) filename: str = Body(default=None)
def create(data: ProductTypeCreate = Body(...)) -> None: return product_type_crud.create(obj_in=data)
async def login(user: LoginUser = Body(None, embed=True), grant_type: str = Body(...), refresh_token: str = Body(None)): service = AuthService() return await service.generate_access_token(user, grant_type, refresh_token)
async def create_build_your_talent(client_id: str, full_name: str, work: str, award: str, portfolio_link: str, profile: str, years_3_5: bool = False, years_5_7: bool = False, years_7_10: bool = False, above_10: bool = False, profile_picture: UploadFile = File(...), filename1: str = Body(default=None), work_picture: UploadFile = File(...), filename2: str = Body(default=None), work_video: UploadFile = File(...), filename3: str = Body(default=None), db: Session = Depends(get_db)): if filename1 is None: #filename = generate_png_string() extension_pro = profile_picture.filename.split(".")[-1] in ("jpg", "jpeg", "png") if not extension_pro: return "Profile picture must be jpg or png format!" suffix_pro = Path(profile_picture.filename).suffix filename1 = time.strftime( str(uuid.uuid4().hex) + "%Y%m%d-%H%M%S" + suffix_pro) data = profile_picture.file._file # Converting tempfile.SpooledTemporaryFile to io.BytesIO uploads3 = await s3_client2.upload_fileobj(bucket=S3_Bucket, key=S3_Key + "/" + filename1, fileobject=data) if uploads3: profile_picture = os.path.join(PUBLIC_DESTINATION, S3_Key + "/" + filename1) else: raise HTTPException(status_code=400, detail="Failed to upload in S3") if filename2 is None: #filename = generate_png_string() extension_pro = work_picture.filename.split(".")[-1] in ("jpg", "jpeg", "png") if not extension_pro: return "work picture must be jpg or png format!" suffix_pro = Path(work_picture.filename).suffix filename2 = time.strftime( str(uuid.uuid4().hex) + "%Y%m%d-%H%M%S" + suffix_pro) data = work_picture.file._file # Converting tempfile.SpooledTemporaryFile to io.BytesIO uploads3 = await s3_client2.upload_fileobj(bucket=S3_Bucket, key=S3_Key + "/" + filename2, fileobject=data) if uploads3: work_picture = os.path.join(PUBLIC_DESTINATION, S3_Key + "/" + filename2) else: raise HTTPException(status_code=400, detail="Failed to upload in S3") if filename3 is None: #filename = generate_png_string() extension_pro = work_video.filename.split(".")[-1] in ("mp4", "3gp", "mkv") if not extension_pro: return "Video must be mp4 or 3gp format!" suffix_pro = Path(work_video.filename).suffix filename3 = time.strftime( str(uuid.uuid4().hex) + "%Y%m%d-%H%M%S" + suffix_pro) data = work_video.file._file # Converting tempfile.SpooledTemporaryFile to io.BytesIO uploads3 = await s3_client1.upload_fileobj(bucket=S3_Bucket, key=S3_Key + "/" + filename3, fileobject=data) if uploads3: work_video = os.path.join(PUBLIC_DESTINATION, S3_Key + "/" + filename3) return crud.create_your_talent(db=db, client_id=client_id, full_name=full_name, work=work, award=award, portfolio_link=portfolio_link, profile=profile, years_3_5=years_3_5, years_5_7=years_5_7, years_7_10=years_7_10, above_10=above_10, profile_picture=profile_picture, work_picture=work_picture, work_video=work_video) else: raise HTTPException(status_code=400, detail="Failed to upload in S3")
def admin_create(data: MapCreateAdmin = Body(...), current_user: UsersTable = Depends( deps.get_current_active_superuser)) -> None: return map_crud.create(obj_in=data)