@eka-care/ekascribe-ts-sdk 1.4.42 → 1.4.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/post-v1-file-upload.d.ts +6 -0
- package/dist/api/post-v1-file-upload.js +29 -0
- package/dist/api/transaction/post-transaction-init.d.ts +1 -1
- package/dist/api/transaction/post-transaction-init.js +6 -2
- package/dist/api/upload-audio-with-presigned-url.d.ts +10 -0
- package/dist/api/upload-audio-with-presigned-url.js +60 -0
- package/dist/audio-chunker/vad-web.d.ts +4 -0
- package/dist/audio-chunker/vad-web.js +7 -0
- package/dist/constants/enums.d.ts +2 -1
- package/dist/constants/enums.js +1 -0
- package/dist/constants/types.d.ts +35 -1
- package/dist/fetch-client/helper.d.ts +1 -0
- package/dist/fetch-client/helper.js +3 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +8 -0
- package/dist/main/init-transaction.d.ts +1 -1
- package/dist/main/init-transaction.js +3 -10
- package/dist/main/upload-full-audio-with-presigned-url.d.ts +8 -0
- package/dist/main/upload-full-audio-with-presigned-url.js +66 -0
- package/package.json +1 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { SDK_STATUS_CODE } from '../constants/constant';
|
|
2
|
+
import fetchWrapper from '../fetch-client';
|
|
3
|
+
import { GET_EKA_HOST } from '../fetch-client/helper';
|
|
4
|
+
async function postV1FileUpload({ txn_id, action, }) {
|
|
5
|
+
try {
|
|
6
|
+
const headers = new Headers();
|
|
7
|
+
headers.append('Content-Type', 'application/json');
|
|
8
|
+
const options = {
|
|
9
|
+
method: 'POST',
|
|
10
|
+
headers,
|
|
11
|
+
body: JSON.stringify({}),
|
|
12
|
+
};
|
|
13
|
+
const response = await fetchWrapper(`${GET_EKA_HOST()}/v1/file-upload?txn_id=${txn_id}&action=${action}`, options);
|
|
14
|
+
let res = await response.json();
|
|
15
|
+
res = {
|
|
16
|
+
...res,
|
|
17
|
+
code: response.status,
|
|
18
|
+
};
|
|
19
|
+
return res;
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.log('%c getPresignedUrl -> error', 'color:#f5ce50', error);
|
|
23
|
+
return {
|
|
24
|
+
code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
|
|
25
|
+
message: `Something went wrong! ${error}`,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export default postV1FileUpload;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { TPostTransactionInitRequest, TPostTransactionResponse } from '../../constants/types';
|
|
2
|
-
declare function postTransactionInit({ mode,
|
|
2
|
+
declare function postTransactionInit({ mode, txn_id, s3Url, input_language, output_format_template, model_training_consent, auto_download, transfer, system_info, patient_details, model_type, version, flavour, batch_s3_url, }: TPostTransactionInitRequest): Promise<TPostTransactionResponse>;
|
|
3
3
|
export default postTransactionInit;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SDK_STATUS_CODE } from '../../constants/constant';
|
|
2
2
|
import fetchWrapper from '../../fetch-client';
|
|
3
3
|
import { GET_EKA_VOICE_HOST_V2 } from '../../fetch-client/helper';
|
|
4
|
-
async function postTransactionInit({ mode,
|
|
4
|
+
async function postTransactionInit({ mode, txn_id, s3Url, input_language, output_format_template, model_training_consent, auto_download, transfer, system_info, patient_details, model_type, version, flavour, batch_s3_url, }) {
|
|
5
5
|
try {
|
|
6
6
|
const headers = new Headers();
|
|
7
7
|
headers.append('Content-Type', 'application/json');
|
|
@@ -15,13 +15,17 @@ async function postTransactionInit({ mode, txnId, s3Url, input_language, output_
|
|
|
15
15
|
transfer,
|
|
16
16
|
system_info,
|
|
17
17
|
patient_details,
|
|
18
|
+
model_type,
|
|
19
|
+
version,
|
|
20
|
+
flavour,
|
|
21
|
+
batch_s3_url,
|
|
18
22
|
};
|
|
19
23
|
const options = {
|
|
20
24
|
method: 'POST',
|
|
21
25
|
headers,
|
|
22
26
|
body: JSON.stringify(raw),
|
|
23
27
|
};
|
|
24
|
-
const response = await fetchWrapper(`${GET_EKA_VOICE_HOST_V2()}/transaction/init/${
|
|
28
|
+
const response = await fetchWrapper(`${GET_EKA_VOICE_HOST_V2()}/transaction/init/${txn_id}`, options);
|
|
25
29
|
let res = await response.json();
|
|
26
30
|
res = {
|
|
27
31
|
...res,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TPostV1FileUploadResponse } from '../constants/types';
|
|
2
|
+
type TUploadFilesResponse = {
|
|
3
|
+
code: number;
|
|
4
|
+
message: string;
|
|
5
|
+
};
|
|
6
|
+
declare function uploadFilesWithPresignedUrl({ audioFiles, presignedUrlResponse, }: {
|
|
7
|
+
audioFiles: File[] | Blob[];
|
|
8
|
+
presignedUrlResponse: TPostV1FileUploadResponse;
|
|
9
|
+
}): Promise<TUploadFilesResponse>;
|
|
10
|
+
export default uploadFilesWithPresignedUrl;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { SDK_STATUS_CODE } from '../constants/constant';
|
|
2
|
+
async function uploadSingleFile(uploadData, folderPath, file, fileName) {
|
|
3
|
+
try {
|
|
4
|
+
const updatedFields = {
|
|
5
|
+
...uploadData.fields,
|
|
6
|
+
key: folderPath + fileName,
|
|
7
|
+
};
|
|
8
|
+
const formData = new FormData();
|
|
9
|
+
Object.entries(updatedFields).forEach(([key, value]) => {
|
|
10
|
+
formData.append(key, value);
|
|
11
|
+
});
|
|
12
|
+
formData.append('file', file);
|
|
13
|
+
const response = await fetch(uploadData.url, {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
body: formData,
|
|
16
|
+
});
|
|
17
|
+
if (response.status === 204) {
|
|
18
|
+
// S3 returns 204 No Content on successful upload
|
|
19
|
+
return {
|
|
20
|
+
key: folderPath + fileName,
|
|
21
|
+
size: file.size,
|
|
22
|
+
success: true,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw new Error(`Upload failed with status: ${response.status}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error('uploadSingleFile error:', error);
|
|
31
|
+
return {
|
|
32
|
+
success: false,
|
|
33
|
+
error: `Upload failed: ${error}`,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function uploadFilesWithPresignedUrl({ audioFiles, presignedUrlResponse, }) {
|
|
38
|
+
try {
|
|
39
|
+
const uploadPromises = audioFiles.map((file, index) => {
|
|
40
|
+
const fileName = `audio_${index + 1}`;
|
|
41
|
+
return uploadSingleFile({ ...presignedUrlResponse.uploadData }, presignedUrlResponse.folderPath, file, fileName);
|
|
42
|
+
});
|
|
43
|
+
const results = await Promise.all(uploadPromises);
|
|
44
|
+
const failedUploads = results.filter((result) => !result.success);
|
|
45
|
+
const successfulUploads = results.filter((result) => result.success);
|
|
46
|
+
// TODO: presigned url expiry handling and failed files handling
|
|
47
|
+
return {
|
|
48
|
+
code: failedUploads.length > 0 ? 207 : 200, // 207 for partial success, 200 for all success
|
|
49
|
+
message: `Upload completed. ${successfulUploads.length}/${results.length} files uploaded successfully.`,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
console.error('uploadAudioFilesWithPresignedUrl error:', error);
|
|
54
|
+
return {
|
|
55
|
+
code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
|
|
56
|
+
message: `Upload failed: ${error}`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export default uploadFilesWithPresignedUrl;
|
|
@@ -329,6 +329,13 @@ class VadWebClient {
|
|
|
329
329
|
this.micVad.pause();
|
|
330
330
|
this.recording_started = false;
|
|
331
331
|
}
|
|
332
|
+
/**
|
|
333
|
+
* End VAD
|
|
334
|
+
*/
|
|
335
|
+
destroyVad() {
|
|
336
|
+
this.micVad.destroy();
|
|
337
|
+
this.recording_started = false;
|
|
338
|
+
}
|
|
332
339
|
/**
|
|
333
340
|
* reset vadWeb instance
|
|
334
341
|
*/
|
|
@@ -24,7 +24,8 @@ export declare enum ERROR_CODE {
|
|
|
24
24
|
NO_AUDIO_CAPTURE = "no_audio_capture",
|
|
25
25
|
SPEECH_DETECTED = "speech_detected",
|
|
26
26
|
TXN_STATUS_MISMATCH = "txn_status_mismatch",
|
|
27
|
-
LONG_SILENCE = "long_silence"
|
|
27
|
+
LONG_SILENCE = "long_silence",
|
|
28
|
+
GET_PRESIGNED_URL_FAILED = "get_presigned_url_failed"
|
|
28
29
|
}
|
|
29
30
|
export declare enum PROCESSING_STATUS {
|
|
30
31
|
SUCCESS = "success",
|
package/dist/constants/enums.js
CHANGED
|
@@ -28,6 +28,7 @@ export var ERROR_CODE;
|
|
|
28
28
|
ERROR_CODE["SPEECH_DETECTED"] = "speech_detected";
|
|
29
29
|
ERROR_CODE["TXN_STATUS_MISMATCH"] = "txn_status_mismatch";
|
|
30
30
|
ERROR_CODE["LONG_SILENCE"] = "long_silence";
|
|
31
|
+
ERROR_CODE["GET_PRESIGNED_URL_FAILED"] = "get_presigned_url_failed";
|
|
31
32
|
})(ERROR_CODE || (ERROR_CODE = {}));
|
|
32
33
|
export var PROCESSING_STATUS;
|
|
33
34
|
(function (PROCESSING_STATUS) {
|
|
@@ -56,6 +56,9 @@ export type TStartRecordingRequest = {
|
|
|
56
56
|
transfer: string;
|
|
57
57
|
system_info: TSystemInfo;
|
|
58
58
|
patient_details?: TPatientDetails;
|
|
59
|
+
model_type: string;
|
|
60
|
+
version?: string;
|
|
61
|
+
flavour?: string;
|
|
59
62
|
};
|
|
60
63
|
export type Gender = 'M' | 'F' | 'O';
|
|
61
64
|
export type TPatientDetails = {
|
|
@@ -105,7 +108,7 @@ export type TEndRecordingResponse = {
|
|
|
105
108
|
export type TPostTransactionInitRequest = {
|
|
106
109
|
mode: string;
|
|
107
110
|
s3Url: string;
|
|
108
|
-
|
|
111
|
+
txn_id: string;
|
|
109
112
|
input_language: string[];
|
|
110
113
|
output_format_template: {
|
|
111
114
|
template_id: string;
|
|
@@ -115,7 +118,15 @@ export type TPostTransactionInitRequest = {
|
|
|
115
118
|
model_training_consent: boolean;
|
|
116
119
|
system_info: TSystemInfo;
|
|
117
120
|
patient_details?: TPatientDetails;
|
|
121
|
+
model_type: string;
|
|
122
|
+
version?: string;
|
|
123
|
+
flavour?: string;
|
|
124
|
+
batch_s3_url?: string;
|
|
118
125
|
};
|
|
126
|
+
export interface TPostV1UploadAudioFilesRequest extends TPostTransactionInitRequest {
|
|
127
|
+
action: string;
|
|
128
|
+
audioFiles: File[] | Blob[];
|
|
129
|
+
}
|
|
119
130
|
export type TPostTransactionCommitRequest = {
|
|
120
131
|
audioFiles: string[];
|
|
121
132
|
txnId: string;
|
|
@@ -338,3 +349,26 @@ export type TPostV1ConvertToTemplateResponse = {
|
|
|
338
349
|
display_message: string;
|
|
339
350
|
};
|
|
340
351
|
};
|
|
352
|
+
export type TV1FileUploadFields = {
|
|
353
|
+
'x-amz-meta-mode': string;
|
|
354
|
+
key: string;
|
|
355
|
+
'x-amz-algorithm': string;
|
|
356
|
+
'x-amz-credential': string;
|
|
357
|
+
'x-amz-date': string;
|
|
358
|
+
policy: string;
|
|
359
|
+
'x-amz-signature': string;
|
|
360
|
+
};
|
|
361
|
+
export type TPostV1FileUploadResponse = {
|
|
362
|
+
uploadData: {
|
|
363
|
+
url: string;
|
|
364
|
+
fields: TV1FileUploadFields;
|
|
365
|
+
};
|
|
366
|
+
folderPath: string;
|
|
367
|
+
txn_id: string;
|
|
368
|
+
code?: number;
|
|
369
|
+
message?: string;
|
|
370
|
+
error?: {
|
|
371
|
+
code: string;
|
|
372
|
+
message: string;
|
|
373
|
+
};
|
|
374
|
+
};
|
|
@@ -10,4 +10,5 @@ export declare const GET_EKA_VOICE_HOST_V2: () => string;
|
|
|
10
10
|
export declare const GET_EKA_VOICE_HOST_V3: () => string;
|
|
11
11
|
export declare const GET_COOK_HOST_V1: () => string;
|
|
12
12
|
export declare const GET_COG_HOST: () => string;
|
|
13
|
+
export declare const GET_EKA_HOST: () => string;
|
|
13
14
|
export default setEnv;
|
|
@@ -4,6 +4,7 @@ const DEV = {
|
|
|
4
4
|
EKA_VOICE_HOST_V2: 'https://v2rxbe.dev.eka.care/voice/api/v2',
|
|
5
5
|
EKA_VOICE_HOST_V3: 'https://v2rxbe.dev.eka.care/voice/api/v3',
|
|
6
6
|
COOK_V1: ' https://deepthought-genai.dev.eka.care/api/v1',
|
|
7
|
+
EKA_HOST: 'https://api.dev.eka.care',
|
|
7
8
|
};
|
|
8
9
|
const PROD = {
|
|
9
10
|
COG_HOST: 'https://cog.eka.care',
|
|
@@ -11,6 +12,7 @@ const PROD = {
|
|
|
11
12
|
EKA_VOICE_HOST_V2: 'https://api.eka.care/voice/api/v2',
|
|
12
13
|
EKA_VOICE_HOST_V3: 'https://api.eka.care/voice/api/v3',
|
|
13
14
|
COOK_V1: ' https://cook.eka.care/api/v1',
|
|
15
|
+
EKA_HOST: 'https://api.eka.care',
|
|
14
16
|
};
|
|
15
17
|
let envVar = PROD;
|
|
16
18
|
let client_id = 'doc-web';
|
|
@@ -33,4 +35,5 @@ export const GET_EKA_VOICE_HOST_V2 = () => envVar.EKA_VOICE_HOST_V2;
|
|
|
33
35
|
export const GET_EKA_VOICE_HOST_V3 = () => envVar.EKA_VOICE_HOST_V3;
|
|
34
36
|
export const GET_COOK_HOST_V1 = () => envVar.COOK_V1;
|
|
35
37
|
export const GET_COG_HOST = () => envVar.COG_HOST;
|
|
38
|
+
export const GET_EKA_HOST = () => envVar.EKA_HOST;
|
|
36
39
|
export default setEnv;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TGetStatusResponse } from './api/transaction/get-voice-api-v3-status';
|
|
2
|
-
import { TEndRecordingResponse, TErrorCallback, TFileUploadProgressCallback, TGetTransactionHistoryResponse, TPatchTransactionRequest, TPatchVoiceApiV2ConfigRequest, TPostTransactionResponse, TPostV1ConvertToTemplateRequest, TPostV1TemplateRequest, TPostV1TemplateSectionRequest, TStartRecordingRequest } from './constants/types';
|
|
2
|
+
import { TEndRecordingResponse, TErrorCallback, TFileUploadProgressCallback, TGetTransactionHistoryResponse, TPatchTransactionRequest, TPatchVoiceApiV2ConfigRequest, TPostTransactionResponse, TPostV1ConvertToTemplateRequest, TPostV1TemplateRequest, TPostV1TemplateSectionRequest, TPostV1UploadAudioFilesRequest, TStartRecordingRequest } from './constants/types';
|
|
3
3
|
import { TSearchSessionsByPatientRequest } from './utils/search-sessions-by-patient-name';
|
|
4
4
|
declare class EkaScribe {
|
|
5
5
|
private static instance;
|
|
@@ -20,6 +20,7 @@ declare class EkaScribe {
|
|
|
20
20
|
initTransaction(request: TStartRecordingRequest): Promise<import("./constants/types").TStartRecordingResponse>;
|
|
21
21
|
startRecording(): Promise<import("./constants/types").TStartRecordingResponse>;
|
|
22
22
|
reinitializeVad(): void;
|
|
23
|
+
destroyVad(): void;
|
|
23
24
|
pauseRecording(): import("./constants/types").TPauseRecordingResponse;
|
|
24
25
|
resumeRecording(): import("./constants/types").TPauseRecordingResponse;
|
|
25
26
|
endRecording(): Promise<TEndRecordingResponse>;
|
|
@@ -64,6 +65,7 @@ declare class EkaScribe {
|
|
|
64
65
|
deleteTemplateSection(section_id: string): Promise<import("./constants/types").TPostV1TemplateSectionResponse>;
|
|
65
66
|
postTransactionConvertToTemplate({ txn_id, template_id }: TPostV1ConvertToTemplateRequest): Promise<import("./constants/types").TPostV1ConvertToTemplateResponse>;
|
|
66
67
|
searchSessionsByPatientName(request: TSearchSessionsByPatientRequest): Promise<unknown>;
|
|
68
|
+
uploadAudioWithPresignedUrl(request: TPostV1UploadAudioFilesRequest): Promise<import("./main/upload-full-audio-with-presigned-url").TFullAudioUploadResponse>;
|
|
67
69
|
}
|
|
68
70
|
export declare const getEkaScribeInstance: ({ access_token, env, clientId, }: {
|
|
69
71
|
access_token?: string;
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ import patchVoiceApiV2Config from './api/config/patch-voice-api-v2-config';
|
|
|
29
29
|
import cookV1MediaAiCreateTemplate from './api/templates/cook-v1-medai-ai-create-template';
|
|
30
30
|
import postV1ConvertToTemplate from './api/templates/post-transaction-convert-to-template';
|
|
31
31
|
import searchSessionsByPatient from './utils/search-sessions-by-patient-name';
|
|
32
|
+
import { postV1UploadAudioFiles } from './main/upload-full-audio-with-presigned-url';
|
|
32
33
|
class EkaScribe {
|
|
33
34
|
// Private constructor to prevent direct instantiation
|
|
34
35
|
constructor() {
|
|
@@ -103,6 +104,9 @@ class EkaScribe {
|
|
|
103
104
|
reinitializeVad() {
|
|
104
105
|
this.vadInstance.reinitializeVad();
|
|
105
106
|
}
|
|
107
|
+
destroyVad() {
|
|
108
|
+
this.vadInstance.destroyVad();
|
|
109
|
+
}
|
|
106
110
|
pauseRecording() {
|
|
107
111
|
console.log('Pausing recording...');
|
|
108
112
|
const pauseRecordingResponse = pauseVoiceRecording();
|
|
@@ -317,6 +321,10 @@ class EkaScribe {
|
|
|
317
321
|
const searchSessionsByPatientNameResponse = await searchSessionsByPatient(request);
|
|
318
322
|
return searchSessionsByPatientNameResponse;
|
|
319
323
|
}
|
|
324
|
+
async uploadAudioWithPresignedUrl(request) {
|
|
325
|
+
const uploadAudioFilesResponse = await postV1UploadAudioFiles(request);
|
|
326
|
+
return uploadAudioFilesResponse;
|
|
327
|
+
}
|
|
320
328
|
}
|
|
321
329
|
Object.defineProperty(EkaScribe, "instance", {
|
|
322
330
|
enumerable: true,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { TStartRecordingRequest, TStartRecordingResponse } from '../constants/types';
|
|
2
|
-
declare const initialiseTransaction: (
|
|
2
|
+
declare const initialiseTransaction: (request: TStartRecordingRequest) => Promise<TStartRecordingResponse>;
|
|
3
3
|
export default initialiseTransaction;
|
|
@@ -2,8 +2,9 @@ import postTransactionInit from '../api/transaction/post-transaction-init';
|
|
|
2
2
|
import { S3_BUCKET_NAME, SDK_STATUS_CODE } from '../constants/constant';
|
|
3
3
|
import { ERROR_CODE } from '../constants/enums';
|
|
4
4
|
import EkaScribeStore from '../store/store';
|
|
5
|
-
const initialiseTransaction = async (
|
|
5
|
+
const initialiseTransaction = async (request) => {
|
|
6
6
|
try {
|
|
7
|
+
const { txn_id } = request;
|
|
7
8
|
const fileManagerInstance = EkaScribeStore.audioFileManagerInstance;
|
|
8
9
|
const sessionStatus = EkaScribeStore.sessionStatus;
|
|
9
10
|
let businessID = '';
|
|
@@ -23,16 +24,8 @@ const initialiseTransaction = async ({ mode, input_language, output_format_templ
|
|
|
23
24
|
const filePath = `${year}${month}${day}/${txn_id}`;
|
|
24
25
|
EkaScribeStore.sessionBucketPath = filePath;
|
|
25
26
|
const txnInitResponse = await postTransactionInit({
|
|
26
|
-
|
|
27
|
-
txnId: txn_id,
|
|
27
|
+
...request,
|
|
28
28
|
s3Url: `s3://${S3_BUCKET_NAME}/${filePath}`,
|
|
29
|
-
input_language,
|
|
30
|
-
output_format_template,
|
|
31
|
-
transfer,
|
|
32
|
-
auto_download,
|
|
33
|
-
model_training_consent,
|
|
34
|
-
system_info,
|
|
35
|
-
patient_details,
|
|
36
29
|
});
|
|
37
30
|
const { code: txnInitStatusCode, b_id: businessId, oid, uuid, message: txnInitMessage, error: txnInitError, } = txnInitResponse;
|
|
38
31
|
if (txnInitStatusCode === 400 && txnInitError?.code === ERROR_CODE.TXN_LIMIT_EXCEEDED) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ERROR_CODE } from '../constants/enums';
|
|
2
|
+
import { TPostV1UploadAudioFilesRequest } from '../constants/types';
|
|
3
|
+
export type TFullAudioUploadResponse = {
|
|
4
|
+
error_code?: ERROR_CODE;
|
|
5
|
+
status_code: number;
|
|
6
|
+
message: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function postV1UploadAudioFiles({ audioFiles, txn_id, action, transfer, mode, s3Url, input_language, output_format_template, model_training_consent, auto_download, system_info, patient_details, model_type, version, flavour, }: TPostV1UploadAudioFilesRequest): Promise<TFullAudioUploadResponse>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import postV1FileUpload from '../api/post-v1-file-upload';
|
|
2
|
+
import postTransactionInit from '../api/transaction/post-transaction-init';
|
|
3
|
+
import uploadFilesWithPresignedUrl from '../api/upload-audio-with-presigned-url';
|
|
4
|
+
import { SDK_STATUS_CODE } from '../constants/constant';
|
|
5
|
+
import { ERROR_CODE } from '../constants/enums';
|
|
6
|
+
export async function postV1UploadAudioFiles({ audioFiles, txn_id, action, transfer, mode, s3Url, input_language, output_format_template, model_training_consent, auto_download, system_info, patient_details, model_type, version, flavour, }) {
|
|
7
|
+
try {
|
|
8
|
+
// Step 1: Get presigned URL
|
|
9
|
+
const presignedUrlResponse = await postV1FileUpload({ txn_id, action });
|
|
10
|
+
if (presignedUrlResponse.code !== 200) {
|
|
11
|
+
return {
|
|
12
|
+
error_code: ERROR_CODE.GET_PRESIGNED_URL_FAILED,
|
|
13
|
+
status_code: presignedUrlResponse.code || SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
|
|
14
|
+
message: presignedUrlResponse.message || 'Get presigned URL failed',
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
// Step 2: Upload files using the presigned URL
|
|
18
|
+
const uploadResponse = await uploadFilesWithPresignedUrl({
|
|
19
|
+
audioFiles,
|
|
20
|
+
presignedUrlResponse,
|
|
21
|
+
});
|
|
22
|
+
if (uploadResponse.code !== 200) {
|
|
23
|
+
return {
|
|
24
|
+
error_code: ERROR_CODE.AUDIO_UPLOAD_FAILED,
|
|
25
|
+
status_code: uploadResponse.code || SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
|
|
26
|
+
message: uploadResponse.message || 'File uploaded.',
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const batch_s3_url = presignedUrlResponse.uploadData.url + presignedUrlResponse.folderPath;
|
|
30
|
+
const initTransactionResponse = await postTransactionInit({
|
|
31
|
+
mode,
|
|
32
|
+
txn_id,
|
|
33
|
+
s3Url,
|
|
34
|
+
input_language,
|
|
35
|
+
output_format_template,
|
|
36
|
+
model_training_consent,
|
|
37
|
+
auto_download,
|
|
38
|
+
transfer,
|
|
39
|
+
system_info,
|
|
40
|
+
patient_details,
|
|
41
|
+
model_type,
|
|
42
|
+
version,
|
|
43
|
+
flavour,
|
|
44
|
+
batch_s3_url,
|
|
45
|
+
});
|
|
46
|
+
if (initTransactionResponse.code >= 400) {
|
|
47
|
+
return {
|
|
48
|
+
error_code: ERROR_CODE.TXN_INIT_FAILED,
|
|
49
|
+
status_code: initTransactionResponse.code || SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
|
|
50
|
+
message: initTransactionResponse.message || 'Transaction initialization failed.',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
status_code: SDK_STATUS_CODE.SUCCESS,
|
|
55
|
+
message: 'Transaction initialized successfully.',
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error('getPresignedUrlAndUploadFiles error:', error);
|
|
60
|
+
return {
|
|
61
|
+
error_code: ERROR_CODE.INTERNAL_SERVER_ERROR,
|
|
62
|
+
status_code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
|
|
63
|
+
message: `Complete upload workflow failed: ${error}`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|