MOVE user authentication and clip creation to ClipService
This commit is contained in:
@@ -1,24 +1,15 @@
|
||||
package com.ddf.vodsystem.services;
|
||||
|
||||
import com.ddf.vodsystem.entities.*;
|
||||
import com.ddf.vodsystem.repositories.ClipRepository;
|
||||
import com.ddf.vodsystem.security.CustomOAuth2User;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Service
|
||||
public class EditService {
|
||||
private final JobService jobService;
|
||||
private final ClipRepository clipRepository;
|
||||
|
||||
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(EditService.class);
|
||||
|
||||
public EditService(JobService jobService, ClipRepository clipRepository) {
|
||||
public EditService(JobService jobService) {
|
||||
this.jobService = jobService;
|
||||
this.clipRepository = clipRepository;
|
||||
}
|
||||
|
||||
public void edit(String uuid, VideoMetadata videoMetadata) {
|
||||
@@ -29,15 +20,6 @@ public class EditService {
|
||||
|
||||
public void process(String uuid) {
|
||||
jobService.jobReady(uuid);
|
||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (auth != null && auth.isAuthenticated() && auth.getPrincipal() instanceof CustomOAuth2User oAuth2user) {
|
||||
logger.debug("Saving clip {} for user {}", uuid, oAuth2user.getName());
|
||||
VideoMetadata videoMetadata = jobService.getJob(uuid).getOutputVideoMetadata();
|
||||
User user = oAuth2user.getUser();
|
||||
|
||||
createClip(videoMetadata, user);
|
||||
}
|
||||
}
|
||||
|
||||
public float getProgress(String uuid) {
|
||||
@@ -87,18 +69,4 @@ public class EditService {
|
||||
}
|
||||
}
|
||||
|
||||
private void createClip(VideoMetadata videoMetadata, User user) {
|
||||
Clip clip = new Clip();
|
||||
clip.setTitle("test");
|
||||
clip.setUser(user);
|
||||
clip.setDescription("This is a test");
|
||||
clip.setCreatedAt(LocalDateTime.now());
|
||||
clip.setWidth(videoMetadata.getWidth());
|
||||
clip.setHeight(videoMetadata.getHeight());
|
||||
clip.setFps(videoMetadata.getFps());
|
||||
clip.setDuration(videoMetadata.getEndPoint() - videoMetadata.getStartPoint());
|
||||
clip.setFileSize(videoMetadata.getFileSize());
|
||||
clip.setVideoPath("test");
|
||||
clipRepository.save(clip);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user