예제 #1
0
def api_aboutus():
    if request.method == 'POST':
        if request.is_json is False:
            # 要求Content-Type为:application/json
            return jsonify({"code": "fail", "error": "content type error!"})
        request_js = request.json
        for f in ["appid", "editer", "content"]:
            if f not in request_js:
                return jsonify({"code": "fail", "error": "data error!"})
        desc = request_js.get("desc", "")
        session = db_manager.master()
        try:
            aboutus = session.query(AboutUs).filter(
                AboutUs.appid == request_js['appid']).one()
            aboutus.appid = request_js['appid']
            aboutus.desc = desc
            aboutus.editer = request_js['editer']
            aboutus.content = request_js['content']
        except MultipleResultsFound:
            return jsonify({"code": "fail", "error": "appid fount many"})
        except NoResultFound:
            aboutus = AboutUs(
                appid=request_js['appid'],
                desc=desc,
                editer=request_js['editer'],
                content=request_js['content'],
            )
        except Exception as e:
            return jsonify({"code": "fail", "error": f"{e}"})
        session.add(aboutus)
        session.commit()
        session.close()
        return jsonify({"code": "success"})
    elif request.method == "GET":
        appid = request.args.get('appid', None)
        if appid is None:
            return jsonify({"code": "fail", "error": "data error!"})
        session = db_manager.slave()
        try:
            aboutus = session.query(AboutUs).filter(
                AboutUs.appid == appid).one()
            session.close()
        except MultipleResultsFound:
            return jsonify({"code": "fail", "error": "appid fount many"})
        except NoResultFound:
            return jsonify({"code": "fail", "error": "appid no found"})
        except Exception as e:
            return jsonify({"code": "fail", "error": f"{e}"})
        return jsonify({
            "appid": aboutus.appid,
            "desc": aboutus.desc,
            "editer": aboutus.editer,
            "edit_time": aboutus.edit_time,
            "content": aboutus.content,
        })
    else:
        return jsonify({"code": "fail", "error": "method no support!"})
예제 #2
0
파일: api.py 프로젝트: ihyf/wallt_Backstage
def get_newest_protocol(*args, **kwargs):
    # 协议
    try:
        session = db_manager.slave()
        p_list = session.query(Protocol).order_by(-Protocol.edit_time).all()
        data = [{"id": p.protocol_id, "protocol_name": p.protocol_name, "protocol_content": p.protocol_content,
                 "edit_time": p.edit_time.strftime("%Y-%m-%d %H:%M:%S")} for p in p_list]
        return {"data": data}
    except Exception as e:
        return {"code": "fail", "error": f"{e}"}
예제 #3
0
파일: api.py 프로젝트: ihyf/wallt_Backstage
def get_newest_help_information(*args, **kwargs):
    # 帮助
    page = kwargs.get("page", None)
    limit = kwargs.get("limit", None)
    try:
        page = int(page) - 1
        limit = int(limit)
        session = db_manager.slave()
        h_list = session.query(HelpInformation).order_by(-HelpInformation.edit_time)[page*limit:(page+1)*limit]
        data = [{"id": h.hi_id, "question": h.question, "answer": h.answer,
                 "edit_time": h.edit_time.strftime("%Y-%m-%d %H:%M:%S")} for h in h_list]
        return {"data": data}
    except Exception as e:
        return {"code": "fail", "error": f"{e}"}
def get_help_information():
    if request.method == "GET":
        try:
            start = int(request.args.get("start", "0"))
            limit = int(request.args.get("limit", "15"))
            pageIndex = int(request.args.get("pageIndex", "15"))
            session = db_manager.slave()
            h_list = session.query(HelpInformation).order_by(-HelpInformation.edit_time)[pageIndex * limit:(pageIndex + 1) * limit]
            count = session.query(HelpInformation).distinct().count()
            data = [{"id": h.hi_id, "question": h.question, "answer": h.answer,
                     "edit_time": h.edit_time.strftime("%Y-%m-%d %H:%M:%S")} for h in h_list]
            return jsonify({"rows": data, "results": count})
        except Exception as e:
            return jsonify({"code": f"{e}"})
