Fix layering and add release ci

This commit is contained in:
2026-01-15 14:36:45 +01:00
parent d43bd985c6
commit c481b105c5
12 changed files with 476 additions and 152 deletions

View File

@@ -126,7 +126,7 @@ public record AssetView(
script.getOriginalMediaType(),
asset.getAssetType(),
script.getAttachments(),
null,
script.getZIndex(),
null,
null,
null,

View File

@@ -33,6 +33,9 @@ public class ScriptAsset {
@Column(name = "source_file_id")
private String sourceFileId;
@Column(name = "z_index")
private Integer zIndex;
@Transient
private List<ScriptAssetAttachmentView> attachments = List.of();
@@ -49,6 +52,9 @@ public class ScriptAsset {
if (this.name == null || this.name.isBlank()) {
this.name = this.id;
}
if (this.zIndex == null || this.zIndex < 1) {
this.zIndex = 1;
}
}
public String getId() {
@@ -115,6 +121,14 @@ public class ScriptAsset {
this.sourceFileId = sourceFileId;
}
public Integer getZIndex() {
return zIndex == null ? 1 : Math.max(1, zIndex);
}
public void setZIndex(Integer zIndex) {
this.zIndex = zIndex == null ? null : Math.max(1, zIndex);
}
public List<ScriptAssetAttachmentView> getAttachments() {
return attachments == null ? List.of() : attachments;
}

View File

@@ -175,7 +175,7 @@ public class ChannelDirectoryService {
return asset == null ? null : AssetView.fromVisual(normalized, asset, visual);
})
.filter(Objects::nonNull)
.sorted(Comparator.comparingInt(AssetView::zIndex))
.sorted(Comparator.comparingInt(AssetView::zIndex).reversed())
.toList();
}
@@ -273,6 +273,7 @@ public class ChannelDirectoryService {
script.setMediaType(optimized.mediaType());
script.setOriginalMediaType(mediaType);
script.setSourceFileId(asset.getId());
script.setZIndex(nextScriptZIndex(channel.getBroadcaster()));
script.setAttachments(List.of());
scriptAssetRepository.save(script);
ScriptAssetFile sourceFile = new ScriptAssetFile(asset.getBroadcaster(), AssetType.SCRIPT);
@@ -333,6 +334,7 @@ public class ChannelDirectoryService {
script.setSourceFileId(sourceFile.getId());
script.setDescription(normalizeDescription(request.getDescription()));
script.setPublic(Boolean.TRUE.equals(request.getIsPublic()));
script.setZIndex(nextScriptZIndex(channel.getBroadcaster()));
script.setAttachments(List.of());
scriptAssetRepository.save(script);
AssetView view = AssetView.fromScript(channel.getBroadcaster(), asset, script);
@@ -711,6 +713,7 @@ public class ChannelDirectoryService {
script.setOriginalMediaType(sourceContent.mediaType());
script.setSourceFileId(sourceFile.getId());
script.setLogoFileId(sourceScript.getLogoFileId());
script.setZIndex(nextScriptZIndex(targetBroadcaster));
script.setAttachments(List.of());
scriptAssetRepository.save(script);
@@ -770,6 +773,7 @@ public class ChannelDirectoryService {
script.setMediaType(sourceContent.mediaType());
script.setOriginalMediaType(sourceContent.mediaType());
script.setSourceFileId(sourceFile.getId());
script.setZIndex(nextScriptZIndex(targetBroadcaster));
script.setAttachments(List.of());
scriptAssetRepository.save(script);
@@ -891,6 +895,34 @@ public class ChannelDirectoryService {
ScriptAsset script = scriptAssetRepository
.findById(asset.getId())
.orElseThrow(() -> new ResponseStatusException(BAD_REQUEST, "Asset is not a script"));
int beforeZIndex = script.getZIndex();
if (req.getZIndex() != null) {
if (req.getZIndex() < 1) {
throw new ResponseStatusException(BAD_REQUEST, "zIndex must be >= 1");
}
script.setZIndex(req.getZIndex());
scriptAssetRepository.save(script);
if (beforeZIndex != script.getZIndex()) {
AssetPatch patch = new AssetPatch(
asset.getId(),
null,
null,
null,
null,
null,
null,
null,
script.getZIndex(),
null,
null,
null,
null,
null,
null
);
messagingTemplate.convertAndSend(topicFor(broadcaster), AssetEvent.updated(broadcaster, patch));
}
}
script.setAttachments(loadScriptAttachments(normalized, asset.getId(), null));
return AssetView.fromScript(normalized, asset, script);
}
@@ -1377,9 +1409,9 @@ public class ChannelDirectoryService {
.map((asset) -> resolveAssetView(broadcaster, asset, visuals, audios, scripts, scriptAttachments))
.filter(Objects::nonNull)
.sorted(
Comparator.comparing((AssetView view) ->
view.zIndex() == null ? Integer.MAX_VALUE : view.zIndex()
).thenComparing(AssetView::createdAt, Comparator.nullsFirst(Comparator.naturalOrder()))
Comparator.comparingInt((AssetView view) -> view.zIndex() == null ? Integer.MIN_VALUE : view.zIndex())
.reversed()
.thenComparing(AssetView::createdAt, Comparator.nullsFirst(Comparator.naturalOrder()))
)
.toList();
}
@@ -1398,6 +1430,18 @@ public class ChannelDirectoryService {
);
}
private int nextScriptZIndex(String broadcaster) {
return (
scriptAssetRepository
.findByIdIn(assetsWithType(normalize(broadcaster), AssetType.SCRIPT))
.stream()
.mapToInt(ScriptAsset::getZIndex)
.max()
.orElse(0) +
1
);
}
private List<String> assetsWithType(String broadcaster, AssetType... types) {
Set<AssetType> typeSet = EnumSet.noneOf(AssetType.class);
typeSet.addAll(Arrays.asList(types));