1
0

nightly commit

This commit is contained in:
2021-02-01 20:34:40 +08:00
parent 3de813304c
commit 9c5dda83d1
2 changed files with 40 additions and 24 deletions

View File

@@ -77,6 +77,7 @@ CREATE TABLE calendar(
## API ## API
所有API均为POST请求 所有API均为POST请求
理论上所有更新操作名字里有update的除去必要的鉴别字段外其余字段均为可选字段可选字段只需要提供至少一个即可。但一些可选字段只有1条的就没有可选字段。
### Common类 ### Common类
@@ -243,6 +244,8 @@ Calendar类下的为日历请求接口
返回参数新的lastChange用以更新本地缓存 返回参数新的lastChange用以更新本地缓存
除去tokenuuidtimezoneOffset和lastChange这4项用来鉴别的条目外其余的条目均为可选项提供则更新不提供则不更新。
#### add #### add
请求地址:`/api/calendar/add` 请求地址:`/api/calendar/add`
@@ -547,6 +550,8 @@ Admin类的操作不涉及任何客户端存储因此不需要lastChange来
返回参数一个bool表示是否修改成功 返回参数一个bool表示是否修改成功
除去tokenusername这2项用来鉴别的条目外其余的条目均为可选项提供则更新不提供则不更新。
#### delete #### delete
请求地址:`/api/admin/delete` 请求地址:`/api/admin/delete`

View File

@@ -72,29 +72,29 @@ def web_loginHandle():
@app.route('/api/common/salt', methods=['POST']) @app.route('/api/common/salt', methods=['POST'])
def api_common_saltHandle(): def api_common_saltHandle():
return SmartDbCaller(calendar_db.common_salt, return SmartDbCaller(calendar_db.common_salt,
(('username', str), )) (('username', str, False), ))
@app.route('/api/common/login', methods=['POST']) @app.route('/api/common/login', methods=['POST'])
def api_common_loginHandle(): def api_common_loginHandle():
return SmartDbCaller(calendar_db.common_login, return SmartDbCaller(calendar_db.common_login,
(('username', str), (('username', str, False),
('password', str))) ('password', str, False)))
@app.route('/api/common/webLogin', methods=['POST']) @app.route('/api/common/webLogin', methods=['POST'])
def api_common_webLoginHandle(): def api_common_webLoginHandle():
return SmartDbCaller(calendar_db.common_webLogin, return SmartDbCaller(calendar_db.common_webLogin,
(('username', str), (('username', str, False),
('password', str))) ('password', str, False)))
@app.route('/api/common/logout', methods=['POST']) @app.route('/api/common/logout', methods=['POST'])
def api_common_logoutHandle(): def api_common_logoutHandle():
return SmartDbCaller(calendar_db.common_logout, return SmartDbCaller(calendar_db.common_logout,
(('token', str), )) (('token', str, False), ))
@app.route('/api/common/tokenValid', methods=['POST']) @app.route('/api/common/tokenValid', methods=['POST'])
def api_common_tokenValidHandle(): def api_common_tokenValidHandle():
return SmartDbCaller(calendar_db.common_tokenValid, return SmartDbCaller(calendar_db.common_tokenValid,
(('token', str), )) (('token', str, False), ))
@app.route('/api/common/isAdmin', methods=['POST']) @app.route('/api/common/isAdmin', methods=['POST'])
def api_common_isAdminHandle(): def api_common_isAdminHandle():
@@ -180,38 +180,38 @@ def api_collection_getSharedHandle():
@app.route('/api/todo/getFull', methods=['POST']) @app.route('/api/todo/getFull', methods=['POST'])
def api_todo_getFullHandle(): def api_todo_getFullHandle():
return SmartDbCaller(calendar_db.todo_getFull, return SmartDbCaller(calendar_db.todo_getFull,
(('token', str), )) (('token', str, False), ))
@app.route('/api/todo/getList', methods=['POST']) @app.route('/api/todo/getList', methods=['POST'])
def api_todo_getListHandle(): def api_todo_getListHandle():
return SmartDbCaller(calendar_db.todo_getList, return SmartDbCaller(calendar_db.todo_getList,
(('token', str), )) (('token', str, False), ))
@app.route('/api/todo/getDetail', methods=['POST']) @app.route('/api/todo/getDetail', methods=['POST'])
def api_todo_getDetailHandle(): def api_todo_getDetailHandle():
return SmartDbCaller(calendar_db.todo_getDetail, return SmartDbCaller(calendar_db.todo_getDetail,
(('token', str), (('token', str, False),
('uuid', str))) ('uuid', str, False)))
@app.route('/api/todo/add', methods=['POST']) @app.route('/api/todo/add', methods=['POST'])
def api_todo_addHandle(): def api_todo_addHandle():
return SmartDbCaller(calendar_db.todo_add, return SmartDbCaller(calendar_db.todo_add,
(('token', str), )) (('token', str, False), ))
@app.route('/api/todo/update', methods=['POST']) @app.route('/api/todo/update', methods=['POST'])
def api_todo_updateHandle(): def api_todo_updateHandle():
return SmartDbCaller(calendar_db.todo_update, return SmartDbCaller(calendar_db.todo_update,
(('token', str), (('token', str, False),
('uuid', str), ('uuid', str, False),
('data', str), ('data', str, False),
('lastChange', str))) ('lastChange', str, False)))
@app.route('/api/todo/delete', methods=['POST']) @app.route('/api/todo/delete', methods=['POST'])
def api_todo_deleteHandle(): def api_todo_deleteHandle():
return SmartDbCaller(calendar_db.todo_delete, return SmartDbCaller(calendar_db.todo_delete,
(('token', str), (('token', str, False),
('uuid', str), ('uuid', str, False),
('lastChange', str))) ('lastChange', str, False)))
# ================================ admin # ================================ admin
@@ -253,14 +253,25 @@ def UpdateStaticResources():
def SmartDbCaller(dbMethod, paramTuple): def SmartDbCaller(dbMethod, paramTuple):
result = (False, 'Invalid parameter', None) result = (False, 'Invalid parameter', None)
optCount = 0
paramList = [] paramList = []
optParamDict = {}
# for each item, item[0] is field name. item[1] is type. item[2] is whether it is optional field
for item in paramTuple: for item in paramTuple:
cache = request.form.get(item[0], default=None, type=item[1]) cache = request.form.get(item[0], default=None, type=item[1])
if item[2]:
# optional param
if cache is not None:
optParamDict[item[0]] = cache
optCount += 1
else:
if cache is None: if cache is None:
break break
paramList.append(cache) paramList.append(cache)
else: else:
result = dbMethod(*paramList) # at least one opt param
if optCount == 0 or len(optParamDict) != 0:
result = dbMethod(*paramList, **optParamDict)
return ConstructResponseBody(result) return ConstructResponseBody(result)