perf(api): add HTTP range requests on media sources (#9)
Reviewed-on: https://gitea.vodsystem.ddns.net/dylan/vod-system/pulls/9
This commit was merged in pull request #9.
This commit is contained in:
@@ -156,6 +156,10 @@ public class ClipService {
|
||||
throw new ClipNotFound("Clip file not found");
|
||||
}
|
||||
|
||||
if (!Files.isReadable(file)) {
|
||||
throw new ClipMediaUnavailable(id, "Clip file is not readable");
|
||||
}
|
||||
|
||||
return new FileSystemResource(file);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
@@ -129,11 +130,29 @@ public class DirectoryService {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDirPermissions() {
|
||||
List<Path> dirs = List.of(
|
||||
Path.of(tempInputsDir),
|
||||
Path.of(tempOutputsDir),
|
||||
Path.of(usersDir)
|
||||
);
|
||||
|
||||
List<Path> bad = dirs.stream()
|
||||
.filter(p -> !Files.isDirectory(p) || !Files.isReadable(p) || !Files.isWritable(p))
|
||||
.toList();
|
||||
|
||||
if (!bad.isEmpty()) {
|
||||
throw new IllegalStateException("Unusable directories: " + bad);
|
||||
}
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void createDirectoriesIfNotExist() throws IOException {
|
||||
Files.createDirectories(Path.of(tempInputsDir));
|
||||
Files.createDirectories(Path.of(tempOutputsDir));
|
||||
Files.createDirectories(Path.of(usersDir));
|
||||
|
||||
checkDirPermissions();
|
||||
}
|
||||
|
||||
@Scheduled(fixedRate = TEMP_DIR_CLEANUP_RATE)
|
||||
|
||||
@@ -93,7 +93,7 @@ public class MediaService {
|
||||
);
|
||||
}).exceptionally(ex -> {
|
||||
job.setState(JobState.FAILED);
|
||||
job.setErrorOutput(ex.getMessage());
|
||||
job.setErrorOutput("Compression job failed");
|
||||
logger.error("Compression job with UUID {} failed due to: {}", job.getUuid(), ex.getMessage());
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -139,6 +139,10 @@ public class VodService {
|
||||
throw new VodNotFound("Vod file not found for ID: " + id);
|
||||
}
|
||||
|
||||
if (!Files.isReadable(file)) {
|
||||
throw new VodMediaUnavailable(id, "Vod file is not readable");
|
||||
}
|
||||
|
||||
return new FileSystemResource(file);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user