Example #1
0
class ResponseErrors:
    invalid_json = resp_json(dict(**_err, message="Invalid JSON"), status=415)
    invalid_params = resp_json(dict(**_err, message="Missing Parameters"),
                               status=422)
    invalid_note = resp_json(
        dict(**_err, message="The note does not exist or has expired."),
        status=404)
async def api_get_playlist(request, type: str, library_id: str):

    if type not in ["music", "aux"]:
        abort(401)

    if type == "music":
        return resp_json(await api.get_playlist_music_items(library_id))
    else:
        return resp_json(await api.get_playlist_aux_items(library_id))
async def api_get_playlists(request, type: str):

    if type not in ["music", "aux"]:
        abort(401)

    if type == "music":
        return resp_json(await api.get_playlist_music())
    else:
        return resp_json(await api.get_playlist_aux())
Example #4
0
def response_json(data,
                  code=SERVICE_SUCCESS_CODE,
                  msg='',
                  page_info=None,
                  **kwargs):
    body = _response(code=code, msg=msg, data=data, page_info=page_info)
    return resp_json(body, dumps=json.dumps, cls=UUIDEncoder, **kwargs)
Example #5
0
async def api_get(request: Request):
    """
    Web API handler for retrieving notes. Should always return JSON data.

    :param request: request provided by Sanic
    :return:
    """
    if request.json is None:
        return ResponseErrors.invalid_json

    uid = request.json.get("uid", None)
    if not isinstance(uid, str):
        return ResponseErrors.invalid_params

    doa = request.app.config.doa
    assert isinstance(doa, BaseNoteDOA)

    try:
        note = await doa.get_by_uid(uid)
    except (NoteExpired, NoteNotFound):
        return ResponseErrors.invalid_note
    else:
        return resp_json(dict(**_suc,
                              message="Successful",
                              title=note["title"],
                              note=note["note"]),
                         status=200)
def json_status(request):
    channel_states = []
    for i in range(server_state.get()["num_channels"]):
        channel_states.append(status(i))
    return resp_json({
        "server": server_state.get(),
        "channels": channel_states
    })
Example #7
0
async def group_star(request):
    """
    接收BI群星级评定
    {
        "command":"update_group_star",
        "data":[{
            "groupId":String,
            "state":number, //评星状态,0-undefined, 1-init 2-upgrade
            "star":number
        }]
    }
    """
    param = request.json
    logger.info(f'group start evaluate, req:{param}')
    command = param.get('command')
    data = param.get('data')
    if command != 'update_group_star':
        return resp_json({'resultCode': 100})
    loop = asyncio.get_event_loop()
    asyncio.run_coroutine_threadsafe(task_receive_group_star(data), loop)
    return resp_json({'resultCode': 100})
Example #8
0
async def api_create(request: Request):
    """
    Web API handler for creating notes. Should always return JSON data.

    :param request: request provided by Sanic
    :return:
    """
    if request.json is None:
        return ResponseErrors.invalid_json

    n, t, e = map(request.json.get, ("note", "title", "expiration"))
    t = t or "Untitled"
    e = e or 0

    if not n:
        return ResponseErrors.invalid_params

    doa = request.app.config.doa
    assert isinstance(doa, BaseNoteDOA)

    uid = await doa.create_note(t, n, e)

    return resp_json(dict(**_suc, message="Successful", uid=uid), status=201)
async def api_search_library(request):

    return resp_json(await api.get_track_search(request.args.get("title"),
                                                request.args.get("artist")))
async def api_list_showplans(request):

    return resp_json(await api.get_showplans())
def player_status_json(request, channel: int):

    return resp_json(status(channel))