changed store path for files

This commit is contained in:
Daniel Gultsch 2015-10-06 16:18:23 +02:00
parent 1d2a24c9c0
commit 32abc76689
1 changed files with 10 additions and 20 deletions

View File

@ -58,33 +58,23 @@ public class FileBackend {
} }
public DownloadableFile getFile(Message message, boolean decrypted) { public DownloadableFile getFile(Message message, boolean decrypted) {
String path = message.getRelativeFilePath();
String extension;
if (path != null && !path.isEmpty()) {
String[] parts = path.split("\\.");
extension = "."+parts[parts.length - 1];
} else {
if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_TEXT) {
extension = ".webp";
} else {
extension = "";
}
path = message.getUuid()+extension;
}
final boolean encrypted = !decrypted final boolean encrypted = !decrypted
&& (message.getEncryption() == Message.ENCRYPTION_PGP && (message.getEncryption() == Message.ENCRYPTION_PGP
|| message.getEncryption() == Message.ENCRYPTION_DECRYPTED); || message.getEncryption() == Message.ENCRYPTION_DECRYPTED);
if (encrypted) { if (encrypted) {
return new DownloadableFile(getConversationsFileDirectory()+message.getUuid()+extension+".pgp"); return new DownloadableFile(getConversationsFileDirectory()+message.getUuid()+".pgp");
} else { } else {
if (path.startsWith("/")) { String path = message.getRelativeFilePath();
if (path == null) {
path = message.getUuid();
} else if (path.startsWith("/")) {
return new DownloadableFile(path); return new DownloadableFile(path);
}
String mime = message.getMimeType();
if (mime != null && mime.startsWith("image")) {
return new DownloadableFile(getConversationsImageDirectory() + path);
} else { } else {
if (Arrays.asList(Transferable.VALID_IMAGE_EXTENSIONS).contains(extension)) { return new DownloadableFile(getConversationsFileDirectory() + path);
return new DownloadableFile(getConversationsFileDirectory() + path);
} else {
return new DownloadableFile(getConversationsImageDirectory() + path);
}
} }
} }
} }