Files
vod-system/src/main/java/com/ddf/vodsystem/services/DownloadService.java
2025-05-15 12:09:22 +02:00

54 lines
1.4 KiB
Java

package com.ddf.vodsystem.services;
import com.ddf.vodsystem.entities.JobStatus;
import com.ddf.vodsystem.exceptions.JobNotFinished;
import com.ddf.vodsystem.exceptions.JobNotFound;
import com.ddf.vodsystem.entities.Job;
import com.vaadin.flow.server.auth.AnonymousAllowed;
import com.vaadin.hilla.Endpoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;
import java.io.File;
@Service
@Endpoint
@AnonymousAllowed
public class DownloadService {
private final JobService jobService;
@Autowired
public DownloadService(JobService jobService) {
this.jobService = jobService;
}
public Resource downloadInput(String uuid) {
Job job = jobService.getJob(uuid);
if (job == null) {
throw new JobNotFound("Job doesn't exist");
}
File file = job.getInputFile();
return new FileSystemResource(file);
}
public Resource downloadOutput(String uuid) {
Job job = jobService.getJob(uuid);
if (job == null) {
throw new JobNotFound("Job doesn't exist");
}
if (job.getStatus() != JobStatus.FINISHED) {
throw new JobNotFinished("Job is not finished");
}
File file = job.getOutputFile();
return new FileSystemResource(file);
}
}