-
Notifications
You must be signed in to change notification settings - Fork 80
Fix #2276 #2294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix #2276 #2294
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c539b5b
Fix #2276
josenavas 6ad5e79
Factoring out generate nginx directory file list
josenavas 27acf31
Factoring out the nginx file list writing
josenavas 460998f
Factoring out generating the file list of an artifact
josenavas c3a27de
Factoring out the header setting
josenavas 92c5b05
Addressing @antgonza's comment
josenavas 32c0382
Addressing @wasade's comments
josenavas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,8 @@ | |
from .base_handlers import BaseHandler | ||
from qiita_pet.handlers.api_proxy import study_get_req | ||
from qiita_db.study import Study | ||
from qiita_db.util import filepath_id_to_rel_path, get_db_files_base_dir | ||
from qiita_db.util import (filepath_id_to_rel_path, get_db_files_base_dir, | ||
get_filepath_information) | ||
from qiita_db.meta_util import validate_filepath_access_by_user | ||
from qiita_db.metadata_template.sample_template import SampleTemplate | ||
from qiita_db.metadata_template.prep_template import PrepTemplate | ||
|
@@ -37,19 +38,42 @@ def get(self, filepath_id): | |
"filepath_id: %s" % (self.current_user.email, str(fid))) | ||
|
||
relpath = filepath_id_to_rel_path(fid) | ||
fp_info = get_filepath_information(fid) | ||
fname = basename(relpath) | ||
|
||
# If we don't have nginx, write a file that indicates this | ||
self.write("This installation of Qiita was not equipped with nginx, " | ||
"so it is incapable of serving files. The file you " | ||
"attempted to download is located at %s" % relpath) | ||
if fp_info['filepath_type'] in ('directory', 'html_summary_dir'): | ||
# This is a directory, we need to list all the files so NGINX | ||
# can download all of them | ||
basedir = get_db_files_base_dir() | ||
basedir_len = len(basedir) + 1 | ||
to_download = [] | ||
for dp, _, fps in walk(fp_info['fullpath']): | ||
for fn in fps: | ||
fullpath = join(dp, fn) | ||
spath = fullpath | ||
if fullpath.startswith(basedir): | ||
spath = fullpath[basedir_len:] | ||
to_download.append((fullpath, spath, spath)) | ||
|
||
all_files = '\n'.join( | ||
["- %s /protected/%s %s" % (getsize(fp), sfp, n) | ||
for fp, sfp, n in to_download]) | ||
|
||
self.set_header('X-Archive-Files', 'zip') | ||
self.write("%s\n" % all_files) | ||
fname = '%s.zip' % fname | ||
else: | ||
# If we don't have nginx, write a file that indicates this | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A lot of this code is copy pastes from other classes, would you mind creating a new class from which these functions are inherit? Perhaps use the BaseHandlerDownload handler ... |
||
self.write("This installation of Qiita was not equipped with " | ||
"nginx, so it is incapable of serving files. The file " | ||
"you attempted to download is located at %s" % relpath) | ||
self.set_header('Content-Type', 'application/octet-stream') | ||
self.set_header('Content-Transfer-Encoding', 'binary') | ||
self.set_header('X-Accel-Redirect', '/protected/' + relpath) | ||
|
||
self.set_header('Content-Description', 'File Transfer') | ||
self.set_header('Content-Type', 'application/octet-stream') | ||
self.set_header('Content-Transfer-Encoding', 'binary') | ||
self.set_header('Expires', '0') | ||
self.set_header('Cache-Control', 'no-cache') | ||
self.set_header('X-Accel-Redirect', '/protected/' + relpath) | ||
self.set_header('Content-Disposition', | ||
'attachment; filename=%s' % fname) | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is a nested function necessary? It looks like it only adds complexity here...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved it outside the function cause it is used in another function, to reduce code duplication.