WIP: Submit transcoding jobs via a HTTP API #6

Draft
ansv7779 wants to merge 22 commits from api-submission into master
2 changed files with 25 additions and 13 deletions
Showing only changes of commit 8d13dc31c6 - Show all commits

View File

@ -54,7 +54,7 @@ public class ApiController {
}
@PostMapping("/api/transcriptions")
public TranscriptionCreatedResponse submitTranscriptionJob(
public TranscriptionResponse submitTranscriptionJob(
Principal owner,
UriComponentsBuilder uriComponentsBuilder,
@RequestBody CreateTranscriptionRequest createTranscriptionRequest)
@ -68,19 +68,23 @@ public class ApiController {
CreateTranscription createTranscription = new CreateTranscription(owner, callbackUri,
createTranscriptionRequest.language(), outputFormat);
Transcription transcription = transcriptionService.createTranscription(createTranscription);
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)));
URI attachSourceFile = createAttachSourceFileUri(uriComponentsBuilder, transcription);
return new TranscriptionResponse(transcription.id(), Map.of("attach-source-file", new Link(attachSourceFile)));
} catch (URISyntaxException e) {
throw new InvalidCallbackUri(createTranscriptionRequest.callback());
}
}
private static URI createAttachSourceFileUri(UriComponentsBuilder uriComponentsBuilder, Transcription transcription) {
return uriComponentsBuilder.cloneBuilder()
.pathSegment("api")
.pathSegment("transcriptions")
.pathSegment(transcription.id().toString())
.pathSegment("file")
.build()
.toUri();
}
private OutputFormat parseOutputFormat(String outputFormat) {
return switch (outputFormat) {
case "txt" -> OutputFormat.PLAIN_TEXT;
@ -97,7 +101,7 @@ public class ApiController {
* They must be unique based on filename, same filename will overwrite the existing file.
*/
@PutMapping(value = "/api/transcriptions/{id}/file", consumes = "*/*")
public ResponseEntity<Void> uploadFileToBeTranscribed(
public TranscriptionResponse uploadFileToBeTranscribed(
Principal owner,
@PathVariable("id") String id,
@RequestHeader("X-Filename") String filename,
@ -127,7 +131,16 @@ public class ApiController {
.pathSegment("result")
.build()
.toUri());
return ResponseEntity.accepted().build();
URI submitJobUri = uriComponentsBuilder.cloneBuilder()
.pathSegment("api")
.pathSegment("transcriptions")
.pathSegment(id)
.pathSegment("job")
.build()
.toUri();
return new TranscriptionResponse(uuid, Map.of(
"attach-source-file", new Link(createAttachSourceFileUri(uriComponentsBuilder, transcription)),
"submit-job", new Link(submitJobUri)));
} catch (IllegalArgumentException ignored) {
// Invalid UUID
throw new TranscriptionNotFound(id);

View File

@ -2,11 +2,10 @@ 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(
public record TranscriptionResponse(
@JsonProperty(value = "id", required = true) UUID id,
@JsonProperty(value = "links", required = true) Map<String, Link> links)
{