-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
116 lines (101 loc) · 2.7 KB
/
server.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const aws = require('aws-sdk');
const express = require('express');
const multer = require('multer');
const multerS3 = require('multer-s3');
const cors = require('cors');
const app = express();
app.use(cors());
const spacesEndpoint = new aws.Endpoint('http://s3-us-east-2.amazonaws.com/vyden');
const s3 = new aws.S3({
endpoint: spacesEndpoint
});
const uploadVideo = multer({
storage: multerS3({
s3: s3,
bucket: 'vyden',
acl: 'public-read',
key: function (request, file, cb) {
console.log(file);
cb(null, "videos/" + file.originalname);
}
}),
limits: { fileSize: 1000000000 }
}).array('upload',1);
app.post('/uploadVideo', function (request, response, next) {
uploadVideo(request, response, function (error) {
if (error) {
console.log(error);
return response.json({message: error});
}
console.log('File uploaded successfully.');
response.json({message: "Success"});
});
});
const uploadAudio = multer({
storage: multerS3({
s3: s3,
bucket: 'vyden',
acl: 'public-read',
key: function (request, file, cb) {
console.log(file);
cb(null, "audios/" + file.originalname);
}
})
}).array('upload', 1);
app.post('/uploadAudio', function (request, response, next) {
uploadAudio(request, response, function (error) {
if (error) {
console.log(error);
return response.json({message: error});
}
console.log('File uploaded successfully.');
response.json({message: "success"});
});
});
const uploadModel = multer({
storage: multerS3({
s3: s3,
bucket: 'vyden',
acl: 'public-read',
key: function (request, file, cb) {
console.log(file);
cb(null, "models/" + file.originalname);
}
}),
limits: { fileSize: 25000000 }
}).array('upload', 1);
app.post('/uploadModel' ,function (req, res) {
uploadModel(req, res, function (error) {
if (error) {
console.log(error);
return res.json({message: error});
}
console.log('File uploaded successfully.');
res.json({message: "Success"});
});
});
const uploadSrt = multer({
storage: multerS3({
s3: s3,
bucket: 'vyden',
acl: 'public-read',
key: function (request, file, cb) {
console.log(file);
cb(null, "srts/" + file.originalname);
}
}),
limits: { fileSize: 25000000 }
}).array('upload', 1);
app.post('/uploadSrt' ,function (req, res) {
uploadSrt(req, res, function (error) {
if (error) {
console.log(error);
return res.json({message: error});
}
console.log('File uploaded successfully.');
res.json({message: "Success"});
});
});
app.listen(3001, function () {
console.log('Server listening on port 3001.');
});