Поправил обработку стикеров. И улучшил генерацию названий для файлов.
Some checks reported errors
continuous-integration/drone/push Build encountered an error

This commit is contained in:
Struchkov Mark 2023-11-27 15:37:06 +03:00
parent 1975bee405
commit 1d49b09c54
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6

View File

@ -156,7 +156,7 @@ public final class MessageMailConvert {
attachment.setFileSize(voice.getFileSize()); attachment.setFileSize(voice.getFileSize());
attachment.setMimeType(voice.getMimeType()); attachment.setMimeType(voice.getMimeType());
attachment.setDuration(Duration.ofSeconds(voice.getDuration())); attachment.setDuration(Duration.ofSeconds(voice.getDuration()));
attachment.setFileName(UUID.randomUUID().toString()); attachment.setFileName(generateFileName(voice.getMimeType()));
return Optional.of(attachment); return Optional.of(attachment);
} }
return Optional.empty(); return Optional.empty();
@ -170,11 +170,23 @@ public final class MessageMailConvert {
attachment.setAnimated(sticker.getIsAnimated()); attachment.setAnimated(sticker.getIsAnimated());
attachment.setVideo(sticker.getIsVideo()); attachment.setVideo(sticker.getIsVideo());
attachment.setFileName(UUID.randomUUID().toString()); attachment.setFileName(UUID.randomUUID().toString());
attachment.setEmoji(sticker.getEmoji());
return Optional.of(attachment); return Optional.of(attachment);
} }
return Optional.empty(); return Optional.empty();
} }
private static String generateFileName(String mimeType) {
final StringBuilder builder = new StringBuilder(UUID.randomUUID().toString());
switch (mimeType) {
case "audio/ogg" -> builder.append(".ogg");
case "image/png" -> builder.append(".png");
case "image/jpeg" -> builder.append(".jpeg");
default -> {}
}
return builder.toString();
}
private static Optional<VideoAttachment> convertVideo(Video video) { private static Optional<VideoAttachment> convertVideo(Video video) {
if (video != null) { if (video != null) {
final VideoAttachment attachment = new VideoAttachment(); final VideoAttachment attachment = new VideoAttachment();