Add Face Plugin's Face Manager customAutoLib framework
- currently API methods only, no UI yetbuild-default-monitor-config-from-definitions
parent
cd9b8a2e5e
commit
051c7abf99
|
@ -0,0 +1,121 @@
|
|||
var fileUpload = require('express-fileupload')
|
||||
module.exports = function(s,config,lang,app,io){
|
||||
if(!config.facesFolder)config.facesFolder = s.mainDirectory + '/plugins/face/faces/'
|
||||
config.facesFolder = s.checkCorrectPathEnding(config.facesFolder)
|
||||
const sendDataToConnectedSuperUsers = (data) => {
|
||||
return s.tx(data,'$')
|
||||
}
|
||||
const getFaceFolderNames = (callback) => {
|
||||
fs.readdir(config.facesFolder,(err,folders) => {
|
||||
var faces = []
|
||||
folders.forEach((folder)=>{
|
||||
var stats = fs.statSync(config.facesFolder + folder)
|
||||
if(stats.isDirectory()){
|
||||
faces.push(folder)
|
||||
}
|
||||
})
|
||||
callback(faces)
|
||||
})
|
||||
}
|
||||
const getFaceImages = (callback) => {
|
||||
fs.readdir(config.facesFolder,(err,folders)=>{
|
||||
var faces = {}
|
||||
folders.forEach((name)=>{
|
||||
var stats = fs.statSync(config.facesFolder + name)
|
||||
if(stats.isDirectory()){
|
||||
faces[name] = []
|
||||
fs.readdir(config.facesFolder + name,(err,images)=>{
|
||||
images.forEach((image)=>{
|
||||
faces[name].push(image)
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
callback(faces)
|
||||
})
|
||||
}
|
||||
app.get(config.webPaths.superApiPrefix+':auth/faceManager/names', function (req,res){
|
||||
s.superAuth(req.params,function(resp){
|
||||
getFaceFolderNames((faces)=>{
|
||||
res.end(s.prettyPrint({
|
||||
ok: true,
|
||||
faces: faces
|
||||
}))
|
||||
})
|
||||
},res,req)
|
||||
})
|
||||
app.get(config.webPaths.superApiPrefix+':auth/faceManager/images', function (req,res){
|
||||
s.superAuth(req.params,function(resp){
|
||||
getFaceImages((faces)=>{
|
||||
res.end(s.prettyPrint({
|
||||
ok: true,
|
||||
faces: faces
|
||||
}))
|
||||
})
|
||||
},res,req)
|
||||
})
|
||||
app.get(config.webPaths.superApiPrefix+':auth/faceManager/image/:name/:image', function (req,res){
|
||||
s.superAuth(req.params,function(resp){
|
||||
const imagePath = config.facesFolder + req.params.name + '/' + req.params.image
|
||||
if(fs.existsSync(imagePath)){
|
||||
res.setHeader('Content-Type', 'image/jpeg')
|
||||
fs.createReadStream(imagePath).pipe(res)
|
||||
}else{
|
||||
res.setHeader('Content-Type', 'application/json')
|
||||
res.end(s.prettyPrint({
|
||||
ok: false,
|
||||
msg: lang['File Not Found']
|
||||
}))
|
||||
}
|
||||
},res,req)
|
||||
})
|
||||
app.get(config.webPaths.superApiPrefix+':auth/faceManager/image/:name/:image/delete', function (req,res){
|
||||
s.superAuth(req.params,function(resp){
|
||||
const imagePath = config.facesFolder + req.params.name + '/' + req.params.image
|
||||
if(fs.existsSync(imagePath)){
|
||||
fs.unlink(imagePath,() => {
|
||||
s.file('delete',imagePath)
|
||||
sendDataToConnectedSuperUsers({
|
||||
f:'faceManagerImageDeleted',
|
||||
faceName: req.params.name,
|
||||
fileName: req.params.image,
|
||||
url: fileLink
|
||||
})
|
||||
})
|
||||
}
|
||||
res.end(s.prettyPrint({
|
||||
ok: true,
|
||||
}))
|
||||
},res,req)
|
||||
})
|
||||
app.post(config.webPaths.superApiPrefix+':auth/faceManager/image/:name', fileUpload(), function (req,res){
|
||||
s.superAuth(req.params,function(resp){
|
||||
res.setHeader('Content-Type', 'application/json')
|
||||
var fileKeys = Object.keys(req.files)
|
||||
if(fileKeys.length == 0){
|
||||
return res.status(400).send('No files were uploaded.')
|
||||
}
|
||||
var filesUploaded = []
|
||||
fileKeys.forEach(function(key){
|
||||
var file = req.files[key]
|
||||
if(file.name.indexOf('.jpg') > -1 || file.name.indexOf('.jpeg') > -1){
|
||||
filesUploaded.push(file.name)
|
||||
file.mv(config.facesFolder + req.params.name + '/' + file.name, function(err) {
|
||||
var fileLink = config.webPaths.superApiPrefix + req.params.auth + `/faceManager/image/${req.params.name}/${file.name}`
|
||||
sendDataToConnectedSuperUsers({
|
||||
f:'faceManagerImageUploaded',
|
||||
faceName: req.params.name,
|
||||
fileName: file.name,
|
||||
url: fileLink
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
var response = {
|
||||
ok: true,
|
||||
filesUploaded: filesUploaded
|
||||
}
|
||||
res.send(s.prettyPrint(response))
|
||||
},res,req)
|
||||
})
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"faceManager": "Face Manager"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
$(document).ready(function(){
|
||||
$('#tablist').append('<li class="nav-item">\
|
||||
<a class="nav-link" data-toggle="modal" data-target="#faceManager">' + lang.faceManager + '</a>\
|
||||
</li>')
|
||||
})
|
|
@ -0,0 +1,18 @@
|
|||
<div class="modal full fade search-parent" id="faceManager" role="dialog" aria-labelledby="faceManagerLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
<h4 class="modal-title" id="faceManagerLabel"><i class="fa fa-pencil-square-o"></i> <%-lang.faceManager%></h4>
|
||||
</div>
|
||||
<div class="modal-body overflow-hidden">
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue