class StorageHandlerV1(tornado.web.RequestHandler): def initialize(self): self.fdfs_client = FDFSUtils() self.res_status = dict() self.set_header('Access-Control-Allow-Origin', '*') self.set_header('Access-Control-Allow-Headers', 'X-Requested-With') self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS') self.set_header('Access-Control-Max-Age', 1000) self.set_header('Access-Control-Allow-Headers', '*') self.set_header('Content-type', 'application/json') @tornado.gen.coroutine @tornado.web.asynchronous def get(self, *args, **kwargs): try: fdfs_all_status, fdfs_all_info = self.fdfs_client.list_all_groups() if fdfs_all_info: all_info, all_group, group_detail = fdfs_all_info result = { "all_info": all_info, "all_group": all_group, "group_detail": group_detail } self.res_status['status'], self.res_status['result'] = 0, result else: raise FdfsExcept(fdfs_all_info) except FdfsExcept as error: logging.error(error.msg) self.res_status['status'], self.res_status['result'] = 1, error.msg except Exception as error: logging.error(str(error)) self.res_status['status'], self.res_status['result'] = 2, str(error) finally: self.write(json.dumps(self.res_status)) self.finish()
class IndexHandlerV1(tornado.web.RequestHandler): def initialize(self): self.fdfs_client = FDFSUtils() @tornado.gen.coroutine @tornado.web.asynchronous def get(self, *args, **kwargs): try: fdfs_all_status, fdfs_all_info = self.fdfs_client.list_all_groups() if fdfs_all_info: all_info, all_group, group_detail = fdfs_all_info self.render('index.html', all_info=all_info, all_group=all_group, group_detail=group_detail) else: pass except: pass finally: pass