-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
72 lines (68 loc) · 2.33 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import axios from 'axios';
interface IvideoObj{
fileName:string;
credentials:{
accessKey:string;
secretAccessKey:string;
}
}
const errorObj={error:'Invalid credentials or not sufficient amount or error fileName'};
export const VideoUploadUrl=async (video:IvideoObj)=>{
try {
axios.post('https://api.suryanshverma.site/api/v1/upload-video',{fileName:video.fileName,credentials:video.credentials})
.then((res)=>{
const responseObj={
uploadUrl:res.data.uploadUrl,
fileName:res.data.fileName
}
return responseObj;
})
.catch((err)=>{
return errorObj;
})
} catch (error) {
return errorObj
}
}
interface ItranscodingProps{
fileName:string;
awsCredentials:{
accessKey:string;
secretAccessKey:string;
}
bucketPath:string;
bucketName:string;
email:string;
credentials:{
accessKey:string;
secretAccessKey:string;
}
}
export const TranscodeVideo=async(transcodingProps:ItranscodingProps)=>{
try {
const transcodingPropsObj={
videoKey:`outputs/${transcodingProps.fileName}`,
userAccessKey:transcodingProps.awsCredentials.accessKey,
userSecretAccessKey:transcodingProps.awsCredentials.secretAccessKey,
bucketPath:transcodingProps.bucketPath,
userBucketName:transcodingProps.bucketName,
email:transcodingProps.email,
credentials:transcodingProps.credentials
}
axios.post('https://api.suryanshverma.site/api/v1/transcoding-video',{transcodingPropsObj})
.then((res)=>{
const resP= {
success:true,
message:'transcoding process is queued. when transcoding completes we will notify through email',
videoPath:`https://s3.<yourregionName>..amazonaws.com/${transcodingProps.bucketName}/${transcodingProps.bucketPath}/outputs/master.m3u8`
}
return resP;
}).catch((err)=>{
const error={error:'Invalid credentials or not sufficient amount or error fileName'}
return error;
})
} catch (error) {
const errorP={error:'Invalid credentials or not sufficient amount or error fileName'}
return errorP;
}
}