Extension on downloaded file is being dropped (#9)

* TrelloAttachment: support all file extensions

* Version set to 1.0.2
This commit is contained in:
Paul Campbell 2021-01-18 20:03:48 +00:00 committed by GitHub
parent ad2a9ab098
commit 5999c33994
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 8 deletions

View file

@ -12,7 +12,7 @@
</parent>
<artifactId>kemitix-trello</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<properties>
<tiles-maven-plugin.version>2.18</tiles-maven-plugin.version>

View file

@ -9,6 +9,7 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.channels.Channels;
import java.util.Optional;
import java.util.logging.Logger;
public class TrelloAttachment implements Attachment {
@ -17,7 +18,6 @@ public class TrelloAttachment implements Attachment {
Logger.getLogger(
TrelloAttachment.class.getName());
private static final String[] EXTENSIONS = new String[]{"doc", "docx", "odt"};
private final com.julienvey.trello.domain.Attachment attachment;
private final Card card;
private final AttachmentDirectory attachmentDirectory;
@ -51,12 +51,10 @@ public class TrelloAttachment implements Attachment {
private String extension() {
URI uri = URI.create(attachment.getUrl());
String path = uri.getPath();
for (String ex : EXTENSIONS) {
if (path.endsWith("." + ex)) {
return ex;
}
}
return "";
return Optional.ofNullable(path)
.filter(f -> f.contains("."))
.map(f -> f.substring(path.lastIndexOf(".") + 1))
.orElse("");
}
@Override

View file

@ -0,0 +1,30 @@
package net.kemitix.trello;
import com.julienvey.trello.domain.Attachment;
import com.julienvey.trello.domain.Card;
import org.assertj.core.api.WithAssertions;
import org.junit.jupiter.api.Test;
import java.io.File;
public class TrelloAttachmentTest
implements WithAssertions {
@Test
void regressionExtensionTruncated() {
//given
Attachment attachment = new Attachment();
attachment.setUrl("card-url.extension");
Card card = new Card();
card.setIdShort("123");
card.setName("card-name");
AttachmentDirectory dir = new AttachmentDirectoryImpl();
var trelloAttachment = TrelloAttachment.create(
attachment, card, dir
);
//when
File filename = trelloAttachment.getFilename();
//then
assertThat(filename.getName()).endsWith(".extension");
}
}