Ad js upload

This commit is contained in:
2026-01-08 13:11:30 +01:00
parent 7c9f47cb1f
commit 361c2b3ec6
8 changed files with 221 additions and 22 deletions

View File

@@ -34,7 +34,9 @@ public class AssetStorageService {
Map.entry("audio/wav", ".wav"),
Map.entry("audio/ogg", ".ogg"),
Map.entry("audio/webm", ".webm"),
Map.entry("audio/flac", ".flac")
Map.entry("audio/flac", ".flac"),
Map.entry("application/javascript", ".js"),
Map.entry("text/javascript", ".js")
);
private final Path assetRoot;

View File

@@ -155,8 +155,9 @@ public class ChannelDirectoryService {
.orElse("asset_" + System.currentTimeMillis());
boolean isAudio = optimized.mediaType().startsWith("audio/");
double defaultWidth = isAudio ? 400 : 640;
double defaultHeight = isAudio ? 80 : 360;
boolean isCode = isCodeMediaType(optimized.mediaType()) || isCodeMediaType(mediaType);
double defaultWidth = isAudio ? 400 : isCode ? 480 : 640;
double defaultHeight = isAudio ? 80 : isCode ? 270 : 360;
double width = optimized.width() > 0 ? optimized.width() : defaultWidth;
double height = optimized.height() > 0 ? optimized.height() : defaultHeight;
@@ -362,6 +363,14 @@ public class ChannelDirectoryService {
return value == null ? null : value.toLowerCase(Locale.ROOT);
}
private boolean isCodeMediaType(String mediaType) {
if (mediaType == null || mediaType.isBlank()) {
return false;
}
String normalized = mediaType.toLowerCase(Locale.ROOT);
return normalized.startsWith("application/javascript") || normalized.startsWith("text/javascript");
}
private String topicFor(String broadcaster) {
return "/topic/channel/" + broadcaster.toLowerCase(Locale.ROOT);
}

View File

@@ -26,7 +26,9 @@ public class MediaDetectionService {
Map.entry("mov", "video/quicktime"),
Map.entry("mp3", "audio/mpeg"),
Map.entry("wav", "audio/wav"),
Map.entry("ogg", "audio/ogg")
Map.entry("ogg", "audio/ogg"),
Map.entry("js", "application/javascript"),
Map.entry("mjs", "text/javascript")
);
private static final Set<String> ALLOWED_MEDIA_TYPES = Set.copyOf(EXTENSION_TYPES.values());

View File

@@ -72,6 +72,10 @@ public class MediaOptimizationService {
return new OptimizedAsset(bytes, mediaType, 0, 0, null);
}
if (mediaType.startsWith("application/javascript") || mediaType.startsWith("text/javascript")) {
return new OptimizedAsset(bytes, mediaType, 0, 0, null);
}
BufferedImage image = ImageIO.read(new ByteArrayInputStream(bytes));
if (image != null) {
return new OptimizedAsset(bytes, mediaType, image.getWidth(), image.getHeight(), null);