mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 03:39:26 +00:00
Fix audio assets
This commit is contained in:
@@ -3,6 +3,7 @@ package com.imgfloat.app.controller;
|
||||
import com.imgfloat.app.model.AdminRequest;
|
||||
import com.imgfloat.app.model.AssetView;
|
||||
import com.imgfloat.app.model.CanvasSettingsRequest;
|
||||
import com.imgfloat.app.model.PlaybackRequest;
|
||||
import com.imgfloat.app.model.TransformRequest;
|
||||
import com.imgfloat.app.model.TwitchUserProfile;
|
||||
import com.imgfloat.app.model.VisibilityRequest;
|
||||
@@ -175,6 +176,18 @@ public class ChannelApiController {
|
||||
});
|
||||
}
|
||||
|
||||
@PostMapping("/assets/{assetId}/play")
|
||||
public ResponseEntity<AssetView> play(@PathVariable("broadcaster") String broadcaster,
|
||||
@PathVariable("assetId") String assetId,
|
||||
@RequestBody(required = false) PlaybackRequest request,
|
||||
OAuth2AuthenticationToken authentication) {
|
||||
String login = TwitchUser.from(authentication).login();
|
||||
ensureAuthorized(broadcaster, login);
|
||||
return channelDirectoryService.triggerPlayback(broadcaster, assetId, request)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElseThrow(() -> new ResponseStatusException(NOT_FOUND, "Asset not found"));
|
||||
}
|
||||
|
||||
@PutMapping("/assets/{assetId}/visibility")
|
||||
public ResponseEntity<AssetView> visibility(@PathVariable("broadcaster") String broadcaster,
|
||||
@PathVariable("assetId") String assetId,
|
||||
|
||||
@@ -5,6 +5,7 @@ public class AssetEvent {
|
||||
CREATED,
|
||||
UPDATED,
|
||||
VISIBILITY,
|
||||
PLAY,
|
||||
DELETED
|
||||
}
|
||||
|
||||
@@ -12,6 +13,7 @@ public class AssetEvent {
|
||||
private String channel;
|
||||
private AssetView payload;
|
||||
private String assetId;
|
||||
private Boolean play;
|
||||
|
||||
public static AssetEvent created(String channel, AssetView asset) {
|
||||
AssetEvent event = new AssetEvent();
|
||||
@@ -22,6 +24,16 @@ public class AssetEvent {
|
||||
return event;
|
||||
}
|
||||
|
||||
public static AssetEvent play(String channel, AssetView asset, boolean play) {
|
||||
AssetEvent event = new AssetEvent();
|
||||
event.type = Type.PLAY;
|
||||
event.channel = channel;
|
||||
event.payload = asset;
|
||||
event.assetId = asset.id();
|
||||
event.play = play;
|
||||
return event;
|
||||
}
|
||||
|
||||
public static AssetEvent updated(String channel, AssetView asset) {
|
||||
AssetEvent event = new AssetEvent();
|
||||
event.type = Type.UPDATED;
|
||||
@@ -63,4 +75,8 @@ public class AssetEvent {
|
||||
public String getAssetId() {
|
||||
return assetId;
|
||||
}
|
||||
|
||||
public Boolean getPlay() {
|
||||
return play;
|
||||
}
|
||||
}
|
||||
|
||||
13
src/main/java/com/imgfloat/app/model/PlaybackRequest.java
Normal file
13
src/main/java/com/imgfloat/app/model/PlaybackRequest.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.imgfloat.app.model;
|
||||
|
||||
public class PlaybackRequest {
|
||||
private Boolean play;
|
||||
|
||||
public Boolean getPlay() {
|
||||
return play == null ? Boolean.TRUE : play;
|
||||
}
|
||||
|
||||
public void setPlay(Boolean play) {
|
||||
this.play = play;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.imgfloat.app.model.AssetEvent;
|
||||
import com.imgfloat.app.model.Channel;
|
||||
import com.imgfloat.app.model.AssetView;
|
||||
import com.imgfloat.app.model.CanvasSettingsRequest;
|
||||
import com.imgfloat.app.model.PlaybackRequest;
|
||||
import com.imgfloat.app.model.TransformRequest;
|
||||
import com.imgfloat.app.model.VisibilityRequest;
|
||||
import com.imgfloat.app.repository.AssetRepository;
|
||||
@@ -187,6 +188,18 @@ public class ChannelDirectoryService {
|
||||
});
|
||||
}
|
||||
|
||||
public Optional<AssetView> triggerPlayback(String broadcaster, String assetId, PlaybackRequest request) {
|
||||
String normalized = normalize(broadcaster);
|
||||
return assetRepository.findById(assetId)
|
||||
.filter(asset -> normalized.equals(asset.getBroadcaster()))
|
||||
.map(asset -> {
|
||||
AssetView view = AssetView.from(normalized, asset);
|
||||
boolean shouldPlay = request == null || request.getPlay();
|
||||
messagingTemplate.convertAndSend(topicFor(broadcaster), AssetEvent.play(broadcaster, view, shouldPlay));
|
||||
return view;
|
||||
});
|
||||
}
|
||||
|
||||
public Optional<AssetView> updateVisibility(String broadcaster, String assetId, VisibilityRequest request) {
|
||||
String normalized = normalize(broadcaster);
|
||||
return assetRepository.findById(assetId)
|
||||
|
||||
Reference in New Issue
Block a user