def do_query(file_id, query_type): if not query_type: return {"error": boilerplate.ERROR_NO_QUERY_TYPE_SPECIFIED} processed_file_id = boilerplate.PROCESSED_PREFIX + file_id if processed_file_id in boilerplate.list_files(recursive=True): return { "result": query_data( {processed_file_id: boilerplate.get_file(processed_file_id)}, query_type=query_type) } return {"error": boilerplate.ERROR_NO_SUCH_FILE}
def do_process_task(file_ids_list): files_to_process = boilerplate.list_files(recursive=True, prefix=boilerplate.UPLOAD_PREFIX) if file_ids_list: files_to_process = [ boilerplate.UPLOAD_PREFIX + file_id for file_id in file_ids_list if (boilerplate.UPLOAD_PREFIX + file_id) in files_to_process ] data_to_process = { file_id[len(boilerplate.UPLOAD_PREFIX):]: boilerplate.get_file(file_id) for file_id in files_to_process } processed_file_ids = list() for processed_file_id, contents in process_data(data_to_process): processed_file_ids.append( boilerplate.add_processed_file(processed_file_id, contents, extension='txt')) return processed_file_ids
def list_files_endpoint(): return jsonify({'file_ids': boilerplate.list_files(recursive=True)})
def get_file_endpoint(file_id): if file_id in boilerplate.list_files(recursive=True): return boilerplate.get_file(file_id) return jsonify({'error': boilerplate.ERROR_NO_SUCH_FILE})