-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
243 lines (217 loc) · 8.61 KB
/
app.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
const express = require('express');
const app = express();
const { validateParams } = require('./src/lib/validateParams');
const dyVideoParserService = require('./src/service/dyVideoParserService');
const tkVideoParserService = require('./src/service/tkVideoParserService');
const utilsService = require('./src/service/utilsService');
const Response = require('./src/lib/Response');
const Errors = require('./src/lib/Errors');
app.use(express.json());
app.post('/api/dy/originalUrlFetch', validateParams(['share_info']), async (req, res) => {
const { share_info } = req.body;
if (share_info.indexOf('http') === -1) {
return new Response(res).result(Errors.PARAMS_VALIDATE_FAIL, 'share_info not contain url')
}
try {
const data = await dyVideoParserService.originalUrlFetch(share_info);
if (!data) {
return new Response(res).fail('original url fetch Error')
}
new Response(res).success(data);
}catch (e) {
new Response(res).fail('original url fetch Error', e.message);
}
});
app.post('/api/dy/fetchLiveRoomInfo', validateParams(['live_url']), async (req, res) => {
const { live_url } = req.body;
if (live_url.indexOf('http') === -1) {
return new Response(res).result(Errors.PARAMS_VALIDATE_FAIL, 'live_url not contain url')
}
try {
const data = await dyVideoParserService.fetchLiveRoomInfo(live_url);
if (!data) {
return new Response(res).fail('fetch live room info Error')
}
new Response(res).success(data);
}catch (e) {
new Response(res).fail('fetch live room info Error', e.message);
}
});
app.get('/api/dy/generalSearch', validateParams(['keyword', 'sort_type', 'publish_time', 'offset', 'count']), async (req, res) => {
const { keyword, sort_type, publish_time, offset, count } = req.query;
try {
const data = await dyVideoParserService.generalSearch(keyword, sort_type, publish_time, offset, count);
if (!data) {
return new Response(res).fail('general search Error')
}
new Response(res).success(data);
}catch (e) {
new Response(res).fail('general search Error', e.message);
}
});
app.get('/api/dy/videoSearch', validateParams(['keyword', 'sort_type', 'publish_time', 'offset', 'count']), async (req, res) => {
const { keyword, sort_type, publish_time, offset, count } = req.query;
try {
const data = await dyVideoParserService.videoSearch(keyword, sort_type, publish_time, offset, count);
if (!data) {
return new Response(res).fail('video search Error')
}
new Response(res).success(data);
}catch (e) {
new Response(res).fail('video search Error', e.message);
}
});
app.get('/api/dy/topicSearch', validateParams(['keyword', 'sort_type', 'publish_time', 'offset', 'count']), async (req, res) => {
const { keyword, sort_type, publish_time, offset, count } = req.query;
try {
const data = await dyVideoParserService.topicSearch(keyword, sort_type, publish_time, offset, count);
if (!data) {
return new Response(res).fail('topic search Error')
}
new Response(res).success(data);
}catch (e) {
new Response(res).fail('topic search Error', e.message);
}
});
app.get('/api/dy/getUserVideos', validateParams(['sec_uid', 'count', 'max_cursor']), async (req, res) => {
const { sec_uid, count, max_cursor } = req.query;
try {
const data = await dyVideoParserService.getUserVideos(sec_uid, count, max_cursor);
if (!data) {
return new Response(res).fail('get user videos Error');
}
new Response(res).success(data);
}catch (e) {
new Response(res).fail('get user videos Error', e.message);
}
});
app.get('/api/dy/getUserInfo', validateParams(['sec_uid']), async (req, res) => {
const { sec_uid } = req.query;
try {
const data = await dyVideoParserService.getUserInfo(sec_uid);
if (!data) {
return new Response(res).fail('get user info Error');
}
new Response(res).success(data);
}catch (e) {
new Response(res).fail('get user info Error', e.message);
}
});
app.get('/api/dy/getVideoComments', validateParams(['aweme_id', 'count', 'cursor']), async (req, res) => {
const { aweme_id, count, cursor } = req.query;
try {
const data = await dyVideoParserService.getVideoComments(aweme_id, count, cursor);
if (!data) {
return new Response(res).fail('get video comments Error');
}
new Response(res).success(data);
}catch (e) {
new Response(res).fail('get video comments Error', e.message);
}
});
app.get('/api/dy/getVideoDetail', validateParams(['aweme_id']), async (req, res) => {
const { aweme_id } = req.query;
try {
const data = await dyVideoParserService.getVideoDetail(aweme_id);
if (!data) {
return new Response(res).fail('get video detail Error');
}
new Response(res).success(data);
}catch (e) {
new Response(res).fail('get video detail Error', e.message);
}
});
app.get('/api/dy/getUserVideosSimpleRecent', validateParams(['sec_uid']), async (req, res) => {
const { sec_uid } = req.query;
try {
const data = await dyVideoParserService.getUserVideosSimpleRecent(sec_uid);
if (!data) {
return new Response(res).fail('get user videos simple recent Error');
}
new Response(res).success(data);
}catch (e) {
new Response(res).fail('get user videos simple recent Error', e.message);
}
});
app.post('/api/tk/originalUrlFetch', validateParams(['share_info']), async (req, res) => {
const { share_info } = req.body;
if (share_info.indexOf('http') === -1) {
return new Response(res).result(Errors.PARAMS_VALIDATE_FAIL, 'share_info not contain url')
}
try {
const data = await tkVideoParserService.originalUrlFetch(share_info);
if (!data) {
return new Response(res).fail('original url fetch Error')
}
new Response(res).success(data);
}catch (e) {
new Response(res).fail('original url fetch Error', e.message);
}
});
app.post('/api/tk/fetchLiveRoomInfo', validateParams(['live_url']), async (req, res) => {
const { live_url } = req.body;
if (live_url.indexOf('http') === -1) {
return new Response(res).result(Errors.PARAMS_VALIDATE_FAIL, 'live_url not contain url')
}
try {
const data = await tkVideoParserService.fetchLiveRoomInfo(live_url);
if (!data) {
return new Response(res).fail('fetch live room info Error')
}
new Response(res).success(data);
}catch (e) {
new Response(res).fail('fetch live room info Error', e.message);
}
});
app.get('/api/tk/getUserVideos', validateParams(['sec_uid', 'count', 'cursor']), async (req, res) => {
const { sec_uid, count, cursor } = req.query;
try {
const data = await tkVideoParserService.getUserVideos(sec_uid, count, cursor);
if (!data) {
return new Response(res).fail('get user videos Error');
}
new Response(res).success(data);
}catch (e) {
new Response(res).fail('get user videos Error', e.message);
}
});
app.get('/api/tk/getUserInfo', validateParams(['unique_id']), async (req, res) => {
const {unique_id} = req.query;
try {
const data = await tkVideoParserService.getUserInfo(unique_id);
if (!data) {
return new Response(res).fail('get user info Error');
}
new Response(res).success(data);
} catch (e) {
new Response(res).fail('get user info Error', e.message);
}
});
app.get('/api/tk/getVideoDetail', validateParams(['aweme_id']), async (req, res) => {
const { aweme_id } = req.query;
try {
const data = await tkVideoParserService.getVideoDetail(aweme_id);
if (!data) {
return new Response(res).fail('get video detail Error');
}
new Response(res).success(data);
}catch (e) {
new Response(res).fail('get video detail Error', e.message);
}
});
app.get('/api/utils/queryIp', validateParams(['host']), async (req, res) => {
const { host } = req.query;
try {
const data = await utilsService.queryIp(host);
if (!data) {
return new Response(res).fail('query ip Error');
}
new Response(res).success(data);
}catch (e) {
new Response(res).fail('query ip Error', e.message);
}
});
app.listen(3000, () => {
console.log('API server is running on port 3000');
console.log('http://localhost:3000');
});