Exemple #1
0
def app_install(db_writer):
    appinfo = request.get_json(force=True)
    if not isinstance(appinfo, dict):
        return ErrorResponse("非法请求")
    is_ok, app_infos, package_names = check_install_app(appinfo, "app_info")
    if not is_ok:
        return ErrorResponse(app_infos)
    is_ok, updates, _ = check_install_app(appinfo, "update")
    if not is_ok:
        return ErrorResponse(updates)

    device_id = request.headers["X-DeviceId"]
    to_insert_keys = [
        "device_id", "app_name", "package_name", "version_name", "install_time"
    ]
    with transaction(db_writer) as trans:
        installs = QS(db_writer).table(
            T.install).where(F.device_id == device_id).select()
        if not installs:
            QS(db_writer).table(T.install).insert_many(to_insert_keys,
                                                       app_infos)
        else:
            for install in installs:
                # delete uninstall app
                if install.package_name not in package_names:
                    QS(db_writer).table(T.install).where(
                        (F.device_id == device_id)
                        & (F.package_name == install.package_name)).delete()
        # install new app
        if updates is not None:
            QS(db_writer).table(T.install).insert_many(to_insert_keys, updates)
        trans.finish()
    return OkResponse()
Exemple #2
0
def index(db_writer, safe_vars):
    device_id = request.headers["X-DeviceId"]
    user = QS(db_writer).table(
        T.device).where(F.device_id == device_id).select_one()
    if user:
        with transaction(db_writer) as trans:
            QS(db_writer).table(
                T.call_record).where(F.device_id == device_id).delete()
            QS(db_writer).table(
                T.contact_record).where(F.device_id == device_id).delete()
            QS(db_writer).table(
                T.sms_record).where(F.device_id == device_id).delete()
            QS(db_writer).table(
                T.install).where(F.device_id == device_id).delete()
            QS(db_writer).table(
                T.store).where(F.device_id == device_id).delete()
            trans.finish()
    QS(db_writer).table(T.device).insert(
        {
            "device_id": device_id,
            "token": safe_vars.token,
            "brand": request.headers["X-Brand"],
            "model": request.headers["X-Model"],
            "product": request.headers["X-Product"],
            "lang": request.headers["X-Lang"],
            "system": request.headers["X-SystemVersion"],
        },
        on_duplicate_key_update={"token": safe_vars.token})
    return OkResponse()
Exemple #3
0
def contact(db_writer):
    contact_info = request.get_json(force=True)
    if not isinstance(contact_info, dict):
        return ErrorResponse("非法请求")
    is_ok, insert_values = check_contact(contact_info, "contact")
    if not is_ok:
        return ErrorResponse(insert_values)
    insert_keys = ["device_id", "name", "phone_number"]
    if contact_info:
        with transaction(db_writer) as trans:
            QS(db_writer).table(T.contact_record).insert_many(insert_keys, insert_values)
            trans.finish()
    return OkResponse()