-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting.js
68 lines (58 loc) · 2.07 KB
/
testing.js
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
const extension = mime.extension(mimetype);
/**
* Check for extension
*/
if (!extension || !VALID_VIDEO_EXTENSIONS.includes(extension)) {
return res.send({ error: 'Video format is not supported.' });
}
const videoId = uuidv4();
/**
* Save the incoming file in uploads folder
*/
fs.mkdirSync(path.resolve('uploads', videoId));
const videoFilePath = path.resolve('temp', `${videoId}.${extension}`);
fs.writeFileSync(videoFilePath, buffer);
const child = fork("video.js");
const newname=`${videoId}.${extension}`
child.send({name:newname,videoId:videoId});
// Listen for message from child process
child.on("message", async(message) => {
if(message.statusCode==200)
{
const createHLSVOD = spawn('bash', ['create-hls-vod.sh', videoId, extension, S3_URL]);
createHLSVOD.stdout.on('data', d => console.log(`stdout info: ${d}`));
createHLSVOD.stderr.on('data', d => console.log(`stderr error: ${d}`));
createHLSVOD.on('error', d => console.log(`error: ${d}`));
createHLSVOD.on('close', code => {
res.send({status:200,message:"UPLOADED SUCCESSFULLY"})
});
if(!file[1])
{
}
else
{
const extension_thumb = mime.extension(file[1].mimetype);
const thumbnailpath = path.resolve(`uploads/${videoId}/`, `thumbnail.${extension_thumb}`);
fs.writeFileSync(thumbnailpath, file[1].buffer);
}
if(!file[2])
{
}
else
{
const extension_shop = mime.extension(file[2].mimetype);
const shoppath = path.resolve(`uploads/${videoId}/`, `shopimg.${extension_shop}`);
fs.writeFileSync(shoppath, file[2].buffer);
}
postBody={
userId:req.payload.aud,
userType:"CREATOR",
fileURLS:[videoId],
createdOn:new Date(),
caption:"",
totalLikes:0,
}
const post = new Post(postBody)
const savedPost = await post.save();
}
})