def get_list(): token = request.headers.get('token') user_id = user_id_by_token(token) data_list = search_data('list', {'user_id': user_id}, True) body = [] if data_list == None else data_list body = list(reversed(body)) return api_factory(body)
def icon(): icon_path = '../client/src/assets/icon/iconfont.css' with open('./el_icon.json', 'r', encoding='utf-8') as f: result = json.loads(f.read()) local_icon_json = {} if os.path.exists('./icon.json'): with open('./icon.json', 'r', encoding='utf-8') as f: local_icon_json = json.loads(f.read()) md5_value = local_icon_json['md5'] if md5_value == file_md5(icon_path): result = local_icon_json['list'] else: result.extend(parsing(icon_path)) write_file(icon_path, result) return api_factory(result) else: result.extend(parsing(icon_path)) write_file(icon_path, result) return api_factory(result)
def change_log(log_id): id_ = unquote(log_id) api_param = request.get_json() api_param = api_param if api_param != None else {} db_value = search_data('log', {'id': id_}) keys = db_value.keys() if isinstance(db_value, dict) else [] for key in keys: if key in api_param.keys(): db_value[key] = api_param[key] update_data('log', db_value, {'id': id_}) return api_factory({'msg': '修改成功'})
def login(): api_param = request.get_json() user = api_param.get('user') pwd = api_param.get('pwd') db_value = search_data('user', {'user': user}) if db_value == None or db_value['pwd'] != pwd: return err_factory('用户名或者密码错误', None, 403) else: token = rand_string() set_token(user, token) print('更新token', user, token) return api_factory(token)
def register(): api_param = request.get_json() user = api_param.get('user') pwd = api_param.get('pwd') db_value = search_data('user', {'user': user}) if db_value == None: insert_data('user', {'id': rand_string(), 'user': user, 'pwd': pwd}) token = rand_string() set_token(user, token) create_menu(user) return api_factory(token) else: return err_factory('该用户已存在', None, 403)
def add_log(list_id): token = request.headers.get('token') user_id = user_id_by_token(token) id_ = unquote(list_id) api_param = request.get_json() item = { 'list_id': id_, 'id': rand_string(), 'status': False, 'user_id': user_id, 'collection': False, 'content': api_param['text'] } insert_data('log', item) return api_factory(True)
def add_list(): token = request.headers.get('token') api_param = request.get_json() name = api_param['name'] type_ = api_param['type'] icon = api_param['icon'] user_id = user_id_by_token(token) insert_data('list', { 'user_id': user_id, 'name': name, 'id': rand_string(), 'type': type_, 'icon': icon }) return api_factory(True)
def upToken(): token = request.headers.get('token') next_token = rand_string() update_data('user', {'token': next_token}, {'token': token}) return api_factory(next_token)
def get_log(list_id): id_ = unquote(list_id) data = search_data('log', {'list_id': id_}, True) result = data if isinstance(data, list) else [] return api_factory(result)
def del_log(log_id): id_ = unquote(log_id) del_data('log', {'id': id_}) return api_factory({'msg': '删除成功'})
def del_list(list_id): id_ = unquote(list_id) del_data('list', {'id': id_}) del_data('log', {'list_id': id_}) return api_factory(True)