chore(backend): remove LocalDateTime usage, replaced with Instant
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
package com.ddf.vodsystem.controllers.dto;
|
package com.ddf.vodsystem.controllers.dto;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.Instant;
|
||||||
|
|
||||||
public record ClipResponse(
|
public record ClipResponse(
|
||||||
Long id,
|
Long id,
|
||||||
@@ -8,5 +8,5 @@ public record ClipResponse(
|
|||||||
String title,
|
String title,
|
||||||
String description,
|
String description,
|
||||||
Float duration,
|
Float duration,
|
||||||
LocalDateTime createdAt
|
Instant createdAt
|
||||||
) {}
|
) {}
|
||||||
@@ -5,7 +5,7 @@ import jakarta.persistence.*;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.Instant;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "clips")
|
@Table(name = "clips")
|
||||||
@@ -28,7 +28,7 @@ public class Clip {
|
|||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@Column(name = "created_at")
|
@Column(name = "created_at")
|
||||||
private LocalDateTime createdAt;
|
private Instant createdAt;
|
||||||
|
|
||||||
@Column(name = "width", nullable = false)
|
@Column(name = "width", nullable = false)
|
||||||
private Integer width;
|
private Integer width;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import jakarta.persistence.*;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.Instant;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "streams")
|
@Table(name = "streams")
|
||||||
@@ -21,11 +21,11 @@ public class Stream {
|
|||||||
private User user;
|
private User user;
|
||||||
|
|
||||||
@Column(name = "start_time")
|
@Column(name = "start_time")
|
||||||
private LocalDateTime startDate;
|
private Instant startDate;
|
||||||
|
|
||||||
@Column(name = "end_time")
|
@Column(name = "end_time")
|
||||||
private LocalDateTime endDate;
|
private Instant endDate;
|
||||||
|
|
||||||
@Column(name = "last_seen")
|
@Column(name = "last_seen")
|
||||||
private LocalDateTime lastSeen;
|
private Instant lastSeen;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.ddf.vodsystem.entities;
|
|||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.Instant;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "users")
|
@Table(name = "users")
|
||||||
@@ -33,7 +33,7 @@ public class User {
|
|||||||
private Integer role; // 0: user, 1: admin
|
private Integer role; // 0: user, 1: admin
|
||||||
|
|
||||||
@Column(name = "created_at")
|
@Column(name = "created_at")
|
||||||
private LocalDateTime createdAt;
|
private Instant createdAt;
|
||||||
|
|
||||||
@Column(name = "stream_key")
|
@Column(name = "stream_key")
|
||||||
private String streamKey;
|
private String streamKey;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import com.ddf.vodsystem.entities.User;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@@ -13,5 +13,5 @@ import java.util.Optional;
|
|||||||
public interface StreamRepository extends JpaRepository<Stream, Long> {
|
public interface StreamRepository extends JpaRepository<Stream, Long> {
|
||||||
Optional<Stream> findByUserAndEndDateIsNull(User user);
|
Optional<Stream> findByUserAndEndDateIsNull(User user);
|
||||||
List<Stream> findByUser(User user);
|
List<Stream> findByUser(User user);
|
||||||
List<Stream> findByEndDateIsNullAndLastSeenBefore(LocalDateTime cutoff);
|
List<Stream> findByEndDateIsNullAndLastSeenBefore(Instant cutoff);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.time.LocalDateTime;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
@@ -208,7 +208,7 @@ public class ClipService {
|
|||||||
clip.setUser(user);
|
clip.setUser(user);
|
||||||
clip.setTitle(options.getTitle() != null ? options.getTitle() : "Untitled Clip");
|
clip.setTitle(options.getTitle() != null ? options.getTitle() : "Untitled Clip");
|
||||||
clip.setDescription(options.getDescription() != null ? options.getDescription() : "");
|
clip.setDescription(options.getDescription() != null ? options.getDescription() : "");
|
||||||
clip.setCreatedAt(LocalDateTime.now());
|
clip.setCreatedAt(Instant.now());
|
||||||
clip.setWidth(options.getWidth());
|
clip.setWidth(options.getWidth());
|
||||||
clip.setHeight(options.getHeight());
|
clip.setHeight(options.getHeight());
|
||||||
clip.setFps(options.getFps());
|
clip.setFps(options.getFps());
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import org.springframework.scheduling.annotation.Scheduled;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.Instant;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -37,7 +37,7 @@ public class StreamService {
|
|||||||
throw new AlreadyStreaming("User " + user.getUsername() + " is already streaming.");
|
throw new AlreadyStreaming("User " + user.getUsername() + " is already streaming.");
|
||||||
});
|
});
|
||||||
|
|
||||||
LocalDateTime now = LocalDateTime.now();
|
Instant now = Instant.now();
|
||||||
Stream stream = new Stream();
|
Stream stream = new Stream();
|
||||||
stream.setUser(user);
|
stream.setUser(user);
|
||||||
stream.setStartDate(now);
|
stream.setStartDate(now);
|
||||||
@@ -52,7 +52,7 @@ public class StreamService {
|
|||||||
.orElseThrow(() -> new IllegalStateException(
|
.orElseThrow(() -> new IllegalStateException(
|
||||||
"No active stream found for user " + user.getUsername()));
|
"No active stream found for user " + user.getUsername()));
|
||||||
|
|
||||||
stream.setEndDate(LocalDateTime.now());
|
stream.setEndDate(Instant.now());
|
||||||
streamRepository.saveAndFlush(stream);
|
streamRepository.saveAndFlush(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ public class StreamService {
|
|||||||
.orElseThrow(() -> new IllegalStateException(
|
.orElseThrow(() -> new IllegalStateException(
|
||||||
"No active stream found for user " + user.getUsername()));
|
"No active stream found for user " + user.getUsername()));
|
||||||
|
|
||||||
stream.setLastSeen(LocalDateTime.now());
|
stream.setLastSeen(Instant.now());
|
||||||
streamRepository.saveAndFlush(stream);
|
streamRepository.saveAndFlush(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,11 +97,11 @@ public class StreamService {
|
|||||||
@Scheduled(fixedDelay = 30_000)
|
@Scheduled(fixedDelay = 30_000)
|
||||||
@Transactional
|
@Transactional
|
||||||
public void endStaleStreams() {
|
public void endStaleStreams() {
|
||||||
LocalDateTime cutoff = LocalDateTime.now().minusSeconds(HEARTBEAT_TIMEOUT_SECONDS);
|
Instant cutoff = Instant.now().minusSeconds(HEARTBEAT_TIMEOUT_SECONDS);
|
||||||
List<Stream> stale = streamRepository.findByEndDateIsNullAndLastSeenBefore(cutoff);
|
List<Stream> stale = streamRepository.findByEndDateIsNullAndLastSeenBefore(cutoff);
|
||||||
if (stale.isEmpty()) return;
|
if (stale.isEmpty()) return;
|
||||||
|
|
||||||
LocalDateTime now = LocalDateTime.now();
|
Instant now = Instant.now();
|
||||||
for (Stream stream : stale) {
|
for (Stream stream : stale) {
|
||||||
stream.setEndDate(now);
|
stream.setEndDate(now);
|
||||||
logger.warn("Stream {} for user {} ended due to heartbeat timeout", stream.getId(), stream.getUser().getUsername());
|
logger.warn("Stream {} for user {} ended due to heartbeat timeout", stream.getId(), stream.getUser().getUsername());
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.time.LocalDateTime;
|
import java.time.Instant;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HexFormat;
|
import java.util.HexFormat;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -77,7 +77,7 @@ public class UserService {
|
|||||||
|
|
||||||
if (existingUser.isEmpty()) {
|
if (existingUser.isEmpty()) {
|
||||||
user.setRole(0);
|
user.setRole(0);
|
||||||
user.setCreatedAt(LocalDateTime.now());
|
user.setCreatedAt(Instant.now());
|
||||||
user.setStreamKey(generateStreamKey());
|
user.setStreamKey(generateStreamKey());
|
||||||
return userRepository.saveAndFlush(user);
|
return userRepository.saveAndFlush(user);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class CompressionService {
|
|||||||
outputFile,
|
outputFile,
|
||||||
clipOptions
|
clipOptions
|
||||||
);
|
);
|
||||||
CommandOutput result = CommandRunner.run(command, line -> setProgress(line, progress, clipOptions.getDuration()));
|
CommandOutput result = CommandRunner.run(command, line -> CommandRunner.setProgress(line, progress, clipOptions.getDuration()));
|
||||||
progress.markComplete();
|
progress.markComplete();
|
||||||
|
|
||||||
return CompletableFuture.completedFuture(result);
|
return CompletableFuture.completedFuture(result);
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ public class StreamActionsService {
|
|||||||
logger.info("Saving section with ({} segments) to '{}'",
|
logger.info("Saving section with ({} segments) to '{}'",
|
||||||
segments.size(), outputFile);
|
segments.size(), outputFile);
|
||||||
CommandRunner.run(command, line -> CommandRunner.setProgress(line, progressTracker, duration));
|
CommandRunner.run(command, line -> CommandRunner.setProgress(line, progressTracker, duration));
|
||||||
|
progressTracker.markComplete();
|
||||||
|
|
||||||
return CompletableFuture.completedFuture(outputFile);
|
return CompletableFuture.completedFuture(outputFile);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
spring.docker.compose.file=docker-compose.dev.yml
|
spring.docker.compose.file=docker-compose.dev.yml
|
||||||
|
|
||||||
media.temp.inputs=./video/inputs
|
media.temp.inputs=./videos/inputs
|
||||||
media.temp.outputs=./videos/outputs
|
media.temp.outputs=./videos/outputs
|
||||||
media.users=${MEDIA_DATA}
|
media.users=${MEDIA_DATA}
|
||||||
media.streams=${STREAM_DATA}
|
media.streams=${STREAM_DATA}
|
||||||
@@ -32,3 +32,6 @@ media.streams=/app/stream/
|
|||||||
|
|
||||||
## Server Configuration
|
## Server Configuration
|
||||||
server.servlet.session.timeout=30m
|
server.servlet.session.timeout=30m
|
||||||
|
|
||||||
|
# Serialize Instant as ISO-8601 UTC string (not epoch seconds)
|
||||||
|
spring.jackson.serialization.write-dates-as-timestamps=false
|
||||||
@@ -10,7 +10,7 @@ CREATE TABLE IF NOT EXISTS users (
|
|||||||
name VARCHAR(100) NOT NULL,
|
name VARCHAR(100) NOT NULL,
|
||||||
profile_picture_url VARCHAR(255),
|
profile_picture_url VARCHAR(255),
|
||||||
role INTEGER DEFAULT 0,
|
role INTEGER DEFAULT 0,
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||||
stream_key VARCHAR(64) NOT NULL UNIQUE
|
stream_key VARCHAR(64) NOT NULL UNIQUE
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ CREATE TABLE IF NOT EXISTS clips (
|
|||||||
user_id BIGINT NOT NULL,
|
user_id BIGINT NOT NULL,
|
||||||
title VARCHAR(255) NOT NULL,
|
title VARCHAR(255) NOT NULL,
|
||||||
description TEXT,
|
description TEXT,
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||||
width INTEGER NOT NULL,
|
width INTEGER NOT NULL,
|
||||||
height INTEGER NOT NULL,
|
height INTEGER NOT NULL,
|
||||||
fps FLOAT NOT NULL,
|
fps FLOAT NOT NULL,
|
||||||
|
|||||||
Reference in New Issue
Block a user