Fix bugs related to importing history
This commit is contained in:
@ -13,13 +13,13 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.bivashy.backend.composer.auth.CustomUserDetails;
|
||||
import com.bivashy.backend.composer.dto.importing.TrackProgressDTO;
|
||||
import com.bivashy.backend.composer.dto.track.AddLocalTrackRequest;
|
||||
import com.bivashy.backend.composer.dto.track.PlaylistTrackResponse;
|
||||
import com.bivashy.backend.composer.dto.track.TrackBulkReorderRequest;
|
||||
import com.bivashy.backend.composer.dto.track.TrackResponse;
|
||||
import com.bivashy.backend.composer.model.SourceTypes;
|
||||
import com.bivashy.backend.composer.model.User;
|
||||
import com.bivashy.backend.composer.service.TrackService;
|
||||
import com.bivashy.backend.composer.service.importing.RedisProgressService;
|
||||
|
||||
@ -35,7 +35,7 @@ public class TrackController {
|
||||
|
||||
@PostMapping(path = "/playlist/{playlistId}/track/local", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ResponseEntity<TrackResponse> addLocalTrack(
|
||||
@AuthenticationPrincipal User user,
|
||||
@AuthenticationPrincipal CustomUserDetails user,
|
||||
@PathVariable Long playlistId,
|
||||
@ModelAttribute AddLocalTrackRequest request) throws IOException {
|
||||
TrackResponse response = trackService.addLocalTrack(user, playlistId, request);
|
||||
@ -45,22 +45,22 @@ public class TrackController {
|
||||
response.fileFormat(),
|
||||
SourceTypes.FILE,
|
||||
100,
|
||||
"",
|
||||
null,
|
||||
System.currentTimeMillis(),
|
||||
user.getId()));
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@GetMapping("/playlist/{playlistId}/tracks")
|
||||
public ResponseEntity<List<PlaylistTrackResponse>> getPlaylistTracks(
|
||||
@AuthenticationPrincipal User user,
|
||||
@AuthenticationPrincipal CustomUserDetails user,
|
||||
@PathVariable Long playlistId) {
|
||||
List<PlaylistTrackResponse> tracks = trackService.getPlaylistTracks(user, playlistId);
|
||||
return ResponseEntity.ok(tracks);
|
||||
}
|
||||
|
||||
@PostMapping("/playlist/{playlistId}/bulk-reorder")
|
||||
public void bulkReorder(@AuthenticationPrincipal User user,
|
||||
public void bulkReorder(@AuthenticationPrincipal CustomUserDetails user,
|
||||
@RequestBody TrackBulkReorderRequest request,
|
||||
@PathVariable Long playlistId) {
|
||||
trackService.bulkReorder(user, playlistId, request);
|
||||
|
||||
@ -67,7 +67,6 @@ public class ProgressSSEController {
|
||||
try {
|
||||
List<TrackProgressDTO> existingProgresses = redisProgressService.getPlaylistProgress(playlistId,
|
||||
userId);
|
||||
System.out.println(existingProgresses);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
for (TrackProgressDTO progress : existingProgresses) {
|
||||
@ -83,7 +82,6 @@ public class ProgressSSEController {
|
||||
.doOnTerminate(() -> {
|
||||
cleanupConnection(playlistId, userId, sink, connectionKey);
|
||||
})
|
||||
.timeout(Duration.ofHours(2))
|
||||
.onErrorResume(e -> {
|
||||
cleanupConnection(playlistId, userId, sink, connectionKey);
|
||||
return Flux.empty();
|
||||
|
||||
@ -6,7 +6,7 @@ public class ImportTrackKey {
|
||||
}
|
||||
|
||||
public static String trackKey(long playlistId, long trackId, long userId) {
|
||||
return String.format("track:%d:%d:%s", userId, playlistId, trackId);
|
||||
return String.format("track:%d:%d:%d", userId, playlistId, trackId);
|
||||
}
|
||||
|
||||
public static String redisChannelKey(long playlistId, long userId) {
|
||||
|
||||
@ -8,16 +8,15 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import com.bivashy.backend.composer.auth.CustomUserDetails;
|
||||
import com.bivashy.backend.composer.dto.track.AddLocalTrackRequest;
|
||||
import com.bivashy.backend.composer.dto.track.PlaylistTrackResponse;
|
||||
import com.bivashy.backend.composer.dto.track.TrackBulkReorderRequest;
|
||||
import com.bivashy.backend.composer.dto.track.TrackReorderAfterRequest;
|
||||
import com.bivashy.backend.composer.dto.track.TrackResponse;
|
||||
import com.bivashy.backend.composer.model.SourceTypes;
|
||||
import com.bivashy.backend.composer.model.Track;
|
||||
import com.bivashy.backend.composer.model.TrackMetadata;
|
||||
import com.bivashy.backend.composer.model.TrackSource;
|
||||
import com.bivashy.backend.composer.model.User;
|
||||
import com.bivashy.backend.composer.repository.TrackRepository;
|
||||
import com.bivashy.backend.composer.service.MetadataParseService.Metadata;
|
||||
|
||||
@ -41,7 +40,8 @@ public class TrackService {
|
||||
this.metadataParseService = metadataParseService;
|
||||
}
|
||||
|
||||
public TrackResponse addLocalTrack(User user, Long playlistId, AddLocalTrackRequest request) throws IOException {
|
||||
public TrackResponse addLocalTrack(CustomUserDetails user, Long playlistId, AddLocalTrackRequest request)
|
||||
throws IOException {
|
||||
Optional<Metadata> metadata = metadataParseService.extractMetadata(request.source().getInputStream());
|
||||
String ffprobeJson = metadata.map(Metadata::rawJson).orElse("{}");
|
||||
|
||||
@ -76,7 +76,7 @@ public class TrackService {
|
||||
fileName);
|
||||
}
|
||||
|
||||
public List<PlaylistTrackResponse> getPlaylistTracks(User user, Long playlistId) {
|
||||
public List<PlaylistTrackResponse> getPlaylistTracks(CustomUserDetails user, Long playlistId) {
|
||||
return trackPlaylistService.getPlaylistTracks(playlistId).stream()
|
||||
.map(pt -> {
|
||||
Track track = trackRepository.findById(pt.getTrackId())
|
||||
@ -93,7 +93,7 @@ public class TrackService {
|
||||
.toList();
|
||||
}
|
||||
|
||||
public void bulkReorder(User user, Long playlistId, TrackBulkReorderRequest request) {
|
||||
public void bulkReorder(CustomUserDetails user, Long playlistId, TrackBulkReorderRequest request) {
|
||||
trackPlaylistService.bulkReorder(playlistId, request.trackIds());
|
||||
}
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ public class RedisProgressService {
|
||||
progress.getUserId());
|
||||
|
||||
String progressJson = objectMapper.writeValueAsString(progress);
|
||||
redisTemplate.opsForHash().put(key, progress.getTrackId(), progressJson);
|
||||
redisTemplate.opsForHash().put(key, Long.toString(progress.getTrackId()), progressJson);
|
||||
|
||||
redisTemplate.opsForValue().set(trackKey, progressJson);
|
||||
|
||||
@ -57,7 +57,7 @@ public class RedisProgressService {
|
||||
progressList.add(progress);
|
||||
}
|
||||
|
||||
progressList.sort(Comparator.comparingLong(TrackProgressDTO::getTimestamp));
|
||||
progressList.sort(Comparator.comparingLong(t -> Optional.ofNullable(t.getTimestamp()).orElse(0L)));
|
||||
|
||||
return progressList;
|
||||
} catch (Exception e) {
|
||||
@ -65,7 +65,7 @@ public class RedisProgressService {
|
||||
}
|
||||
}
|
||||
|
||||
public TrackProgressDTO getTrackProgress(long playlistId, String trackId, long userId) {
|
||||
public TrackProgressDTO getTrackProgress(long playlistId, long trackId, long userId) {
|
||||
try {
|
||||
String key = ImportTrackKey.trackKey(playlistId, trackId, userId);
|
||||
String progressJson = redisTemplate.opsForValue().get(key);
|
||||
|
||||
Reference in New Issue
Block a user