Exemple #1
0
def update(token, uid, csdn):
    if token == '':
        if uid == '':
            return _error_uid_empty()
        if csdn == '':
            return _error_csdn_empty()

        if db.user_get(uid, csdn) is None:
            print(f'用户暂未登陆CSDN账号 {uid} -> {csdn}')
            return _error_csdn_not_login()

        _condition = {
            'action': 'update',
            'uid': uid,
            'message': csdn,
            '$nor': [{
                'state': 'fail'
            }, {
                'state': 'done'
            }]
        }
        if db.act.find_one(_condition) is not None:
            print(f'当前账户正在更新信息中,请勿重复提交。{uid} -> {csdn}')
            return _error_repeated_request()

        token = _gen_token('update')
        db.act_create(token, uid, 'update', 'request', csdn)
        return _token_build(token)
    else:
        return update_get_state(token, uid)
Exemple #2
0
def download(token, uid, csdn, url):
    if token == '':
        if uid == '':
            return _error_uid_empty()
        if csdn == '':
            return _error_csdn_empty()
        if url == '':
            return _error_xxx_empty('url')

        if db.user_get(uid, csdn) is None:
            print(f'用户暂未登陆CSDN账号 {uid} -> {csdn}')
            return _error_csdn_not_login()

        _condition = {
            'action': 'download',
            'uid': uid,
            'message.url': url,
            '$nor': [{
                'state': 'fail'
            }, {
                'state': 'done'
            }]
        }
        if db.act.find_one(_condition) is not None:
            print(f'当前资源正在下载中,请勿重复提交。{uid} -> {csdn} {url}')
            return _error_repeated_request()

        token = _gen_token('download')
        db.act_create(token, uid, 'download', 'request', {
            'csdn': csdn,
            'url': url
        })
        return _token_build(token)
    else:
        return download_get_state(token, uid)
Exemple #3
0
def download(url):
    uid = config.download_user
    csdn = config.download_csdn

    _condition = {'action': 'download', 'uid': uid, 'message.url': url,
                  '$nor': [{'state': 'fail'}, {'state': 'done'}]}
    if db.act.find_one(_condition) is not None:
        return False, '正在下载,请勿重复提交。'

    token = _gen_token('qq_download')
    db.act_create(token, uid, 'download', 'request', {'csdn': csdn, 'url': url})
    return True, token
Exemple #4
0
def login(token, uid):
    if token == '':
        if uid == '':
            return _error_uid_empty()

        _condition = {'action': 'login', 'uid': uid,
                      '$nor': [{'state': 'fail'}, {'state': 'done'}]}
        _act = db.act.find_one(_condition)
        if _act is not None:
            print(f'恢复之前的请求 {uid}')
            return _token_build(_act['id'])

        token = _gen_token('login')
        db.act_create(token, uid, 'login', 'request')
        return _token_build(token)
    else:
        return login_get_state(token, uid)
Exemple #5
0
def login_verify_set(token, uid, code):
    if token == '':
        return _error_token_empty()
    if uid == '':
        return _error_uid_empty()
    if code == '':
        return _error_xxx_empty('code')

    act = db.act.find_one({'id': token, 'uid': uid})
    if act is None:
        return _error_token_not_exist()
    if act['state'].startswith('verify_set'):
        combine_token = f'{token}_verify_set_{_gen_token()}'
        act = db.act.find_one({'id': combine_token, 'uid': uid})
        if act is None:
            db.act_create(combine_token, uid, 'login_verify_set', 'request', code)
            return _success_build()
    return _error_state_wrong(act['state'], 'verify_set')
Exemple #6
0
def fake_add_request(uid, csdn):
    _id = f'update_{uuid.uuid4()}_auto'
    db.act_create(_id, uid, 'update', 'request', csdn)