diff --git a/mediaServer/src/constants/clova-api-response-type.constant.ts b/mediaServer/src/constants/clova-api-response-type.constant.ts new file mode 100644 index 0000000..999055d --- /dev/null +++ b/mediaServer/src/constants/clova-api-response-type.constant.ts @@ -0,0 +1,4 @@ +const SUCCEEDED = "SUCCEEDED"; +const RETRIABLE_ERROR = ["ERROR_SERVER_BUSY", "ERROR_AUDIO_CONVERSION", "ERROR_INTERNAL_ERROR", "ERROR_EXTERNAL_ERROR"]; + +export { SUCCEEDED, RETRIABLE_ERROR }; diff --git a/mediaServer/src/dto/clova-api-request.dto.ts b/mediaServer/src/dto/clova-api-request.dto.ts new file mode 100644 index 0000000..12202f7 --- /dev/null +++ b/mediaServer/src/dto/clova-api-request.dto.ts @@ -0,0 +1,15 @@ +export const ClovaApiRequest =(url: any, code: string) =>{ + const headers = new Headers(); + headers.append('Content-Type', 'application/json'); + headers.append('X-CLOVASPEECH-API-KEY', process.env.CLOVA_API_KEY as string); + return { + method: 'POST', + headers: headers, + body: JSON.stringify({ + language: process.env.CLOVA_API_LANGUAGE, + completion: process.env.CLOVA_API_COMPLETION, + url: url, + callback: `${process.env.SERVER_API_URL}/lecture/${code}/text` + }) + } +} diff --git a/mediaServer/src/dto/clova-api-response.dto.ts b/mediaServer/src/dto/clova-api-response.dto.ts new file mode 100644 index 0000000..6575942 --- /dev/null +++ b/mediaServer/src/dto/clova-api-response.dto.ts @@ -0,0 +1,11 @@ +export class ClovaApiReponse { + result:string; + message: string; + timestamp: string; + + constructor(result:string, message:string, timestamp:string) { + this.result = result; + this.message = message; + this.timestamp = timestamp; + } +} \ No newline at end of file diff --git a/mediaServer/src/utils/media-converter.ts b/mediaServer/src/utils/media-converter.ts index 83d8d02..328dfbb 100644 --- a/mediaServer/src/utils/media-converter.ts +++ b/mediaServer/src/utils/media-converter.ts @@ -8,6 +8,9 @@ import path from 'path'; import { PeerStreamInfo } from '../models/PeerStreamInfo'; import { FfmpegCommand } from '../models/FfmpegCommand'; import { uploadFileToObjectStorage } from './ncp-storage'; +import { RETRIABLE_ERROR, SUCCEEDED } from '../constants/clova-api-response-type.constant'; +import { ClovaApiReponse } from '../dto/clova-api-response.dto'; +import { ClovaApiRequest } from '../dto/clova-api-request.dto'; import { AUDIO_OUTPUT_DIR } from '../constants/media-converter.constant'; ffmpeg.setFfmpegPath(ffmpegPath.path); @@ -132,21 +135,15 @@ class MediaConverter { }; extractSubtitle = async (url: any, code: string) => { - const headers = new Headers(); - headers.append('Content-Type', 'application/json'); - headers.append('X-CLOVASPEECH-API-KEY', process.env.CLOVA_API_KEY as string); - - const response = await fetch(process.env.CLOVA_API_URL as string, { - method: 'POST', - headers: headers, - body: JSON.stringify({ - language: process.env.CLOVA_API_LANGUAGE, - completion: process.env.CLOVA_API_COMPLETION, - url: url, - callback: `${process.env.SERVER_API_URL}/lecture/${code}/text` - }) - }); - console.log(`[${response.status}] 강의 자막 저장`); + const response = await fetch(process.env.CLOVA_API_URL as string, ClovaApiRequest(url, code)); + const result = await response.json() as ClovaApiReponse; + + if (result.result == SUCCEEDED) { + console.log(`[${result.result}] 강의 자막 저장`); + } + if (result.result in RETRIABLE_ERROR) { + const response = await fetch(process.env.CLOVA_API_URL as string, ClovaApiRequest(url, code)); + } }; }