refactor(stream): centralize stream directory resolution in DirectoryService
This commit is contained in:
@@ -23,6 +23,9 @@ public class DirectoryService {
|
||||
@Value("${storage.outputs}")
|
||||
private String outputDir;
|
||||
|
||||
@Value("${STREAM_DATA}")
|
||||
private String streamDir;
|
||||
|
||||
@Value("${storage.temp.inputs}")
|
||||
private String tempInputsDir;
|
||||
|
||||
@@ -77,6 +80,12 @@ public class DirectoryService {
|
||||
return file;
|
||||
}
|
||||
|
||||
public File getStreamDir(String streamKey) throws IOException {
|
||||
File file = new File(streamDir + File.separator + streamKey);
|
||||
createDirectory(file.getAbsolutePath());
|
||||
return file;
|
||||
}
|
||||
|
||||
public File getUserThumbnailsFile(Long userId, String filename) throws IOException {
|
||||
if (filename == null || filename.isEmpty()) {
|
||||
throw new IllegalArgumentException("File name cannot be null or empty");
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.ddf.vodsystem.repositories.StreamRepository;
|
||||
import com.ddf.vodsystem.services.media.StreamActionsService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -35,9 +34,6 @@ public class StreamService {
|
||||
private final StreamActionsService streamActionsService;
|
||||
private final DirectoryService directoryService;
|
||||
|
||||
@Value("${storage.stream}")
|
||||
private String streamDataPath;
|
||||
|
||||
public StreamService(StreamRepository streamRepository,
|
||||
UserService userService,
|
||||
StreamActionsService streamActionsService,
|
||||
@@ -135,8 +131,8 @@ public class StreamService {
|
||||
User user = userService.getLoggedInUser()
|
||||
.orElseThrow(() -> new NotAuthenticated("User is not authenticated"));
|
||||
|
||||
String streamDirectory = streamDataPath + File.separator + user.getStreamKey();
|
||||
List<File> fileSegments = getSegmentsInRange(streamDirectory, startTime, endTime);
|
||||
File streamDirectory = directoryService.getStreamDir(user.getStreamKey());
|
||||
List<File> fileSegments = getSegmentsInRange(streamDirectory.getAbsolutePath(), startTime, endTime);
|
||||
|
||||
if (fileSegments.isEmpty()) {
|
||||
throw new IllegalArgumentException("No stream segments found in the given time range");
|
||||
|
||||
Reference in New Issue
Block a user