WIP: Submit transcoding jobs via a HTTP API #6

Draft
ansv7779 wants to merge 22 commits from api-submission into master
3 changed files with 21 additions and 2 deletions
Showing only changes of commit aa49f418d2 - Show all commits

View File

@ -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());
}

View 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) {}

View File

@ -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)
{
}