Esempio n. 1
0
def publish():
    """Release resources

    Args:
        status: 1:add, 2:update, 3:delete(enabled=False)
    """
    data = copy.deepcopy(g.form.data)
    data['appkey'] = g.appkey
    username_wallet = get_wallet_name(data['author'])
    pay_password = data.pop('pay_password')
    data['currency'] = app.config['PUBLISH_CURRENCY']
    data['bid'] = app.config['PUBLISH_BID']
    data['claim_name'] = generate_appkey()

    metadata = dict(title=data['title'],
                    author=data['author'],
                    tag=data['tags'],
                    description=data['des'],
                    language=data['language'] or 'en',
                    license=data['license'],
                    licenseUrl=data['license_url'],
                    nsfw=False,
                    preview=data['preview'],
                    thumbnail=data['thumbnail'])
    try:
        server = get_jsonrpc_server()
        result = server.publish(username_wallet, pay_password,
                                data['claim_name'], metadata,
                                data['content_type'], data['udfs_hash'],
                                data['currency'], data['price'], data['bid'],
                                None, None, True)
        if result.get('errcode') != 0:
            return result
    except:
        app.logger.error(formatter_error(traceback.format_exc()))
        return return_result(20201)
    result = result.get('result')
    data['fee'] = float(result.get('fee', 0))
    data['claim_id'] = result.get('claim_id')
    data['txid'] = result.get('txid')
    data['nout'] = int(result.get('nout', 0))
    if len(data['txid']) != 64:
        return return_result(20201, result=result)
    data['status'] = 1
    data['tags'] = save_tag(data['tags'])
    content = Content(**data)
    db.session.add(content)
    data.pop('tags')
    history = ContentHistory(**data)
    db.session.add(history)
    db.session.commit()
    return return_result(result=dict(id=content.id, claim_id=content.claim_id))
Esempio n. 2
0
def delete():
    """Update published resources

    Args:
        status: 1:add, 2:update, 3:delete(DB: enabled=False; CHAIN:metadata['nsfw']=True)
    """

    content = Content.query.filter_by(id=g.form.id.data,
                                      appkey=g.appkey,
                                      enabled=True).first()
    if not content:
        return return_result(20007)

    metadata = dict(title=content.title,
                    author=content.author,
                    tag=[tag.name for tag in content.tags],
                    description=content.des,
                    language=content.language or 'en',
                    license=content.license,
                    licenseUrl=content.license_url,
                    nsfw=True,
                    preview=content.preview,
                    thumbnail=content.preview)
    try:
        server = get_jsonrpc_server()
        result = server.update_claim(
            get_wallet_name(content.author), g.form.pay_password.data,
            content.claim_name, content.claim_id, content.txid, content.nout,
            metadata, content.content_type, content.udfs_hash,
            content.currency, content.price, content.bid, None, None)
        if result.get('errcode') != 0:
            return result
    except:
        app.logger.error(formatter_error(traceback.format_exc()))
        return return_result(20208)

    result = result.get('result')
    content.txid = result.get('txid')
    content.nout = int(result.get('nout', 0))
    content.fee = float(result.get('fee', 0))
    content.status = 3
    content.enabled = False

    data = contenthistory_schema.dump(content).data
    data['appkey'] = g.appkey
    history = ContentHistory(**data)
    db.session.add(history)
    db.session.commit()
    return return_result(result=dict(num=1))
Esempio n. 3
0
def save_content_history(**kwargs):
    history = ContentHistory(**kwargs)
    db.session.add(history)
    return history
Esempio n. 4
0
def update():
    """Update published resources

    Args:
        status: 1:add, 2:update, 3:delete(enabled=False)
    """
    data = copy.deepcopy(g.form.data)
    _id = data.pop('id')
    pay_password = data.pop('pay_password')
    content = Content.query.filter_by(id=_id, appkey=g.appkey,
                                      enabled=True).first()
    if not content:
        return return_result(20007)
    content.currency = app.config['PUBLISH_CURRENCY']
    content.bid = app.config['PUBLISH_BID']

    for k, v in data.items():
        if k in ['id', 'pay_password']:
            continue
        if v:
            if k == 'tags':
                v = save_tag(v)
            setattr(content, k, v)

    metadata = dict(title=content.title,
                    author=content.author,
                    tag=[tag.name for tag in content.tags],
                    description=content.des,
                    language=content.language or 'en',
                    license=content.license,
                    licenseUrl=content.license_url,
                    nsfw=False,
                    preview=content.preview,
                    thumbnail=content.thumbnail)
    try:
        server = get_jsonrpc_server()
        result = server.update_claim(
            get_wallet_name(content.author), pay_password, content.claim_name,
            content.claim_id, content.txid, content.nout, metadata,
            content.content_type, content.udfs_hash, content.currency,
            content.price, content.bid, None, None)
        if result.get('errcode') != 0:
            return result
    except:
        app.logger.error(formatter_error(traceback.format_exc()))
        return return_result(20208)

    result = result.get('result')
    content.txid = result.get('txid')
    content.nout = int(result.get('nout', 0))
    content.fee = float(result.get('fee', 0))
    content.status = 2
    if len(content.txid) != 64:
        return return_result(20208, result=result)

    data = contenthistory_schema.dump(content).data
    data['appkey'] = g.appkey
    history = ContentHistory(**data)
    db.session.add(history)
    db.session.commit()
    return return_result(result=dict(id=content.id, claim_id=content.claim_id))