This repository was archived by the owner on Jul 13, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
The uri io adapter should use the content-disposition filename #2210
Closed
Closed
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a890f98
The uri io adapter should use the content-disposition filename
netmask fe1197d
Fix style comments
netmask a13fa20
URI Adapter refactoring
netmask 3c5f9db
Fix comment styles
netmask 2bc3fbb
- Removed editor tracking file
netmask 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 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 |
---|---|---|
|
@@ -18,8 +18,11 @@ def download_content | |
end | ||
|
||
def cache_current_values | ||
@original_filename = @target.path.split("/").last | ||
extract_attachment_filename | ||
|
||
@original_filename ||= @target.path.split("/").last | ||
@original_filename ||= "index.html" | ||
|
||
self.original_filename = @original_filename.strip | ||
|
||
@content_type = @content.content_type if @content.respond_to?(:content_type) | ||
|
@@ -28,6 +31,13 @@ def cache_current_values | |
@size = @content.size | ||
end | ||
|
||
def extract_attachment_filename | ||
if @content.meta.has_key? "content-disposition" | ||
@original_filename = @content.meta["content-disposition"] | ||
.match(/filename="([^"]*)"/)[1] | ||
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. Place the . on the previous line, together with the method call receiver. |
||
end | ||
end | ||
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. While we are here we can refactor some code. Suggestion: def cache_current_values
self.content_type = content_type_from_content || "text/html"
self.original_filename =
filename_from_content_disposition ||
filename_from_path ||
default_filename
@size = @content.size
end
def content_type_from_content
if @content.respond_to?(:content_type)
@content.content_type
end
end
def filename_from_content_disposition
if @content.meta.has_key?("content-disposition")
@original_filename = @content.meta["content-disposition"]
.match(/filename="([^"]*)"/)[1]
end
end
def filename_from_path
@target.path.split("/").last
end
def default_filename
"index.html"
end 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. this looks much better 👍 |
||
|
||
def copy_to_tempfile(src) | ||
while data = src.read(16*1024) | ||
destination.write(data) | ||
|
This file contains 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 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.
Will
@content
always have themeta
method defined?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.
It should, the adapter uses the open uri module which always contains the meta hash