예제 #5
0
파일: api.py 프로젝트: ihyf/wallt_Backstage
def get_newest_message(*args, **kwargs):
    # 消息
    page = kwargs.get("page", None)
    limit = kwargs.get("limit", None)
    try:
        page = int(page) - 1
        limit = int(limit)
        session = db_manager.slave()
        msg_list = session.query(Message).order_by(-Message.edit_time)[page*limit:(page+1)*limit]
        data = [{"id": m.id, "msg_name": m.msg_name, "msg_content": m.msg_content,
                 "edit_time": m.edit_time.strftime("%Y-%m-%d %H:%M:%S")} for m in msg_list]
        print(data)
        return {"data": data}
    except Exception as e:
        return {"code": "fail", "error": f"{e}"}
예제 #6
0
def get_keys(appid):
    checkout_keys = "checkout_{0}_keys".format(appid)
    checkout_ns = "checkout_{0}_ns".format(appid)
    checkout_ip = "checkout_{0}_ip".format(appid)
    checkout_srv = "checkout_{0}_srv".format(appid)
    checkout_update = "checkout_{0}_update".format(appid)
    res_kes = {
        "keys": None,
        "ns": None,
        "ip": None,
        "srv": None
    }
    if redis_store.exists(checkout_keys) == 0:
        session = db_manager.slave()
        try:
            app = session.query(Apps).filter(Apps.appid == appid).one()
            session.close()
        except MultipleResultsFound:
            return False, {"code": "fail", "error": "appid fount many"}
        except NoResultFound:
            return False, {"code": "fail", "error": "appid no found"}
        except Exception as e:
            return False, {"code": "fail", "error": f"{e}"}
        res_kes["keys"] = [
                app.cli_publickey,
                app.cli_privatekey,
                app.srv_publickey,
                app.srv_privatekey,
        ]
        redis_store.delete(checkout_keys, checkout_ns, checkout_ip, checkout_srv)
        redis_store.rpush(checkout_keys, res_kes["keys"][0], res_kes["keys"][1], res_kes["keys"][2], res_kes["keys"][3])
        res_kes["ns"] = app.ns
        res_kes["ip"] = app.ip
        res_kes["srv"] = app.srv
        if res_kes["ns"]:
            redis_store.rpush(checkout_ns, *res_kes["ns"])
        if res_kes["ip"]:
            redis_store.rpush(checkout_ip, *res_kes["ip"])
        if res_kes["srv"]:
            redis_store.rpush(checkout_srv, *res_kes["srv"])
        redis_store.set(checkout_update, datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
    else:
        res_kes["keys"] = redis_store.lrange(checkout_keys, 0, 3)
        res_kes["ns"] = redis_store.lrange(checkout_ns, 0, -1)
        res_kes["ip"] = redis_store.lrange(checkout_ip, 0, -1)
        res_kes["srv"] = redis_store.lrange(checkout_srv, 0, -1)
    return True, res_kes
예제 #7
0
def api_apk():
    if request.method == "GET":
        if "ids[]" in request.args:
            ids = request.args.getlist("ids[]")
            session = db_manager.master()
            session.query(Apk).filter(
                Apk.id.in_(ids)).delete(synchronize_session=False)
            session.commit()
            session.close()
            return "ok"
        session = db_manager.slave()
        apks = session.query(Apk).order_by(
            Apk.id.desc())  # .slice(start, start + limit)
        start = int(request.args.get('start', 0))
        limit = int(request.args.get('limit', 10))
        pageindex = int(request.args.get('pageIndex', 0))
        response = {"rows": [], "results": apks.count()}
        for s in apks.slice(start, start + limit):
            row = {
                'id': s.id,
                'version_number': s.version_number,
                'version_name': s.version_name,
                'filename': s.filename,
                'description': s.description,
                'download_url': s.download_url,
                'apk_size': s.apk_size,
                'upload_time': s.upload_time.timestamp(),
            }
            response["rows"].append(row)
        return jsonify(response)
    elif request.method == "POST":
        if not request.is_json:
            return
        pjs = request.json
        session = db_manager.master()
        apk = Apk(
            version_number=pjs['version_number'],
            version_name=pjs['version_name'],
            filename=pjs['info']['filename'],
            description=pjs['description'],
            download_url=app.config['APK_DL_URL'] + pjs['info']['filename'],
            apk_size=pjs['info']['size'],
        )
        session.add(apk)
        session.commit()
        session.close()
        return jsonify({"result": "ok"})
예제 #8
0
def get_message():
    if request.method == "GET":
        try:
            start = int(request.args.get("start", "0"))
            limit = int(request.args.get("limit", "15"))
            pageIndex = int(request.args.get("pageIndex", "15"))
            session = db_manager.slave()
            msg_list = session.query(Message).order_by(
                -Message.edit_time)[pageIndex * limit:(pageIndex + 1) * limit]
            count = session.query(Message).distinct().count()
            data = [{
                "id": m.id,
                "msg_name": m.msg_name,
                "msg_content": m.msg_content,
                "edit_time": m.edit_time.strftime("%Y-%m-%d %H:%M:%S")
            } for m in msg_list]
            return jsonify({"rows": data, "results": count})
        except Exception as e:
            return jsonify({"code": f"{e}"})
예제 #9
0
def api_slideshow():
    if request.method == 'POST':
        if not request.is_json:
            return
        pjs = request.json
        session = db_manager.master()
        if 'isNew' in pjs:
            slideshow = SlideShow(slide_show_name=pjs['slide_show_name'],
                                  description=pjs['description'],
                                  images=pjs['pics'])
            session.add(slideshow)
            session.commit()
            session.close()
            return jsonify({"result": "ok"})
        else:
            try:
                slideshow = session.query(SlideShow).filter(
                    SlideShow.id == pjs['id']).one()
                if "containspics" in pjs and pjs['containspics'] == "yes":
                    slideshow.images = pjs['pics']
                slideshow.description = pjs['description']
                slideshow.slide_show_name = pjs['slide_show_name']
            except MultipleResultsFound:
                return jsonify({"result": "appid fount many"})
            except NoResultFound:
                slideshow = SlideShow(slide_show_name=pjs['slide_show_name'],
                                      description=pjs['description'],
                                      images=pjs['pics'])
                session.add(slideshow)
            except Exception as e:
                return jsonify({"result": f"{e}"})
            session.commit()
            session.close()
            return jsonify({"result": "ok"})
    elif request.method == 'GET':
        # http://localhost:7000/main/api/slideshow/?start=0&limit=30&pageIndex=0&_=1547524941956
        if "ids[]" in request.args:
            ids = request.args.getlist("ids[]")
            session = db_manager.master()
            session.query(SlideShow).filter(
                SlideShow.id.in_(ids)).delete(synchronize_session=False)
            session.commit()
            session.close()
            return "ok"
        else:
            session = db_manager.slave()
            slideshow = session.query(SlideShow).order_by(
                SlideShow.id.desc())  # .slice(start, start + limit)
            session.close()
            start = int(request.args.get('start', 0))
            limit = int(request.args.get('limit', 10))
            pageindex = int(request.args.get('pageIndex', 0))
            response = {"rows": [], "results": slideshow.count()}
            for s in slideshow.slice(start, start + limit):
                row = {
                    'id': s.id,
                    'slide_show_name': s.slide_show_name,
                    'description': s.description,
                    'edit_time': s.edit_time.timestamp(),
                    'images_num': len(s.images),
                    'images': s.images
                }
                response["rows"].append(row)
            return jsonify(response)