def _catch_filemanager_methods(self, request_dict): if not request_dict['method'].startswith('filemanager_'): return None try: fm_method = request_dict['method'].replace('filemanager_', '') fm_request = {} params = [] if 'params' not in request_dict else request_dict[ 'params'] fm_request['params'] = { i[0]: i[1] for i in map(lambda p: p.split("=", 1), params) } fm_request['params']['mode'] = fm_method request_dict = { '_executed': time.time(), } except Exception as exc: lg.exc() return api.ERROR(exc.message) try: fm_result = api.filemanager(fm_request) if isinstance(fm_result, Deferred): fm_result.addCallback(self._convert_filemanager_response) else: fm_result = self._convert_filemanager_response(fm_result) except Exception as exc: lg.exc() fm_result = api.ERROR(exc.message) return fm_result
def filemanager_api_view(request): try: json_request = json.loads(request.body.decode('utf-8')) except: error_dict = { "result": { "success": False, "error": traceback.format_exc() } } json_context = json.dumps(error_dict).encode('utf-8') return HttpResponseBadRequest(json_context, content_type='application/json') # lg.out(4, 'filemanagerapp.filemanager_api_view request: %s' % json_request) mode = json_request['params']['mode'] params = json_request['params'] try: if mode == 'list': result = api.files_list(params['path']) if mode == 'listall': result = api.files_list('') elif mode == 'upload': filename = unicode(params['path']) import os local_path = os.path.abspath( os.path.join(os.path.expanduser('~'), filename)) api.file_create(filename) result = api.file_upload_start(local_path, filename) else: result = api.filemanager(json_request) except: return HttpResponseBadRequest(json_context, content_type='application/json') return HttpResponse(json.dumps(result), content_type='application/json')
def filemanager_api_view(request): try: json_request = json.loads(request.body.decode('utf-8')) except: error_dict = {"result": {"success": False, "error": traceback.format_exc()}} json_context = json.dumps( error_dict).encode('utf-8') return HttpResponseBadRequest( json_context, content_type='application/json') result = api.filemanager(json_request) return HttpResponse(json.dumps(result), content_type='application/json')
def jsonrpc_filemanager(self, json_request): return api.filemanager(json_request)