diff --git a/.env.example b/.env.example index b1f5962..8864b13 100644 --- a/.env.example +++ b/.env.example @@ -13,4 +13,5 @@ POSTGRES_USER=myuser POSTGRES_PASSWORD=mypassword POSTGRES_DB=vodSystem -FRONTEND_URL= \ No newline at end of file +FRONTEND_URL= +BACKEND_URL \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 3ce1e7f..796f1cb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -33,7 +33,7 @@ services: dockerfile: Dockerfile container_name: vod_frontend environment: - VITE_API_URL: "http://localhost:8080" + VITE_API_URL: ${BACKEND_URL} VITE_GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID} depends_on: - backend diff --git a/src/main/java/com/ddf/vodsystem/services/StreamService.java b/src/main/java/com/ddf/vodsystem/services/StreamService.java index 07d7b45..667ad55 100644 --- a/src/main/java/com/ddf/vodsystem/services/StreamService.java +++ b/src/main/java/com/ddf/vodsystem/services/StreamService.java @@ -3,7 +3,6 @@ package com.ddf.vodsystem.services; import com.ddf.vodsystem.entities.Stream; import com.ddf.vodsystem.entities.User; import com.ddf.vodsystem.exceptions.AlreadyStreaming; -import com.ddf.vodsystem.exceptions.FFMPEGException; import com.ddf.vodsystem.exceptions.KeyNotFound; import com.ddf.vodsystem.exceptions.NotAuthenticated; import com.ddf.vodsystem.repositories.StreamRepository; @@ -32,6 +31,7 @@ public class StreamService { private static final int HEARTBEAT_TIMEOUT_SECONDS = 60; private static final float CLIP_MAX_LENGTH = 180; + private static final int HLS_SEGMENT_LENGTH = 3; private final StreamRepository streamRepository; private final UserService userService; @@ -91,9 +91,20 @@ public class StreamService { } public List getStreamHistory(Long userId) { - User user = userService.getUserById(userId) + User streamUser = userService.getUserById(userId) .orElseThrow(() -> new IllegalArgumentException("User not found: " + userId)); - return streamRepository.findByUser(user); + + Optional user = userService.getLoggedInUser(); + + if (user.isEmpty()) { + throw new NotAuthenticated("Log in to see user streams"); + } + + if (!user.get().equals(streamUser)) { + throw new NotAuthenticated("You are not authenticated to see these user streams"); + } + + return streamRepository.findByUser(streamUser); } /** @@ -108,7 +119,6 @@ public class StreamService { * @throws IllegalArgumentException if {@code startTime} is not before {@code endTime}, * or if no stream segments exist in the given range * @throws NotAuthenticated if no user is currently authenticated - * @throws FFMPEGException if the underlying FFMPEG save operation fails * @throws IOException if reading the stream directory or its segments fails * @throws InterruptedException if the thread is interrupted while performing the save */ @@ -131,10 +141,7 @@ public class StreamService { float trimOffset = Math.max(0f, (startTime.toEpochMilli() - firstSegmentMs) / 1000f); float duration = (endTime.toEpochMilli() - startTime.toEpochMilli()) / 1000f; - streamActionsService.saveSection(fileSegments, trimOffset, duration) - .exceptionally(ex -> { - throw new FFMPEGException("Saving stream section failed due to FFMPEG Error"); - }); + streamActionsService.saveSection(fileSegments, trimOffset, duration); } /** @@ -149,7 +156,6 @@ public class StreamService { * @throws IllegalArgumentException if {@code duration} is not in the range {@code (0, CLIP_MAX_LENGTH]}, * or if no stream segments exist in the computed window * @throws NotAuthenticated if no user is currently authenticated - * @throws FFMPEGException if the underlying FFMPEG save operation fails * @throws IOException if reading the stream directory or its segments fails * @throws InterruptedException if the thread is interrupted while performing the save */ @@ -196,7 +202,7 @@ public class StreamService { return Arrays.stream(tsFiles) .filter(f -> { long segMs = parseTimestampMs(f); - return segMs < endMs && (segMs + 3_000) > startMs; + return segMs < endMs && (segMs + HLS_SEGMENT_LENGTH * 1000) > startMs; }) .sorted(Comparator.comparingLong(this::parseTimestampMs)) .collect(Collectors.toList()); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 1d4fc35..38aa1bd 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -29,7 +29,7 @@ jwt.expiration=3600000 frontend.url=${FRONTEND_URL} # Stream HLS -storage.stream=${STREAM_DATA:/stream} +storage.stream=${STREAM_DATA} ## Server Configuration server.servlet.session.timeout=30m \ No newline at end of file