1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-01 23:38:37 +00:00

Add view raw file

This commit is contained in:
zhengxie 2015-11-12 12:13:33 +08:00
parent 623c4fb5f8
commit 4813a496ed
2 changed files with 28 additions and 0 deletions

View File

@ -394,6 +394,7 @@ def _file_view(request, repo_id, path):
return render_permission_error(request, _(u'Unable to view file'))
# Pass permission check, start download or render file.
if request.GET.get('dl', '0') == '1':
token = seafile_api.get_fileserver_access_token(repo_id, obj_id,
'download', username,
@ -403,6 +404,15 @@ def _file_view(request, repo_id, path):
send_file_access_msg(request, repo, path, 'web')
return HttpResponseRedirect(dl_url)
if request.GET.get('raw', '0') == '1':
token = seafile_api.get_fileserver_access_token(repo_id, obj_id,
'view', username,
use_onetime=True)
raw_url = gen_file_get_url(token, u_filename)
# send stats message
send_file_access_msg(request, repo, path, 'web')
return HttpResponseRedirect(raw_url)
# Get file view raw path, ``user_perm`` is not used anymore.
if filetype == VIDEO or filetype == AUDIO:
raw_path, inner_path, user_perm = get_file_view_path_and_perm(

View File

@ -227,3 +227,21 @@ class ViewLibFileTest(BaseTestCase):
resp = self.client.get(url)
self.assertEqual(302, resp.status_code)
assert '8082/files/' in resp.get('location')
resp = requests.request('GET', resp.get('location'))
cont_disp = resp.headers['content-disposition']
assert 'inline' not in cont_disp
assert 'attachment' in cont_disp
def test_can_view_raw(self):
self.login_as(self.user)
url = reverse('view_lib_file', args=[self.repo.id, self.file]) + '?raw=1'
resp = self.client.get(url)
self.assertEqual(302, resp.status_code)
assert '8082/files/' in resp.get('location')
resp = requests.request('GET', resp.get('location'))
cont_disp = resp.headers['content-disposition']
assert 'inline' in cont_disp
assert 'attachment' not in cont_disp