Esempio n. 1
0
def save_new_files(indexed_files: list, file_type: str):
    """
    Function get files dict and files type and save it to DB

    :param indexed_files: List with all indexed files

    :param file_type: Files type - `image` or `video`
    """
    try:
        if file_type == "image":
            for image_data in indexed_files:
                # if current md5_hash not exist
                if not Image.get(image_md5_hash=image_data["md5_hash"]):
                    Image(
                        image_name=image_data["namepath"][0],
                        image_path=image_data["namepath"][1],
                        image_height=image_data["height"],
                        image_width=image_data["width"],
                        image_descriptor=image_data["image_descriptor"],
                        image_md5_hash=image_data["md5_hash"],
                    )
        elif file_type == "video":
            for video_data in indexed_files:
                # if current video+path not exist
                if not Video.get(video_path=video_data["namepath"][1]):
                    Video(video_name=video_data["namepath"][0],
                          video_path=video_data["namepath"][1])
        else:
            raise ValueError("Wrong `file_type` param set")

    except Exception:
        logger.error(traceback.format_exc())
Esempio n. 2
0
 def get(self, img_id):
     file = Image.get(id=img_id)
     user_id = get_jwt_identity()
     user = User.get(id=user_id)
     if not file:
         return {'message': 'Файл не найден'}, 404
     elif file.uploaded_by != user:
         return {'message': 'Информация о загруженных файлах доступно только загрузившим их пользователям'}, 403
     elif not file.complete:
         return {'message': 'Обработка файла не завершена'}
     else:
         path = os.path.join(UPLOAD_FOLDER, file.filename)
         file.delete()
         return send_file(path)