WIP: Submit transcoding jobs via a HTTP API #6
@ -2,7 +2,7 @@ package se.su.dsv.whisperapi;
|
||||
|
||||
import org.springframework.jdbc.core.simple.JdbcClient;
|
||||
import se.su.dsv.whisperapi.core.OutputFormat;
|
||||
import se.su.dsv.whisperapi.core.TransactionRepository;
|
||||
import se.su.dsv.whisperapi.core.TranscriptionRepository;
|
||||
import se.su.dsv.whisperapi.core.Transcription;
|
||||
|
||||
import java.net.URI;
|
||||
@ -11,10 +11,10 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class JDBCTransactionRepository implements TransactionRepository {
|
||||
public class JDBCTranscriptionRepository implements TranscriptionRepository {
|
||||
private final JdbcClient jdbcClient;
|
||||
|
||||
public JDBCTransactionRepository(JdbcClient jdbcClient) {
|
||||
public JDBCTranscriptionRepository(JdbcClient jdbcClient) {
|
||||
this.jdbcClient = jdbcClient;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import org.springframework.jdbc.core.simple.JdbcClient;
|
||||
import org.springframework.security.config.Customizer;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import se.su.dsv.whisperapi.core.TransactionRepository;
|
||||
import se.su.dsv.whisperapi.core.TranscriptionRepository;
|
||||
import se.su.dsv.whisperapi.core.TranscriptionService;
|
||||
|
||||
@SpringBootApplication
|
||||
@ -42,14 +42,14 @@ public class WhisperApiApplication {
|
||||
|
||||
@Bean
|
||||
public TranscriptionService transcriptionService(
|
||||
TransactionRepository transcriptionRepository,
|
||||
TranscriptionRepository transcriptionRepository,
|
||||
WhisperFrontendConfiguration config)
|
||||
{
|
||||
return new TranscriptionService(transcriptionRepository, config.transcriptionFilesDirectory(), config.jobsDirectory());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JDBCTransactionRepository jdbcTransactionRepository(JdbcClient jdbcClient) {
|
||||
return new JDBCTransactionRepository(jdbcClient);
|
||||
public JDBCTranscriptionRepository jdbcTransactionRepository(JdbcClient jdbcClient) {
|
||||
return new JDBCTranscriptionRepository(jdbcClient);
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface TransactionRepository {
|
||||
public interface TranscriptionRepository {
|
||||
void save(Transcription transcription);
|
||||
|
||||
Optional<Transcription> findByOwnerAndId(Principal owner, UUID uuid);
|
@ -16,12 +16,12 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TranscriptionService {
|
||||
private final TransactionRepository transactionRepository;
|
||||
private final TranscriptionRepository transcriptionRepository;
|
||||
private final Path fileDirectory;
|
||||
private final Path jobsDirectory;
|
||||
|
||||
public TranscriptionService(TransactionRepository transactionRepository, Path fileDirectory, Path jobsDirectory) {
|
||||
this.transactionRepository = transactionRepository;
|
||||
public TranscriptionService(TranscriptionRepository transcriptionRepository, Path fileDirectory, Path jobsDirectory) {
|
||||
this.transcriptionRepository = transcriptionRepository;
|
||||
this.fileDirectory = fileDirectory;
|
||||
this.jobsDirectory = jobsDirectory;
|
||||
}
|
||||
@ -34,12 +34,12 @@ public class TranscriptionService {
|
||||
createTranscription.owner(),
|
||||
createTranscription.callbackUri(),
|
||||
createTranscription.outputFormat());
|
||||
transactionRepository.save(transcription);
|
||||
transcriptionRepository.save(transcription);
|
||||
return transcription;
|
||||
}
|
||||
|
||||
public Optional<Transcription> getTranscription(Principal owner, UUID uuid) {
|
||||
return transactionRepository.findByOwnerAndId(owner, uuid);
|
||||
return transcriptionRepository.findByOwnerAndId(owner, uuid);
|
||||
}
|
||||
|
||||
public void addFileToBeTranscribed(Transcription transcription, TranscriptionFile file)
|
||||
@ -51,14 +51,14 @@ public class TranscriptionService {
|
||||
var in = file.data())
|
||||
{
|
||||
in.transferTo(out);
|
||||
transactionRepository.addFileToTranscription(transcription, file.filename());
|
||||
transcriptionRepository.addFileToTranscription(transcription, file.filename());
|
||||
}
|
||||
}
|
||||
|
||||
public void submitTranscriptionJob(Transcription transcription, CallbackUriGenerator callbackUriGenerator) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
|
||||
List<String> filenames = transactionRepository.getFiles(transcription);
|
||||
List<String> filenames = transcriptionRepository.getFiles(transcription);
|
||||
for (String filename : filenames) {
|
||||
UUID jobId = UUID.randomUUID();
|
||||
Path fileToBeTranscribed = fileDirectory.resolve(transcription.id().toString()).resolve(filename);
|
||||
|
Loading…
x
Reference in New Issue
Block a user