async def post(self): room_name = self.get_argument("name", "") token = await self.session.get("token") res = await GChatRoomSDk.create_chat_room(token, room_name) if not res: self.finish(static_method.return_code(500, '创建失败')) return self.finish(static_method.return_code(100, "创建成功"))
async def post(self): roomid = self.get_argument("roomid", "") token = await self.session.get('token') res = await GChatRoomSDk.join_chat_room(roomid, token) logging.info(res) if res == 100: self.finish(static_method.return_code(100, '加入成功')) elif res == 200: self.finish(static_method.return_code(100, '你已经在房间了')) else: self.finish(static_method.return_code(500, '系统错误')) return
async def post(self): content = self.get_argument('c', '') title = self.get_argument('t', '') bid = self.get_argument('bid', '') if not title or not content: self.finish(static_method.return_code(500, "请填写完整信息")) return if bid: res = await BlogModel().modify_blog(bid, title, content) else: res = await BlogModel().write_blog(title, content) info = static_method.return_code(100, res) self.finish(info)
async def get(self): """取出一个资源""" blog_list = await BlogModel().get_blog_list() info = dict( blog_list=blog_list ) self.set_status(200, 'OK') self.finish(static_method.return_code(100, info))
async def post(self): username = self.get_argument('u', '') password = self.get_argument('p', '') isrember = self.get_argument('r', '') if not username or not password: self.finish(static_method.return_code(500, '请填写账号密码')) return if username == 'liudong' and password == '123kkk': if isrember: await self.session.set("useruuid", username, exp=86400*30) else: await self.session.set("useruuid", username) token, useruuid = await GChatRoomSDk.get_user_info(username) await self.session.set("uuid", useruuid) await self.session.set("token", token) self.finish(static_method.return_code(100, 'success')) return self.finish(static_method.return_code(500, '账号密码错误')) return
async def _upload(self): baseimg = self.get_argument('img','') basefile = [] if baseimg: baseimg = baseimg.split(',')[1] imgData = base64.b64decode(baseimg) basefile.append({"content_type":"image/png","filename":"base64.png","body":imgData}) file_metas = basefile if baseimg else self.request.files['file'] # 提取表单中‘name’为‘fileToUpload’的文件元数据 for f in file_metas: filetype = f['content_type'] # 获取后缀名 rawname = f['filename'] if rawname=='blob': _suffix = 'png' else: try: _suffix = rawname.split('.').pop() except: _suffix = None suffix = _suffix.lower() if _suffix else None if suffix not in ('png','jpg','jpeg','gif','doc','docx','xls','xlsx','pdf','ppt','pptx','txt'): self.finish(static_method.return_code(500, "type error")) return tf = tempfile.NamedTemporaryFile() tf.write(f['body']) tf.seek(0) orgfileuuid = static_method.get_file_mD5(tf) # 从数据库查询,是否已有这个文件 uuid = str(uuid4()) filename = uuid+ '.'+ suffix fileinfo = await SystemModel().get_file(orgfileuuid) # imgurl = "http://192.168.22.100:8000/static/image/blog/"+filename imgurl = IMG_URL_BASE+filename if fileinfo: # 已经存在这个文件了 tf.close() info = {'status':1, 'url':fileinfo['file_path']} return json.dumps(info) files = open(SAVE_FILE_PATH+filename, 'wb') # files = open('/home/toby/work/kenny/static/image/blog/'+filename, 'wb') files.write(f['body']) files.close() await SystemModel().save_file(orgfileuuid, imgurl) info = {'status':1, 'url':imgurl} return json.dumps(info)