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

View File

@ -2,11 +2,10 @@ package se.su.dsv.whisperapi.api;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
public record TranscriptionCreatedResponse( public record TranscriptionResponse(
@JsonProperty(value = "id", required = true) UUID id, @JsonProperty(value = "id", required = true) UUID id,
@JsonProperty(value = "links", required = true) Map<String, Link> links) @JsonProperty(value = "links", required = true) Map<String, Link> links)
{ {