update
parent
6051d86d4d
commit
c121965515
File diff suppressed because one or more lines are too long
|
@ -1292,7 +1292,7 @@
|
|||
]
|
||||
},
|
||||
"package.json": {
|
||||
"bytes": 1839,
|
||||
"bytes": 1841,
|
||||
"imports": []
|
||||
},
|
||||
"src/xception/extractParams.ts": {
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1292,7 +1292,7 @@
|
|||
]
|
||||
},
|
||||
"package.json": {
|
||||
"bytes": 1839,
|
||||
"bytes": 1841,
|
||||
"imports": []
|
||||
},
|
||||
"src/xception/extractParams.ts": {
|
||||
|
@ -2591,7 +2591,7 @@
|
|||
"imports": [],
|
||||
"exports": [],
|
||||
"inputs": {},
|
||||
"bytes": 1445525
|
||||
"bytes": 1445459
|
||||
},
|
||||
"dist/face-api.esm.js": {
|
||||
"imports": [],
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1292,7 +1292,7 @@
|
|||
]
|
||||
},
|
||||
"package.json": {
|
||||
"bytes": 1839,
|
||||
"bytes": 1841,
|
||||
"imports": []
|
||||
},
|
||||
"src/xception/extractParams.ts": {
|
||||
|
@ -2591,7 +2591,7 @@
|
|||
"imports": [],
|
||||
"exports": [],
|
||||
"inputs": {},
|
||||
"bytes": 1445532
|
||||
"bytes": 1445466
|
||||
},
|
||||
"dist/face-api.js": {
|
||||
"imports": [],
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1292,7 +1292,7 @@
|
|||
]
|
||||
},
|
||||
"package.json": {
|
||||
"bytes": 1839,
|
||||
"bytes": 1841,
|
||||
"imports": []
|
||||
},
|
||||
"src/xception/extractParams.ts": {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1292,7 +1292,7 @@
|
|||
]
|
||||
},
|
||||
"package.json": {
|
||||
"bytes": 1839,
|
||||
"bytes": 1841,
|
||||
"imports": []
|
||||
},
|
||||
"src/xception/extractParams.ts": {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -396,7 +396,7 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"(disabled):/home/vlado/dev/face-api/node_modules/node-fetch/browser.js": {
|
||||
"(disabled):node_modules/node-fetch/browser.js": {
|
||||
"bytes": 0,
|
||||
"imports": []
|
||||
},
|
||||
|
@ -408,7 +408,7 @@
|
|||
"kind": "import-statement"
|
||||
},
|
||||
{
|
||||
"path": "(disabled):/home/vlado/dev/face-api/node_modules/node-fetch/browser.js",
|
||||
"path": "(disabled):node_modules/node-fetch/browser.js",
|
||||
"kind": "require-call"
|
||||
}
|
||||
]
|
||||
|
@ -15661,7 +15661,7 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"(disabled):/home/vlado/dev/face-api/node_modules/string_decoder/lib/string_decoder.js": {
|
||||
"(disabled):node_modules/string_decoder/lib/string_decoder.js": {
|
||||
"bytes": 0,
|
||||
"imports": []
|
||||
},
|
||||
|
@ -15681,7 +15681,7 @@
|
|||
"kind": "import-statement"
|
||||
},
|
||||
{
|
||||
"path": "(disabled):/home/vlado/dev/face-api/node_modules/string_decoder/lib/string_decoder.js",
|
||||
"path": "(disabled):node_modules/string_decoder/lib/string_decoder.js",
|
||||
"kind": "require-call"
|
||||
}
|
||||
]
|
||||
|
@ -25347,7 +25347,7 @@
|
|||
"imports": [],
|
||||
"exports": [],
|
||||
"inputs": {},
|
||||
"bytes": 1127308
|
||||
"bytes": 1127242
|
||||
},
|
||||
"dist/tfjs.esm.js": {
|
||||
"imports": [],
|
||||
|
@ -25816,7 +25816,7 @@
|
|||
"zerosLike"
|
||||
],
|
||||
"inputs": {
|
||||
"(disabled):/home/vlado/dev/face-api/node_modules/node-fetch/browser.js": {
|
||||
"(disabled):node_modules/node-fetch/browser.js": {
|
||||
"bytesInOutput": 18
|
||||
},
|
||||
"node_modules/seedrandom/lib/alea.js": {
|
||||
|
@ -25846,7 +25846,7 @@
|
|||
"node_modules/seedrandom/index.js": {
|
||||
"bytesInOutput": 177
|
||||
},
|
||||
"(disabled):/home/vlado/dev/face-api/node_modules/string_decoder/lib/string_decoder.js": {
|
||||
"(disabled):node_modules/string_decoder/lib/string_decoder.js": {
|
||||
"bytesInOutput": 18
|
||||
},
|
||||
"(disabled):path": {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>FaceAPI Static Images Demo</title>
|
||||
<meta http-equiv="content-type">
|
||||
<meta charset="utf-8">
|
||||
<meta content="text/html">
|
||||
<meta charset="UTF-8">
|
||||
<title>FaceAPI Static Images Demo</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=yes">
|
||||
<script src="./index.js" type="module"></script>
|
||||
</head>
|
||||
<body style="font-family: monospace; background: black; color: white; font-size: 16px; line-height: 22px; margin: 0;">
|
||||
|
|
|
@ -2,6 +2,7 @@ import * as faceapi from '../dist/face-api.esm.js';
|
|||
|
||||
// configuration options
|
||||
const modelPath = 'https://vladmandic.github.io/face-api/model/'; // path to model folder that will be loaded using http
|
||||
// const modelPath = '../model/'; // path to model folder that will be loaded using http
|
||||
const imgSize = 512; // maximum image size in pixels
|
||||
const minScore = 0.1; // minimum score
|
||||
const maxResults = 5; // maximum number of results to return
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>FaceAPI Live WebCam Demo</title>
|
||||
<meta http-equiv="content-type">
|
||||
<meta charset="utf-8">
|
||||
<meta content="text/html">
|
||||
<meta charset="UTF-8">
|
||||
<title>FaceAPI Live WebCam Demo</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=yes">
|
||||
<script src="./webcam.js" type="module"></script>
|
||||
</head>
|
||||
<body style="font-family: monospace; background: black; color: white; font-size: 16px; line-height: 22px; margin: 0;">
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
"requires": true,
|
||||
"dependencies": {
|
||||
"@babel/code-frame": {
|
||||
"version": "7.12.13",
|
||||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.12.13.tgz",
|
||||
"integrity": "sha512-HV1Cm0Q3ZrpCR93tkWOYiuYIgLxZXZFVG2VgK+MBWjUqZTundupbfx2aXarXuw5Ko5aMcjtJgbSs4vUGBS5v6g==",
|
||||
"version": "7.12.11",
|
||||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.12.11.tgz",
|
||||
"integrity": "sha512-Zt1yodBx1UcyiePMSkWnU4hPqhwq7hGi2nFL1LeA3EUl+q2LQx16MISgJ0+z7dnmgvP9QtIleuETGOiOH1RcIw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/highlight": "^7.12.13"
|
||||
"@babel/highlight": "^7.10.4"
|
||||
}
|
||||
},
|
||||
"@babel/helper-validator-identifier": {
|
||||
|
@ -963,9 +963,9 @@
|
|||
}
|
||||
},
|
||||
"esbuild": {
|
||||
"version": "0.8.44",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.8.44.tgz",
|
||||
"integrity": "sha512-m9yyBZMgWuAB7e7tA2g9L4PovoLa5Xb73+Yg9uBBR2w3Fe4P9/nxqj/HLrw1k/rjdjF1eX1kNJRytboqOtRCCQ==",
|
||||
"version": "0.8.45",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.8.45.tgz",
|
||||
"integrity": "sha512-AhR+h/Kat9QMssi0rSJIei0yR+dJ0DQ5aDqnZy4VLu9kOBHdJh8vDSE2XzUlwnm4umvMFnfQTELZlsH7Zmvksw==",
|
||||
"dev": true
|
||||
},
|
||||
"escalade": {
|
||||
|
@ -981,12 +981,12 @@
|
|||
"dev": true
|
||||
},
|
||||
"eslint": {
|
||||
"version": "7.19.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-7.19.0.tgz",
|
||||
"integrity": "sha512-CGlMgJY56JZ9ZSYhJuhow61lMPPjUzWmChFya71Z/jilVos7mR/jPgaEfVGgMBY5DshbKdG8Ezb8FDCHcoMEMg==",
|
||||
"version": "7.20.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-7.20.0.tgz",
|
||||
"integrity": "sha512-qGi0CTcOGP2OtCQBgWZlQjcTuP0XkIpYFj25XtRTQSHC+umNnp7UMshr2G8SLsRFYDdAPFeHOsiteadmMH02Yw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/code-frame": "^7.0.0",
|
||||
"@babel/code-frame": "7.12.11",
|
||||
"@eslint/eslintrc": "^0.3.0",
|
||||
"ajv": "^6.10.0",
|
||||
"chalk": "^4.0.0",
|
||||
|
@ -998,7 +998,7 @@
|
|||
"eslint-utils": "^2.1.0",
|
||||
"eslint-visitor-keys": "^2.0.0",
|
||||
"espree": "^7.3.1",
|
||||
"esquery": "^1.2.0",
|
||||
"esquery": "^1.4.0",
|
||||
"esutils": "^2.0.2",
|
||||
"file-entry-cache": "^6.0.0",
|
||||
"functional-red-black-tree": "^1.0.1",
|
||||
|
@ -2646,9 +2646,9 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"ajv": {
|
||||
"version": "7.0.4",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-7.0.4.tgz",
|
||||
"integrity": "sha512-xzzzaqgEQfmuhbhAoqjJ8T/1okb6gAzXn/eQRNpAN1AEUoHJTNF9xCDRTtf/s3SKldtZfa+RJeTs+BQq+eZ/sw==",
|
||||
"version": "7.1.0",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-7.1.0.tgz",
|
||||
"integrity": "sha512-svS9uILze/cXbH0z2myCK2Brqprx/+JJYK5pHicT/GQiBfzzhUVAIT6MwqJg8y4xV/zoGsUeuPuwtoiKSGE15g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fast-deep-equal": "^3.1.1",
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
},
|
||||
"scripts": {
|
||||
"start": "node --trace-warnings example/node-singleprocess.js",
|
||||
"dev": "npm install && node server/dev.js",
|
||||
"dev": "npm install && node server/serve.js",
|
||||
"build": "rimraf dist/* types/* && node server/build.js",
|
||||
"lint": "eslint src/**/* example/*.js server/*.js"
|
||||
},
|
||||
|
@ -49,8 +49,8 @@
|
|||
"@typescript-eslint/eslint-plugin": "^4.15.0",
|
||||
"@typescript-eslint/parser": "^4.15.0",
|
||||
"chokidar": "^3.5.1",
|
||||
"esbuild": "^0.8.44",
|
||||
"eslint": "^7.19.0",
|
||||
"esbuild": "^0.8.45",
|
||||
"eslint": "^7.20.0",
|
||||
"eslint-config-airbnb-base": "^14.2.1",
|
||||
"eslint-plugin-import": "^2.22.1",
|
||||
"eslint-plugin-json": "^2.1.2",
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#!/usr/bin/env -S node --trace-warnings
|
||||
|
||||
/* eslint-disable no-restricted-syntax */
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
/* eslint-disable node/no-unpublished-require */
|
||||
/* eslint-disable node/shebang */
|
||||
|
@ -164,7 +163,7 @@ async function getStats(metafile) {
|
|||
}
|
||||
|
||||
function compile(fileNames, options) {
|
||||
log.info('Compile:', fileNames);
|
||||
log.info('Compile typings:', fileNames);
|
||||
const program = ts.createProgram(fileNames, options);
|
||||
const emit = program.emit();
|
||||
const diag = ts
|
||||
|
|
147
server/dev.js
147
server/dev.js
|
@ -1,147 +0,0 @@
|
|||
/*
|
||||
micro http2 server with file monitoring and automatic app rebuild
|
||||
- can process concurrent http requests
|
||||
- monitors specified filed and folders for changes
|
||||
- triggers library and application rebuild
|
||||
- any build errors are immediately displayed and can be corrected without need for restart
|
||||
- passthrough data compression
|
||||
*/
|
||||
|
||||
const process = require('process');
|
||||
const fs = require('fs');
|
||||
const zlib = require('zlib');
|
||||
const http = require('http');
|
||||
const http2 = require('http2');
|
||||
const path = require('path');
|
||||
// eslint-disable-next-line node/no-unpublished-require, import/no-extraneous-dependencies
|
||||
const chokidar = require('chokidar');
|
||||
const log = require('@vladmandic/pilogger');
|
||||
const build = require('./build.js');
|
||||
|
||||
// app configuration
|
||||
// you can provide your server key and certificate or use provided self-signed ones
|
||||
// self-signed certificate generated using:
|
||||
// openssl req -x509 -newkey rsa:4096 -nodes -keyout https.key -out https.crt -days 365 -subj "/C=US/ST=Florida/L=Miami/O=@vladmandic"
|
||||
// client app does not work without secure server since browsers enforce https for webcam access
|
||||
const options = {
|
||||
key: fs.readFileSync('server/https.key'),
|
||||
cert: fs.readFileSync('server/https.crt'),
|
||||
root: '..',
|
||||
default: 'example/index.html',
|
||||
httpPort: 8000,
|
||||
httpsPort: 8001,
|
||||
monitor: ['package.json', 'example', 'src'],
|
||||
};
|
||||
|
||||
// just some predefined mime types
|
||||
const mime = {
|
||||
'.html': 'text/html',
|
||||
'.js': 'text/javascript',
|
||||
'.css': 'text/css',
|
||||
'.json': 'application/json',
|
||||
'.png': 'image/png',
|
||||
'.jpg': 'image/jpg',
|
||||
'.gif': 'image/gif',
|
||||
'.ico': 'image/x-icon',
|
||||
'.svg': 'image/svg+xml',
|
||||
'.wav': 'audio/wav',
|
||||
'.mp4': 'video/mp4',
|
||||
'.woff': 'application/font-woff',
|
||||
'.ttf': 'application/font-ttf',
|
||||
'.wasm': 'application/wasm',
|
||||
};
|
||||
|
||||
// watch filesystem for any changes and notify build when needed
|
||||
async function watch() {
|
||||
const watcher = chokidar.watch(options.monitor, {
|
||||
persistent: true,
|
||||
ignorePermissionErrors: false,
|
||||
alwaysStat: false,
|
||||
ignoreInitial: true,
|
||||
followSymlinks: true,
|
||||
usePolling: false,
|
||||
useFsEvents: false,
|
||||
atomic: true,
|
||||
});
|
||||
// single event handler for file add/change/delete
|
||||
watcher
|
||||
.on('add', (evt) => build.build(evt, 'add'))
|
||||
.on('change', (evt) => build.build(evt, 'modify'))
|
||||
.on('unlink', (evt) => build.build(evt, 'remove'))
|
||||
.on('error', (err) => log.error(`Client watcher error: ${err}`))
|
||||
.on('ready', () => log.state('Monitoring:', options.monitor));
|
||||
}
|
||||
|
||||
// get file content for a valid url request
|
||||
function handle(url) {
|
||||
return new Promise((resolve) => {
|
||||
let obj = { ok: false };
|
||||
obj.file = url;
|
||||
if (!fs.existsSync(obj.file)) resolve(null);
|
||||
obj.stat = fs.statSync(obj.file);
|
||||
if (obj.stat.isFile()) obj.ok = true;
|
||||
if (!obj.ok && obj.stat.isDirectory()) {
|
||||
obj.file = path.join(obj.file, options.default);
|
||||
// @ts-ignore
|
||||
obj = handle(obj.file);
|
||||
}
|
||||
resolve(obj);
|
||||
});
|
||||
}
|
||||
|
||||
// process http requests
|
||||
async function httpRequest(req, res) {
|
||||
handle(path.join(__dirname, options.root, decodeURI(req.url)))
|
||||
.then((result) => {
|
||||
// get original ip of requestor, regardless if it's behind proxy or not
|
||||
// eslint-disable-next-line dot-notation
|
||||
const forwarded = (req.headers['forwarded'] || '').match(/for="\[(.*)\]:/);
|
||||
const ip = (Array.isArray(forwarded) ? forwarded[1] : null) || req.headers['x-forwarded-for'] || req.ip || req.socket.remoteAddress;
|
||||
if (!result || !result.ok) {
|
||||
res.writeHead(404, { 'Content-Type': 'text/html' });
|
||||
res.end('Error 404: Not Found\n', 'utf-8');
|
||||
log.warn(`${req.method}/${req.httpVersion}`, res.statusCode, req.url, ip);
|
||||
} else {
|
||||
const ext = String(path.extname(result.file)).toLowerCase();
|
||||
const contentType = mime[ext] || 'application/octet-stream';
|
||||
const accept = req.headers['accept-encoding'] ? req.headers['accept-encoding'].includes('br') : false; // does target accept brotli compressed data
|
||||
res.writeHead(200, {
|
||||
// 'Content-Length': result.stat.size, // not using as it's misleading for compressed streams
|
||||
'Content-Language': 'en', 'Content-Type': contentType, 'Content-Encoding': accept ? 'br' : '', 'Last-Modified': result.stat.mtime, 'Cache-Control': 'no-cache', 'X-Powered-By': `NodeJS/${process.version}`,
|
||||
});
|
||||
const compress = zlib.createBrotliCompress({ params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 5 } }); // instance of brotli compression with level 5
|
||||
const stream = fs.createReadStream(result.file);
|
||||
if (!accept) stream.pipe(res); // don't compress data
|
||||
else stream.pipe(compress).pipe(res); // compress data
|
||||
|
||||
// alternative methods of sending data
|
||||
/// 2. read stream and send by chunk
|
||||
// const stream = fs.createReadStream(result.file);
|
||||
// stream.on('data', (chunk) => res.write(chunk));
|
||||
// stream.on('end', () => res.end());
|
||||
|
||||
// 3. read entire file and send it as blob
|
||||
// const data = fs.readFileSync(result.file);
|
||||
// res.write(data);
|
||||
log.data(`${req.method}/${req.httpVersion}`, res.statusCode, contentType, result.stat.size, req.url, ip);
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.catch((err) => log.error('handle error:', err));
|
||||
}
|
||||
|
||||
// app main entry point
|
||||
async function main() {
|
||||
log.header();
|
||||
await watch();
|
||||
// @ts-ignore
|
||||
const server1 = http.createServer(options, httpRequest);
|
||||
server1.on('listening', () => log.state('HTTP server listening:', options.httpPort));
|
||||
server1.listen(options.httpPort);
|
||||
const server2 = http2.createSecureServer(options, httpRequest);
|
||||
server2.on('listening', () => log.state('HTTP2 server listening:', options.httpsPort));
|
||||
server2.listen(options.httpsPort);
|
||||
await build.build('all', 'startup');
|
||||
}
|
||||
|
||||
main();
|
Loading…
Reference in New Issue