WIP: Submit transcoding jobs via a HTTP API #6
@ -34,6 +34,7 @@ import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.Principal;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -55,6 +56,7 @@ public class ApiController {
|
||||
@PostMapping("/api/transcriptions")
|
||||
public TranscriptionCreatedResponse submitTranscriptionJob(
|
||||
Principal owner,
|
||||
UriComponentsBuilder uriComponentsBuilder,
|
||||
@RequestBody CreateTranscriptionRequest createTranscriptionRequest)
|
||||
{
|
||||
try {
|
||||
@ -66,7 +68,14 @@ public class ApiController {
|
||||
CreateTranscription createTranscription = new CreateTranscription(owner, callbackUri,
|
||||
createTranscriptionRequest.language(), outputFormat);
|
||||
Transcription transcription = transcriptionService.createTranscription(createTranscription);
|
||||
return new TranscriptionCreatedResponse(transcription.id());
|
||||
URI attachSourceFile = uriComponentsBuilder.cloneBuilder()
|
||||
.pathSegment("api")
|
||||
.pathSegment("transcriptions")
|
||||
.pathSegment(transcription.id().toString())
|
||||
.pathSegment("file")
|
||||
.build()
|
||||
.toUri();
|
||||
return new TranscriptionCreatedResponse(transcription.id(), Map.of("attach-source-file", new Link(attachSourceFile)));
|
||||
} catch (URISyntaxException e) {
|
||||
throw new InvalidCallbackUri(createTranscriptionRequest.callback());
|
||||
}
|
||||
|
7
src/main/java/se/su/dsv/whisperapi/api/Link.java
Normal file
7
src/main/java/se/su/dsv/whisperapi/api/Link.java
Normal file
@ -0,0 +1,7 @@
|
||||
package se.su.dsv.whisperapi.api;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public record Link(@JsonProperty(value = "href", required = true) URI href) {}
|
@ -2,9 +2,12 @@ package se.su.dsv.whisperapi.api;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public record TranscriptionCreatedResponse(
|
||||
@JsonProperty(value = "id", required = true) UUID id)
|
||||
@JsonProperty(value = "id", required = true) UUID id,
|
||||
@JsonProperty(value = "links", required = true) Map<String, Link> links)
|
||||
{
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user