def get_files(): """Get files info of the logged user Returns ------- json files: list of all files of current user error: True if error, else False errorMessage: the error message of error, else an empty string """ files_id = None if request.method == 'POST': data = request.get_json() if data: files_id = data.get('filesId') try: files_handler = FilesHandler(current_app, session) files = files_handler.get_files_infos(files_id=files_id) disk_space = files_handler.get_size_occupied_by_user() except Exception as e: traceback.print_exc(file=sys.stdout) return jsonify({ 'files': [], 'diskSpace': 0, 'error': True, 'errorMessage': str(e) }), 500 return jsonify({ 'files': files, 'diskSpace': disk_space, 'error': False, 'errorMessage': '' })
def edit_file(): """Edit file name Returns ------- json files: list of all files of current user error: True if error, else False errorMessage: the error message of error, else an empty string """ data = request.get_json() current_app.logger.debug(data) if not (data and data.get("id") and data.get("newName")): return jsonify({ 'files': [], 'diskSpace': 0, 'error': True, 'errorMessage': "Missing parameters" }), 400 files_id = [data["id"]] new_name = data["newName"] try: files_handler = FilesHandler(current_app, session) files_handler.handle_files(files_id) for file in files_handler.files: file.edit_name_in_db(new_name) files = files_handler.get_files_infos() except Exception as e: traceback.print_exc(file=sys.stdout) return jsonify({ 'files': [], 'diskSpace': 0, 'error': True, 'errorMessage': str(e) }), 500 return jsonify({ 'files': files, 'diskSpace': files_handler.get_size_occupied_by_user(), 'error': False, 'errorMessage': '' })