Skip to content

Commit

Permalink
Fix missing file extension for downloaded files. Fixes #5816 by falli…
Browse files Browse the repository at this point in the history
…ng back to PDF as default file type. (#5841)
  • Loading branch information
tobiasdiez authored and Siedlerchr committed Jan 18, 2020
1 parent 33241d5 commit 2612e22
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where the Medline fetcher was only working when JabRef was running from source. [#5645](https://github.com/JabRef/jabref/issues/5645)
- We fixed some visual issues in the dark theme. [#5764](https://github.com/JabRef/jabref/pull/5764) [#5753](https://github.com/JabRef/jabref/issues/5753)
- We fixed an issue where non-default previews didn't handle unicode characters. [#5779](https://github.com/JabRef/jabref/issues/5779)
- We fixed an issue where the ampersand character wasn't rendering correctly on previews.[#3840](https://github.com/JabRef/jabref/issues/3840)
- We fixed an issue where the ampersand character wasn't rendering correctly on previews. [#3840](https://github.com/JabRef/jabref/issues/3840)
- We fixed an issue where an erroneous "The library has been modified by another program" message was shown when saving. [#4877](https://github.com/JabRef/jabref/issues/4877)
- We fixed an issue where the file extension was missing after downloading a file (we now fall-back to pdf). [#5816](https://github.com/JabRef/jabref/issues/5816)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.jabref.gui.externalfiles.FileDownloadTask;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.externalfiletype.StandardExternalFileType;
import org.jabref.gui.filelist.LinkedFileEditDialogView;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.icon.JabRefIcon;
Expand Down Expand Up @@ -85,7 +86,7 @@ public LinkedFileViewModel(LinkedFile linkedFile,
this.taskExecutor = taskExecutor;
this.externalFileTypes = externalFileTypes;
this.xmpPreferences = xmpPreferences;

downloadOngoing.bind(downloadProgress.greaterThanOrEqualTo(0).and(downloadProgress.lessThan(1)));
canWriteXMPMetadata.setValue(!linkedFile.isOnlineLink() && linkedFile.getFileType().equalsIgnoreCase("pdf"));
}
Expand Down Expand Up @@ -397,7 +398,7 @@ public void download() {
}
try {
Optional<Path> targetDirectory = databaseContext.getFirstExistingFileDir(filePreferences);
if (!targetDirectory.isPresent()) {
if (targetDirectory.isEmpty()) {
dialogService.showErrorDialogAndWait(Localization.lang("Download file"), Localization.lang("File directory is not set or does not exist!"));
return;
}
Expand All @@ -420,7 +421,7 @@ public BackgroundTask<Path> prepareDownloadTask(Path targetDirectory, URLDownloa
BackgroundTask<Path> downloadTask = BackgroundTask
.wrap(() -> {
Optional<ExternalFileType> suggestedType = inferFileType(urlDownload);
String suggestedTypeName = suggestedType.map(ExternalFileType::getName).orElse("");
String suggestedTypeName = suggestedType.orElse(StandardExternalFileType.PDF).getName();
linkedFile.setFileType(suggestedTypeName);

String suggestedName = linkedFileHandler.getSuggestedFileName(suggestedTypeName);
Expand All @@ -435,7 +436,7 @@ private Optional<ExternalFileType> inferFileType(URLDownload urlDownload) {
Optional<ExternalFileType> suggestedType = inferFileTypeFromMimeType(urlDownload);

// If we did not find a file type from the MIME type, try based on extension:
if (!suggestedType.isPresent()) {
if (suggestedType.isEmpty()) {
suggestedType = inferFileTypeFromURL(urlDownload.getSource().toExternalForm());
}
return suggestedType;
Expand All @@ -454,7 +455,7 @@ private Optional<ExternalFileType> inferFileTypeFromMimeType(URLDownload urlDown

private Optional<ExternalFileType> inferFileTypeFromURL(String url) {
return URLUtil.getSuffix(url)
.flatMap(extension -> externalFileTypes.getExternalFileTypeByExt(extension));
.flatMap(externalFileTypes::getExternalFileTypeByExt);
}

public LinkedFile getFile() {
Expand Down

0 comments on commit 2612e22

Please sign in to comment.