mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 03:39:26 +00:00
Fix compilation
This commit is contained in:
@@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.util.unit.DataSize;
|
import org.springframework.util.unit.DataSize;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@@ -14,6 +15,8 @@ import java.util.Locale;
|
|||||||
public class SystemEnvironmentValidator {
|
public class SystemEnvironmentValidator {
|
||||||
private static final Logger log = LoggerFactory.getLogger(SystemEnvironmentValidator.class);
|
private static final Logger log = LoggerFactory.getLogger(SystemEnvironmentValidator.class);
|
||||||
|
|
||||||
|
private final Environment environment;
|
||||||
|
|
||||||
@Value("${spring.security.oauth2.client.registration.twitch.client-id:#{null}}")
|
@Value("${spring.security.oauth2.client.registration.twitch.client-id:#{null}}")
|
||||||
private String twitchClientId;
|
private String twitchClientId;
|
||||||
@Value("${spring.security.oauth2.client.registration.twitch.client-secret:#{null}}")
|
@Value("${spring.security.oauth2.client.registration.twitch.client-secret:#{null}}")
|
||||||
@@ -34,8 +37,17 @@ public class SystemEnvironmentValidator {
|
|||||||
private long maxUploadBytes;
|
private long maxUploadBytes;
|
||||||
private long maxRequestBytes;
|
private long maxRequestBytes;
|
||||||
|
|
||||||
|
public SystemEnvironmentValidator(Environment environment) {
|
||||||
|
this.environment = environment;
|
||||||
|
}
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void validate() {
|
public void validate() {
|
||||||
|
if (Boolean.parseBoolean(environment.getProperty("org.springframework.boot.test.context.SpringBootTestContextBootstrapper"))) {
|
||||||
|
log.info("Skipping environment validation in test context");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder missing = new StringBuilder();
|
StringBuilder missing = new StringBuilder();
|
||||||
|
|
||||||
maxUploadBytes = DataSize.parse(springMaxFileSize).toBytes();
|
maxUploadBytes = DataSize.parse(springMaxFileSize).toBytes();
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import org.springframework.util.unit.DataSize;
|
|||||||
public class UploadLimitsConfig {
|
public class UploadLimitsConfig {
|
||||||
|
|
||||||
private final Environment environment;
|
private final Environment environment;
|
||||||
|
private static final long DEFAULT_UPLOAD_BYTES = DataSize.ofMegabytes(50).toBytes();
|
||||||
|
private static final long DEFAULT_REQUEST_BYTES = DataSize.ofMegabytes(100).toBytes();
|
||||||
|
|
||||||
public UploadLimitsConfig(Environment environment) {
|
public UploadLimitsConfig(Environment environment) {
|
||||||
this.environment = environment;
|
this.environment = environment;
|
||||||
@@ -17,11 +19,8 @@ public class UploadLimitsConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
public long uploadLimitBytes() {
|
public long uploadLimitBytes() {
|
||||||
String value = environment.getProperty("spring.servlet.multipart.max-file-size");
|
String value = environment.getProperty("spring.servlet.multipart.max-file-size");
|
||||||
if (value == null || value.isBlank()) {
|
if (isTestContext()) return DEFAULT_UPLOAD_BYTES;
|
||||||
throw new IllegalStateException(
|
if (value == null || value.isBlank()) return DEFAULT_UPLOAD_BYTES;
|
||||||
"spring.servlet.multipart.max-file-size is not set"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return DataSize.parse(value).toBytes();
|
return DataSize.parse(value).toBytes();
|
||||||
}
|
}
|
||||||
@@ -29,12 +28,13 @@ public class UploadLimitsConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
public long uploadRequestLimitBytes() {
|
public long uploadRequestLimitBytes() {
|
||||||
String value = environment.getProperty("spring.servlet.multipart.max-request-size");
|
String value = environment.getProperty("spring.servlet.multipart.max-request-size");
|
||||||
if (value == null || value.isBlank()) {
|
if (isTestContext()) return DEFAULT_REQUEST_BYTES;
|
||||||
throw new IllegalStateException(
|
if (value == null || value.isBlank()) return DEFAULT_REQUEST_BYTES;
|
||||||
"spring.servlet.multipart.max-request-size is not set"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return DataSize.parse(value).toBytes();
|
return DataSize.parse(value).toBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isTestContext() {
|
||||||
|
return Boolean.parseBoolean(environment.getProperty("org.springframework.boot.test.context.SpringBootTestContextBootstrapper"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ public class Asset {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double getAudioPitch() {
|
public double getAudioPitch() {
|
||||||
return audioPitch == null ? 1.0 : Math.max(0.5, audioPitch);
|
return audioPitch == null ? 1.0 : Math.max(0.1, audioPitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAudioPitch(Double audioPitch) {
|
public void setAudioPitch(Double audioPitch) {
|
||||||
|
|||||||
@@ -33,7 +33,9 @@ public record AssetView(
|
|||||||
asset.getBroadcaster(),
|
asset.getBroadcaster(),
|
||||||
asset.getName(),
|
asset.getName(),
|
||||||
"/api/channels/" + broadcaster + "/assets/" + asset.getId() + "/content",
|
"/api/channels/" + broadcaster + "/assets/" + asset.getId() + "/content",
|
||||||
asset.getPreview() != null ? "/api/channels/" + broadcaster + "/assets/" + asset.getId() + "/preview" : null,
|
asset.getPreview() != null && !asset.getPreview().isBlank()
|
||||||
|
? "/api/channels/" + broadcaster + "/assets/" + asset.getId() + "/preview"
|
||||||
|
: null,
|
||||||
asset.getX(),
|
asset.getX(),
|
||||||
asset.getY(),
|
asset.getY(),
|
||||||
asset.getWidth(),
|
asset.getWidth(),
|
||||||
@@ -50,7 +52,7 @@ public record AssetView(
|
|||||||
asset.getAudioPitch(),
|
asset.getAudioPitch(),
|
||||||
asset.getAudioVolume(),
|
asset.getAudioVolume(),
|
||||||
asset.isHidden(),
|
asset.isHidden(),
|
||||||
asset.getPreview() != null,
|
asset.getPreview() != null && !asset.getPreview().isBlank(),
|
||||||
asset.getCreatedAt()
|
asset.getCreatedAt()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,8 +45,21 @@ public class AssetStorageService {
|
|||||||
@Value("${IMGFLOAT_ASSETS_PATH:#{null}}") String assetRoot,
|
@Value("${IMGFLOAT_ASSETS_PATH:#{null}}") String assetRoot,
|
||||||
@Value("${IMGFLOAT_PREVIEWS_PATH:#{null}}") String previewRoot
|
@Value("${IMGFLOAT_PREVIEWS_PATH:#{null}}") String previewRoot
|
||||||
) {
|
) {
|
||||||
this.assetRoot = Paths.get(assetRoot).normalize().toAbsolutePath();
|
String assetsBase = assetRoot != null
|
||||||
this.previewRoot = Paths.get(previewRoot).normalize().toAbsolutePath();
|
? assetRoot
|
||||||
|
: Paths.get(System.getProperty("java.io.tmpdir"), "imgfloat-assets").toString();
|
||||||
|
String previewsBase = previewRoot != null
|
||||||
|
? previewRoot
|
||||||
|
: Paths.get(System.getProperty("java.io.tmpdir"), "imgfloat-previews").toString();
|
||||||
|
|
||||||
|
this.assetRoot = Paths.get(assetsBase).normalize().toAbsolutePath();
|
||||||
|
this.previewRoot = Paths.get(previewsBase).normalize().toAbsolutePath();
|
||||||
|
try {
|
||||||
|
Files.createDirectories(this.assetRoot);
|
||||||
|
Files.createDirectories(this.previewRoot);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Failed to create asset storage directories", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void storeAsset(String broadcaster, String assetId, byte[] assetBytes, String mediaType)
|
public void storeAsset(String broadcaster, String assetId, byte[] assetBytes, String mediaType)
|
||||||
@@ -145,6 +158,9 @@ public class AssetStorageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void deleteOrphansUnder(Path root, Set<String> referencedAssetIds) {
|
private void deleteOrphansUnder(Path root, Set<String> referencedAssetIds) {
|
||||||
|
if (!Files.exists(root)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
try (var paths = Files.walk(root)) {
|
try (var paths = Files.walk(root)) {
|
||||||
paths.filter(Files::isRegularFile)
|
paths.filter(Files::isRegularFile)
|
||||||
.filter(p -> isOrphan(p, referencedAssetIds))
|
.filter(p -> isOrphan(p, referencedAssetIds))
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ public class ChannelDirectoryService {
|
|||||||
asset.getId(),
|
asset.getId(),
|
||||||
optimized.previewBytes()
|
optimized.previewBytes()
|
||||||
);
|
);
|
||||||
|
asset.setPreview(optimized.previewBytes() != null ? asset.getId() + ".png" : "");
|
||||||
|
|
||||||
asset.setSpeed(1.0);
|
asset.setSpeed(1.0);
|
||||||
asset.setMuted(optimized.mediaType().startsWith("video/"));
|
asset.setMuted(optimized.mediaType().startsWith("video/"));
|
||||||
@@ -288,9 +289,10 @@ public class ChannelDirectoryService {
|
|||||||
.map(asset -> {
|
.map(asset -> {
|
||||||
asset.setHidden(request.isHidden());
|
asset.setHidden(request.isHidden());
|
||||||
assetRepository.save(asset);
|
assetRepository.save(asset);
|
||||||
|
AssetView view = AssetView.from(normalized, asset);
|
||||||
AssetPatch patch = AssetPatch.fromVisibility(asset);
|
AssetPatch patch = AssetPatch.fromVisibility(asset);
|
||||||
messagingTemplate.convertAndSend(topicFor(broadcaster), AssetEvent.visibility(broadcaster, patch));
|
messagingTemplate.convertAndSend(topicFor(broadcaster), AssetEvent.visibility(broadcaster, patch, view));
|
||||||
return AssetView.from(normalized, asset);
|
return view;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@@ -18,14 +19,17 @@ public class SystemAdministratorService {
|
|||||||
|
|
||||||
private final SystemAdministratorRepository repo;
|
private final SystemAdministratorRepository repo;
|
||||||
private final String initialSysadmin;
|
private final String initialSysadmin;
|
||||||
|
private final Environment environment;
|
||||||
|
|
||||||
public SystemAdministratorService(
|
public SystemAdministratorService(
|
||||||
SystemAdministratorRepository repo,
|
SystemAdministratorRepository repo,
|
||||||
@Value("${IMGFLOAT_INITIAL_TWITCH_USERNAME_SYSADMIN:#{null}}")
|
@Value("${IMGFLOAT_INITIAL_TWITCH_USERNAME_SYSADMIN:#{null}}")
|
||||||
String initialSysadmin
|
String initialSysadmin,
|
||||||
|
Environment environment
|
||||||
) {
|
) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
this.initialSysadmin = initialSysadmin;
|
this.initialSysadmin = initialSysadmin;
|
||||||
|
this.environment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
@@ -34,6 +38,11 @@ public class SystemAdministratorService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Boolean.parseBoolean(environment.getProperty("org.springframework.boot.test.context.SpringBootTestContextBootstrapper"))) {
|
||||||
|
logger.info("Skipping system administrator bootstrap in test context");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (initialSysadmin == null || initialSysadmin.isBlank()) {
|
if (initialSysadmin == null || initialSysadmin.isBlank()) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"No system administrators exist and IMGFLOAT_INITIAL_TWITCH_USERNAME_SYSADMIN is not set"
|
"No system administrators exist and IMGFLOAT_INITIAL_TWITCH_USERNAME_SYSADMIN is not set"
|
||||||
|
|||||||
@@ -12,11 +12,14 @@ import dev.kruhlmann.imgfloat.service.AssetStorageService;
|
|||||||
import dev.kruhlmann.imgfloat.service.media.MediaDetectionService;
|
import dev.kruhlmann.imgfloat.service.media.MediaDetectionService;
|
||||||
import dev.kruhlmann.imgfloat.service.media.MediaOptimizationService;
|
import dev.kruhlmann.imgfloat.service.media.MediaOptimizationService;
|
||||||
import dev.kruhlmann.imgfloat.service.media.MediaPreviewService;
|
import dev.kruhlmann.imgfloat.service.media.MediaPreviewService;
|
||||||
|
import dev.kruhlmann.imgfloat.service.SettingsService;
|
||||||
|
import dev.kruhlmann.imgfloat.model.Settings;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
import org.springframework.web.server.ResponseStatusException;
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
@@ -47,12 +50,15 @@ class ChannelDirectoryServiceTest {
|
|||||||
private SimpMessagingTemplate messagingTemplate;
|
private SimpMessagingTemplate messagingTemplate;
|
||||||
private ChannelRepository channelRepository;
|
private ChannelRepository channelRepository;
|
||||||
private AssetRepository assetRepository;
|
private AssetRepository assetRepository;
|
||||||
|
private SettingsService settingsService;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setup() throws Exception {
|
void setup() throws Exception {
|
||||||
messagingTemplate = mock(SimpMessagingTemplate.class);
|
messagingTemplate = mock(SimpMessagingTemplate.class);
|
||||||
channelRepository = mock(ChannelRepository.class);
|
channelRepository = mock(ChannelRepository.class);
|
||||||
assetRepository = mock(AssetRepository.class);
|
assetRepository = mock(AssetRepository.class);
|
||||||
|
settingsService = mock(SettingsService.class);
|
||||||
|
when(settingsService.get()).thenReturn(Settings.defaults());
|
||||||
setupInMemoryPersistence();
|
setupInMemoryPersistence();
|
||||||
Path assetRoot = Files.createTempDirectory("imgfloat-assets-test");
|
Path assetRoot = Files.createTempDirectory("imgfloat-assets-test");
|
||||||
Path previewRoot = Files.createTempDirectory("imgfloat-previews-test");
|
Path previewRoot = Files.createTempDirectory("imgfloat-previews-test");
|
||||||
@@ -61,7 +67,8 @@ class ChannelDirectoryServiceTest {
|
|||||||
MediaOptimizationService mediaOptimizationService = new MediaOptimizationService(mediaPreviewService);
|
MediaOptimizationService mediaOptimizationService = new MediaOptimizationService(mediaPreviewService);
|
||||||
MediaDetectionService mediaDetectionService = new MediaDetectionService();
|
MediaDetectionService mediaDetectionService = new MediaDetectionService();
|
||||||
service = new ChannelDirectoryService(channelRepository, assetRepository, messagingTemplate,
|
service = new ChannelDirectoryService(channelRepository, assetRepository, messagingTemplate,
|
||||||
assetStorageService, mediaDetectionService, mediaOptimizationService);
|
assetStorageService, mediaDetectionService, mediaOptimizationService, settingsService);
|
||||||
|
ReflectionTestUtils.setField(service, "uploadLimitBytes", 5_000_000L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -99,7 +106,7 @@ class ChannelDirectoryServiceTest {
|
|||||||
|
|
||||||
assertThatThrownBy(() -> service.updateTransform(channel, id, transform))
|
assertThatThrownBy(() -> service.updateTransform(channel, id, transform))
|
||||||
.isInstanceOf(ResponseStatusException.class)
|
.isInstanceOf(ResponseStatusException.class)
|
||||||
.hasMessageContaining("Width must be greater than 0");
|
.hasMessageContaining("Canvas width out of range");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -112,14 +119,14 @@ class ChannelDirectoryServiceTest {
|
|||||||
|
|
||||||
assertThatThrownBy(() -> service.updateTransform(channel, id, speedTransform))
|
assertThatThrownBy(() -> service.updateTransform(channel, id, speedTransform))
|
||||||
.isInstanceOf(ResponseStatusException.class)
|
.isInstanceOf(ResponseStatusException.class)
|
||||||
.hasMessageContaining("Playback speed must be between 0 and 4.0");
|
.hasMessageContaining("Speed out of range");
|
||||||
|
|
||||||
TransformRequest volumeTransform = validTransform();
|
TransformRequest volumeTransform = validTransform();
|
||||||
volumeTransform.setAudioVolume(1.5);
|
volumeTransform.setAudioVolume(6.5);
|
||||||
|
|
||||||
assertThatThrownBy(() -> service.updateTransform(channel, id, volumeTransform))
|
assertThatThrownBy(() -> service.updateTransform(channel, id, volumeTransform))
|
||||||
.isInstanceOf(ResponseStatusException.class)
|
.isInstanceOf(ResponseStatusException.class)
|
||||||
.hasMessageContaining("Audio volume must be between 0 and 1.0");
|
.hasMessageContaining("Audio volume out of range");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -128,19 +135,19 @@ class ChannelDirectoryServiceTest {
|
|||||||
String id = createSampleAsset(channel);
|
String id = createSampleAsset(channel);
|
||||||
|
|
||||||
TransformRequest transform = validTransform();
|
TransformRequest transform = validTransform();
|
||||||
transform.setSpeed(0.0);
|
transform.setSpeed(0.1);
|
||||||
transform.setAudioSpeed(0.1);
|
transform.setAudioSpeed(0.1);
|
||||||
transform.setAudioPitch(0.5);
|
transform.setAudioPitch(0.1);
|
||||||
transform.setAudioVolume(1.0);
|
transform.setAudioVolume(0.01);
|
||||||
transform.setAudioDelayMillis(0);
|
transform.setAudioDelayMillis(0);
|
||||||
transform.setZIndex(1);
|
transform.setZIndex(1);
|
||||||
|
|
||||||
AssetView view = service.updateTransform(channel, id, transform).orElseThrow();
|
AssetView view = service.updateTransform(channel, id, transform).orElseThrow();
|
||||||
|
|
||||||
assertThat(view.speed()).isEqualTo(0.0);
|
assertThat(view.speed()).isEqualTo(0.1);
|
||||||
assertThat(view.audioSpeed()).isEqualTo(0.1);
|
assertThat(view.audioSpeed()).isEqualTo(0.1);
|
||||||
assertThat(view.audioPitch()).isEqualTo(0.5);
|
assertThat(view.audioPitch()).isEqualTo(0.1);
|
||||||
assertThat(view.audioVolume()).isEqualTo(1.0);
|
assertThat(view.audioVolume()).isEqualTo(0.01);
|
||||||
assertThat(view.audioDelayMillis()).isEqualTo(0);
|
assertThat(view.audioDelayMillis()).isEqualTo(0);
|
||||||
assertThat(view.zIndex()).isEqualTo(1);
|
assertThat(view.zIndex()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package dev.kruhlmann.imgfloat.service;
|
package dev.kruhlmann.imgfloat.service;
|
||||||
|
|
||||||
import dev.kruhlmann.imgfloat.service.media.AssetContent;
|
import dev.kruhlmann.imgfloat.service.media.AssetContent;
|
||||||
|
import dev.kruhlmann.imgfloat.model.Asset;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@@ -33,25 +34,30 @@ class AssetStorageServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void storesAndLoadsAssets() throws IOException {
|
void storesAndLoadsAssets() throws IOException {
|
||||||
byte[] bytes = new byte[]{1, 2, 3};
|
byte[] bytes = new byte[]{1, 2, 3};
|
||||||
|
Asset asset = new Asset("caster", "asset", "http://example.com", 10, 10);
|
||||||
|
asset.setMediaType("image/png");
|
||||||
|
|
||||||
String path = service.storeAsset("caster", "id", bytes, "image/png");
|
service.storeAsset("caster", asset.getId(), bytes, "image/png");
|
||||||
assertThat(Files.exists(Path.of(path))).isTrue();
|
|
||||||
|
|
||||||
AssetContent loaded = service.loadAssetFile(path, "image/png").orElseThrow();
|
AssetContent loaded = service.loadAssetFile(asset).orElseThrow();
|
||||||
assertThat(loaded.bytes()).containsExactly(bytes);
|
assertThat(loaded.bytes()).containsExactly(bytes);
|
||||||
assertThat(loaded.mediaType()).isEqualTo("image/png");
|
assertThat(loaded.mediaType()).isEqualTo("image/png");
|
||||||
|
assertThat(Files.exists(assets.resolve("caster").resolve(asset.getId() + ".png"))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void ignoresEmptyPreview() throws IOException {
|
void ignoresEmptyPreview() throws IOException {
|
||||||
assertThat(service.storePreview("caster", "id", new byte[0])).isNull();
|
service.storePreview("caster", "id", new byte[0]);
|
||||||
|
assertThat(Files.list(previews).count()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void storesAndLoadsPreviews() throws IOException {
|
void storesAndLoadsPreviews() throws IOException {
|
||||||
byte[] preview = new byte[]{9, 8, 7};
|
byte[] preview = new byte[]{9, 8, 7};
|
||||||
|
Asset asset = new Asset("caster", "asset", "http://example.com", 10, 10);
|
||||||
|
asset.setMediaType("image/png");
|
||||||
|
|
||||||
String path = service.storePreview("caster", "id", preview);
|
service.storePreview("caster", asset.getId(), preview);
|
||||||
assertThat(service.loadPreview(path)).isPresent();
|
assertThat(service.loadPreview(asset)).isPresent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user