Skip to content

Commit

Permalink
Remove download when html file
Browse files Browse the repository at this point in the history
Fixes #10149
  • Loading branch information
Siedlerchr committed Apr 20, 2024
1 parent 359dc32 commit d7c122a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import javax.net.ssl.HostnameVerifier;
Expand Down Expand Up @@ -93,7 +95,7 @@ public DownloadLinkedFileAction(BibDatabaseContext databaseContext,

@Override
public void execute() {
LOGGER.info("Downloading file from " + downloadUrl);
LOGGER.info("Downloading file from {}", downloadUrl);
if (downloadUrl.isEmpty() || !LinkedFile.isOnlineLink(downloadUrl)) {
throw new UnsupportedOperationException("In order to download the file, the url has to be an online link");
}
Expand Down Expand Up @@ -164,19 +166,22 @@ private void onSuccess(Path targetDirectory, Path destination) {
} else {
newLinkedFile.setSourceURL(linkedFile.getSourceUrl());
}
entry.replaceDownloadedFile(linkedFile.getLink(), newLinkedFile);
isHtml = newLinkedFile.getFileType().equals(StandardExternalFileType.URL.getName());
if (!isHtml) {
entry.replaceDownloadedFile(linkedFile.getLink(), newLinkedFile);
}
}

// Notify in bar when the file type is HTML.
if (isHtml) {
dialogService.notify(Localization.lang("Downloaded website as an HTML file."));
LOGGER.debug("Downloaded website {} as an HTML file at {}", linkedFile.getLink(), destination);
dialogService.notify(Localization.lang("Download was a HTML file. Not adding it."));
List<LinkedFile> newFiles = new ArrayList<>(entry.getFiles());
newFiles.remove(linkedFile);
entry.setFiles(newFiles);
}
}

private void onFailure(URLDownload urlDownload, Exception ex) {
LOGGER.error("Error downloading from URL: " + urlDownload, ex);
LOGGER.error("Error downloading from URL: {}", urlDownload, ex);
String fetcherExceptionMessage = ex.getMessage();
String failedTitle = Localization.lang("Failed to download from URL");
int statusCode;
Expand Down Expand Up @@ -261,7 +266,7 @@ private Optional<ExternalFileType> inferFileTypeFromMimeType(URLDownload urlDown
String mimeType = urlDownload.getMimeType();

if (mimeType != null) {
LOGGER.debug("MIME Type suggested: " + mimeType);
LOGGER.debug("MIME Type suggested: {}", mimeType);
return ExternalFileTypes.getExternalFileTypeByMimeType(mimeType, filePreferences);
} else {
return Optional.empty();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ Donate\ to\ JabRef=Donate to JabRef

Download\ file=Download file

Downloaded\ website\ as\ an\ HTML\ file.=Downloaded website as an HTML file.
Download\ was\ a\ HTML\ file.\ Not\ adding\ it.=Download was a HTML file. Not adding it.

duplicate\ removal=duplicate removal

Expand Down

0 comments on commit d7c122a

Please sign in to comment.