Commit 2c4823aa authored by Marcel's avatar Marcel
Browse files

Re-implement download capabilities.

parent 9ade6dc8
......@@ -13,39 +13,28 @@ class FSController(AbstractController):
@cherrypy.expose
@cherrypy.tools.allow(methods=['GET'])
def getfile(self, path, download=None, rnd=None):
try:
if not download or str(download).lower() not in ['true', '1', 'yes']:
download = False
else:
download = True
data, contenttype, isbrowserfile = self.handleDownload(str(path))
cherrypy.response.headers['Content-Type'] = contenttype
if download or not isbrowserfile:
cherrypy.response.headers[
'Content-Disposition'] = 'attachment; filename=%s' % path.split('/')[-1]
return data
except Exception, e:
cherrypy.session['error_data'] = {'status': 404,
'message': str(e), 'traceback': '', 'version': ''}
raise cherrypy.HTTPRedirect(
vispa.url.dynamic(os.path.join('error/filenotfound')))
def handleDownload(self, path):
self.get('fs')
if not fs.exists(path, 'file'):
def getfile(self, path, download=None):
if not download or str(download).lower() not in ['true', '1', 'yes']:
download = False
else:
download = True
data, contenttype, isbrowserfile = self.handleDownload(str(path), cherrypy.request.private_params.get('_wid', None))
cherrypy.response.headers['Content-Type'] = contenttype
if download or not isbrowserfile:
cherrypy.response.headers['Content-Disposition'] = 'attachment; filename=%s' % path.split('/')[-1]
return data
def handleDownload(self, path, wid):
fs = self.get('fs', 1)
if not fs.exists(path, 'f'):
raise Exception('The file \'%s\' does not exist' % path)
content = fs.get_file_content(path)
data = xmlrpclib.Binary(
content).data # TODO: remove xmlrpclib dependency
data = fs.get_file_content(path)
# get the content type depending on the file extension
ext = path.split('.')[-1]
mimetype = fs.get_mime_type(path)
if mimetype is None:
raise Exception(
'The file extension \'%s\' is not supported by this server' % ext)
raise Exception('The file extension \'%s\' is not supported by this server' % ext)
return data, mimetype, fs.is_browser_file(path)
......
......@@ -6,6 +6,7 @@ from vispa.controller import AbstractController
from vispa.controller.ajax import AjaxController
from vispa.controller.filesystem import FSController
from vispa.controller.bus import BusController
from vispa.controller.error import ErrorController
from vispa.models.user import User
from vispa.models.workspace import Workspace
from vispa.models.profile import Profile
......
......@@ -55,6 +55,7 @@ class FileSystem(object):
return False
def exists(self, path, type=None):
return True
# type may be 'f' or 'd'
if path:
path = os.path.expanduser(os.path.expandvars(path))
......@@ -111,7 +112,6 @@ class FileSystem(object):
else:
return data
def get_suggestions(self, path, length=1, append_hidden=True, encode_json=False):
suggestions = []
source, filter = None, None
......@@ -181,7 +181,6 @@ class FileSystem(object):
f.close()
except Exception as e:
raise Exception(str(e))
def rename_folder(self, path, name):
# file or folder
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment