mdserver-web/web/thisdb/app.py

65 lines
2.0 KiB
Python
Raw Permalink Normal View History

2024-11-10 09:43:08 -05:00
# coding:utf-8
# ---------------------------------------------------------------------------------
# MW-Linux面板
# ---------------------------------------------------------------------------------
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved.
# ---------------------------------------------------------------------------------
# Author: midoks <midoks@163.com>
# ---------------------------------------------------------------------------------
import core.mw as mw
2024-11-10 11:48:54 -05:00
__FIELD = 'id,app_id,app_secret,white_list,status,add_time,update_time'
2024-11-10 09:43:08 -05:00
2024-11-10 11:48:54 -05:00
def addApp(app_id,app_secret,white_list):
2024-11-10 09:48:41 -05:00
now_time = mw.getDateFromNow()
2024-11-10 09:43:08 -05:00
add_data = {
'app_id': app_id,
'app_secret': app_secret,
'status': 1,
2024-11-10 11:48:54 -05:00
'white_list':white_list,
2024-11-10 09:43:08 -05:00
'add_time': now_time,
'update_time': now_time
}
return mw.M('app').insert(add_data)
2024-11-26 12:41:17 -05:00
def getAppList(page=1,size=10):
2024-11-10 09:48:41 -05:00
m = mw.M('app').field(__FIELD)
2024-11-10 09:43:08 -05:00
2024-11-10 09:48:41 -05:00
start = (int(page) - 1) * (int(size))
2024-11-10 09:43:08 -05:00
limit = str(start) + ',' +str(size)
2024-11-10 09:48:41 -05:00
app_list = m.limit(limit).order('id desc').select()
count = m.count()
2024-11-10 09:43:08 -05:00
2024-11-10 09:48:41 -05:00
data = {}
2024-11-10 09:43:08 -05:00
data['list'] = app_list
data['count'] = count
return data
def getAppById(aid):
2024-11-10 09:48:41 -05:00
return mw.M('app').field(__FIELD).where("id=?", (aid,)).find()
2024-11-10 09:43:08 -05:00
2024-12-03 10:26:15 -05:00
def getAppByAppId(app_id):
return mw.M('app').field(__FIELD).where("app_id=?", (app_id,)).find()
2024-11-10 09:43:08 -05:00
def deleteAppById(aid):
return mw.M('app').where("id=?", (aid,)).delete()
2024-11-11 10:48:44 -05:00
def toggleAppStatus(aid):
info = mw.M('app').field(__FIELD).where("id=?", (aid,)).find()
if info['status'] == 1:
return mw.M('app').where('id=?',(aid,)).update({'status':0})
return mw.M('app').where('id=?',(aid,)).update({'status':1})
2024-11-26 12:41:17 -05:00
def setAppData(aid, status=None, app_id=None, app_secret=None):
2024-11-10 09:43:08 -05:00
up_data = {}
if status is not None:
up_data['status'] = status
if app_id is not None:
up_data['app_id'] = app_id
if app_secret is not None:
up_data['app_secret'] = app_secret
return mw.M('app').where('id=?',(aid,)).update(up_data)