Skip to content
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

Fix downloading pdf produces html as extension #4965

Merged
merged 5 commits into from
May 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public BackgroundTask<Path> prepareDownloadTask(Path targetDirectory, URLDownloa
String suggestedTypeName = suggestedType.map(ExternalFileType::getName).orElse("");
linkedFile.setFileType(suggestedTypeName);

String suggestedName = linkedFileHandler.getSuggestedFileName();
String suggestedName = linkedFileHandler.getSuggestedFileName(suggestedTypeName);
return targetDirectory.resolve(suggestedName);
})
.then(destination -> new FileDownloadTask(urlDownload.getSource(), destination))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ public void openBrowseDialog() {

public void setValues(LinkedFile linkedFile) {
description.set(linkedFile.getDescription());

Path linkPath = Paths.get(linkedFile.getLink());
link.set(relativize(linkPath));
link.setValue(linkedFile.getLink()); //Might be an URL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the relativize command is missing, right?
Maybe have something like if (linkedFile.isOnline()) link.setValue(...) else link.setValue(relativize(Paths.get(...)))?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The relativize command was creating an error, if the url is a string.
I also tested the rename functionality and it's fine, no need for the relativizere here I think

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The relativize is only for the display, and I would prefer to keep it.
I was proposing the if (linkedFile.isOnline()) check to see if the string is an url.


selectedExternalFileType.setValue(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.slf4j.LoggerFactory;

public class LinkedFileHandler {

private static final Logger LOGGER = LoggerFactory.getLogger(LinkedFileHandler.class);

private final BibDatabaseContext databaseContext;
Expand Down Expand Up @@ -84,7 +85,7 @@ public boolean renameToName(String targetFileName) throws IOException {

String expandedOldFilePath = oldFile.get().toString();
boolean pathsDifferOnlyByCase = newPath.toString().equalsIgnoreCase(expandedOldFilePath)
&& !newPath.toString().equals(expandedOldFilePath);
&& !newPath.toString().equals(expandedOldFilePath);

if (Files.exists(newPath) && !pathsDifferOnlyByCase) {
// We do not overwrite files
Expand Down Expand Up @@ -113,9 +114,14 @@ private String relativize(Path path) {
public String getSuggestedFileName() {
String oldFileName = fileEntry.getLink();

String extension = FileHelper.getFileExtension(oldFileName).orElse(fileEntry.getFileType());
return getSuggestedFileName(extension);
}

public String getSuggestedFileName(String extension) {
String targetFileName = FileUtil.createFileNameFromPattern(databaseContext.getDatabase(), entry, filePreferences.getFileNamePattern()).trim()
+ '.'
+ FileHelper.getFileExtension(oldFileName).orElse(fileEntry.getFileType());
+ '.'
+ extension;

// Only create valid file names
return FileUtil.getValidFileName(targetFileName);
Expand Down