Skip to content

Commit

Permalink
Add media download api endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
philmcmahon committed Oct 2, 2024
1 parent ed2cce8 commit ef9d407
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ import {
logger,
getObjectText,
getS3Client,
sendMessage,
} from '@guardian/transcription-service-backend-common';
import {
ClientConfig,
TranscriptExportRequest,
inputBucketObjectMetadata,
transcribeFileRequestBody,
transcribeUrlRequestBody,
MediaDownloadJob,
} from '@guardian/transcription-service-common';
import type { SignedUrlResponseBody } from '@guardian/transcription-service-common';
import {
Expand Down Expand Up @@ -71,6 +74,43 @@ const getApp = async () => {
}),
]);

apiRouter.post('/transcribe-url', [
checkAuth,
asyncHandler(async (req, res) => {
const userEmail = req.user?.email;
const body = transcribeUrlRequestBody.safeParse(req.body);
const id = uuid4();
if (!body.success || !userEmail) {
res.status(422).send('missing request params');
return;
}
const downloadJob: MediaDownloadJob = {
id,
url: body.data.url,
languageCode: body.data.languageCode,
translationRequested: body.data.translationRequested,
userEmail,
};

const sendResult = await sendMessage(
sqsClient,
config.app.mediaDownloadQueueUrl,
JSON.stringify(downloadJob),
id,
);
if (isSqsFailure(sendResult)) {
res.status(500).send(sendResult.errorMsg);
return;
}
logger.info('API successfully sent the message to SQS', {
id,
url: body.data.url,
userEmail,
});
res.send('Message sent');
}),
]);

apiRouter.post('/transcribe-file', [
checkAuth,
asyncHandler(async (req, res) => {
Expand Down

0 comments on commit ef9d407

Please sign in to comment.