WIP: Submit transcoding jobs via a HTTP API #6
@ -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,19 +68,23 @@ 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);
|
||||||
.pathSegment("api")
|
return new TranscriptionResponse(transcription.id(), Map.of("attach-source-file", new Link(attachSourceFile)));
|
||||||
.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) {
|
} catch (URISyntaxException e) {
|
||||||
throw new InvalidCallbackUri(createTranscriptionRequest.callback());
|
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) {
|
private OutputFormat parseOutputFormat(String outputFormat) {
|
||||||
return switch (outputFormat) {
|
return switch (outputFormat) {
|
||||||
case "txt" -> OutputFormat.PLAIN_TEXT;
|
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.
|
* 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);
|
||||||
|
@ -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)
|
||||||
{
|
{
|
Loading…
x
Reference in New Issue
Block a user