def download(): # { slot_id } # # # OnError : { message, status: 401 } # OnError : { message, status: 403 } # : { status: 500 } auth_token = utils.get_token_from_header(request.headers.get('Authorization')) if not auth_token: return jsonify({'status': 'FAIL', 'message': 'Missing TOKEN'}), 401 task = download_log.apply_async(args=[auth_token, request.data.decode()]) _dir, name = task.wait() @after_this_request def remove_file(response): try: os.remove(_dir + '/' + name) except OSError: print('Could not remove file', _dir + '/' + name) pass return response return send_from_directory(_dir, filename=name, as_attachment=True)
def retrieve(): # OnSuccess: { data: [{ nodetype_id, images }], status: 200 } # {}, 500 auth_token = utils.get_token_from_header( request.headers.get('Authorization')) if not auth_token: return jsonify({'message': 'Missing TOKEN'}), 401 task = get_images.apply_async(args=[auth_token]) res = task.wait() status = res.pop('status') return jsonify(res), status
def delete(file_name): # OnSuccess: {}, 204 # {}, 500 auth_token = utils.get_token_from_header( request.headers.get('Authorization')) if not auth_token: return jsonify({'message': 'Missing TOKEN'}), 401 task = delete_image.apply_async(args=[auth_token, file_name]) res = task.wait() status = res.pop('status') return jsonify(res), status
def start(): # { slot_id } # # OnSuccess: { task_id, status: 200 } # OnError : { message, status: 401 } # { status: 500 } auth_token = utils.get_token_from_header(request.headers.get('Authorization')) if not auth_token: return jsonify({'status': 'FAIL', 'message': 'Missing TOKEN'}), 401 task = start_debug_channel.apply_async(args=[auth_token, request.data.decode()]) return jsonify({'task_id': task.id}), 200
def erase(): # { slot_id, node_uids } # # OnSuccess: { task_id, status: 200 } # OnError : { message, status: 401 } # { } auth_token = utils.get_token_from_header( request.headers.get('Authorization')) if not auth_token: return jsonify({'message': 'Missing TOKEN'}), 401 task = erase_nodes.apply_async(args=[auth_token, request.data.decode()]) return jsonify({'task_id': task.id}), 200
def clear(): # { slot_id } # # OnSuccess: { status: 204 } # OnError : { message, status: 401 } # { status: 500 } auth_token = utils.get_token_from_header(request.headers.get('Authorization')) if not auth_token: return jsonify({'status': 'FAIL', 'message': 'Missing TOKEN'}), 401 task = clear_log.apply_async(args=[auth_token, request.data.decode()]) res = task.wait() status = res.pop('status') return jsonify(res), status
def save(): # { slots: [{start, end}] } # # OnSuccess: { slots: [{start, end}], status: 200 } # OnError : { message, status: 401 } # { status: 500 } auth_token = utils.get_token_from_header( request.headers.get('Authorization')) if not auth_token: return jsonify({'message': 'Missing TOKEN'}), 401 task = save_timeslots.apply_async(args=[auth_token, request.data.decode()]) res = task.wait() status = res.pop('status') return jsonify(res), status
def user_slots(): # # # OnSuccess: [{slot_id, start, end}], 200 # OnError : message, 401 # {}, 500 auth_token = utils.get_token_from_header( request.headers.get('Authorization')) if not auth_token: return jsonify({'message': 'Missing TOKEN'}), 401 task = get_user_slots.apply_async(args=[auth_token]) res = task.wait() status = res.pop('status') return jsonify(res), status
def retrieve(): # {} # # OnSuccess: { nodes, status: 200 } # OnError : { message, status: 401 } # { status: 500 } auth_token = utils.get_token_from_header( request.headers.get('Authorization')) if not auth_token: return jsonify({'message': 'Missing TOKEN'}), 401 task = get_nodes.apply_async(args=[auth_token]) res = task.wait() status = res.pop('status') return jsonify(res), status
def reset(): # { slot_id, node_uids } # # OnSuccess: { } # OnError : { message, status: 401 } # { } auth_token = utils.get_token_from_header( request.headers.get('Authorization')) if not auth_token: return jsonify({'message': 'Missing TOKEN'}), 401 task = reset_nodes.apply_async(args=[auth_token, request.data.decode()]) res = task.wait() status = res.pop('status') return jsonify(res), status
def save(file_name): # OnSuccess: {}, 200 # {}, 500 auth_token = utils.get_token_from_header( request.headers.get('Authorization')) if not auth_token: return jsonify({'message': 'Missing TOKEN'}), 401 file_data = request.files['binary'].read() task = store_image.apply_async(args=[ auth_token, file_name, file_data.decode(), request.form['nodetype_id'] ]) res = task.wait() status = res.pop('status') return jsonify(res), status