-
Notifications
You must be signed in to change notification settings - Fork 10
/
server.js
70 lines (62 loc) · 3.22 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
const express = require('express')
const path = require('path')
const { get } = require('request')
const app = express()
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
const viewsDir = path.join(__dirname, 'views')
app.use(express.static(viewsDir))
app.use(express.static(path.join(__dirname, './public')))
app.use(express.static(path.join(__dirname, './public/images')))
app.use(express.static(path.join(__dirname, './public/media')))
app.use(express.static(path.join(__dirname, './models')))
app.use(express.static(path.join(__dirname, './dist')))
app.get('/', (req, res) => res.redirect('/face_and_landmark_detection'))
app.get('/face_and_landmark_detection', (req, res) => res.sendFile(path.join(viewsDir, 'faceAndLandmarkDetection.html')))
app.get('/face_extraction', (req, res) => res.sendFile(path.join(viewsDir, 'faceExtraction.html')))
app.get('/face_recognition', (req, res) => res.sendFile(path.join(viewsDir, 'faceRecognition.html')))
app.get('/video_face_tracking', (req, res) => res.sendFile(path.join(viewsDir, 'videoFaceTracking.html')))
app.get('/webcam_face_tracking', (req, res) => res.sendFile(path.join(viewsDir, 'webcamFaceTracking.html')))
app.get('/bbt_face_landmark_detection', (req, res) => res.sendFile(path.join(viewsDir, 'bbtFaceLandmarkDetection.html')))
app.get('/bbt_face_similarity', (req, res) => res.sendFile(path.join(viewsDir, 'bbtFaceSimilarity.html')))
app.get('/bbt_face_matching', (req, res) => res.sendFile(path.join(viewsDir, 'bbtFaceMatching.html')))
app.get('/bbt_face_recognition', (req, res) => res.sendFile(path.join(viewsDir, 'bbtFaceRecognition.html')))
app.get('/batch_face_landmarks', (req, res) => res.sendFile(path.join(viewsDir, 'batchFaceLandmarks.html')))
app.get('/batch_face_recognition', (req, res) => res.sendFile(path.join(viewsDir, 'batchFaceRecognition.html')))
app.get('/simplify_face_comparison', (req, res) => res.sendFile(path.join(viewsDir, 'simplifyFaceComparison.html')))
app.get('/simplify_face_comparison_many', (req, res) => res.sendFile(path.join(viewsDir, 'simplifyFaceComparisonMany.html')))
app.get('/simplify_webrtc_face_trackimg', (req, res) => res.sendFile(path.join(viewsDir, 'simplifyWebRTCFaceTracking.html')))
app.post('/fetch_external_image', async (req, res) => {
const { imageUrl } = req.body
if (!imageUrl) {
return res.status(400).send('imageUrl param required')
}
try {
const externalResponse = await request(imageUrl)
res.set('content-type', externalResponse.headers['content-type'])
return res.status(202).send(Buffer.from(externalResponse.body))
} catch (err) {
return res.status(404).send(err.toString())
}
})
app.listen(3000, () => console.log('Listening on port 3000!'))
function request(url, returnBuffer = true, timeout = 10000) {
return new Promise(function(resolve, reject) {
const options = Object.assign(
{},
{
url,
isBuffer: true,
timeout,
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER'
}
},
returnBuffer ? { encoding: null } : {}
)
get(options, function(err, res) {
if (err) return reject(err)
return resolve(res)
})
})
}