Exemplo n.º 1
0
def publish_video(video_payload: VideoType, channel_id: str, request: Request,
                  response: Response):

    video = Video()
    video.name = video_payload.name
    video.summary = video_payload.summary
    video.tags = video_payload.tags
    video.path = video_payload.path
    video.filename = video_payload.filename
    video.channel = channel_id

    # Thumbnail
    thumbnail = Photo()
    thumbnail._id = uuid.uuid4()
    thumbnail.path = video_payload.thumbnail.path
    thumbnail.filename = video_payload.thumbnail.filename
    video.thumbnail = thumbnail

    # Save vide
    video.save()

    return {"msg": "publishing videos!"}
Exemplo n.º 2
0
def upload():
    try:
        f = request.files["file"]

        key = upload_to_cloud(f)
        video = Video()
        video.key = key
        video.user_id = request.user_id
        video.filename = f.filename

        db.session.add(video)
        db.session.commit()

        video_with_url = {**(video.to_dict()), "url": build_url(video.key)}

        return response(status=constants.SUCCESS,
                        message=constants.UPLOAD_SUCCESS,
                        video=video_with_url)
    except Exception:
        return response(status=constants.ERROR,
                        message=constants.SOMETHING_WENT_WRONG,
                        status_code=422)