Working again

Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
James Ketr 2023-01-23 08:49:43 -08:00
parent 3e9438bb27
commit 58a2baddde
5 changed files with 68 additions and 32 deletions

View File

@ -17,7 +17,7 @@ services:
# - db # - db
restart: always restart: always
ports: ports:
- ${PORT}:80 # nginx -> server/app.js express app - ${PORT}:443 # nginx -> server/app.js express app
# - 127.0.0.1:${SHELL_PORT}:4200 # shellinabox # - 127.0.0.1:${SHELL_PORT}:4200 # shellinabox
volumes: volumes:
- /etc/letsencrypt:/etc/letsencrypt:ro # Use host web keys - /etc/letsencrypt:/etc/letsencrypt:ro # Use host web keys

View File

@ -1,9 +1,10 @@
# DEVELOPMENT -- use npm development server on port 3000 (entrypoint.sh) # DEVELOPMENT -- use npm development server on port 3000 (entrypoint.sh)
location /identities/api/v1/ { location /identities/api/v1/ {
rewrite ^/identities/api/v1/(.*)$ /api/v1/$1 break; rewrite ^/identities/api/v1/(.*)$ /api/v1/$1 break;
proxy_pass http://localhost/; proxy_pass http://localhost:8123;
proxy_redirect off; proxy_redirect off;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_ssl_verify off;
} }
location /identities { location /identities {
@ -17,5 +18,6 @@ location /identities {
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade"; proxy_set_header Connection "Upgrade";
proxy_pass http://localhost:3000; proxy_ssl_verify off;
proxy_pass https://localhost:3000;
} }

View File

@ -1,17 +1,17 @@
server { server {
listen 80 default_server; listen 80 default_server;
listen [::]:80 default_server; listen [::]:80 default_server;
# return 301 https://$host$request_uri; return 301 https://$host$request_uri;
#} }
#server { server {
# listen 443 ssl; listen 443 ssl;
client_max_body_size 5g; client_max_body_size 5g;
# ssl on; ssl on;
# ssl_certificate /etc/letsencrypt/live/ketrenos.com/fullchain.pem; ssl_certificate /etc/letsencrypt/live/ketrenos.com/fullchain.pem;
# ssl_certificate_key /etc/letsencrypt/live/ketrenos.com/privkey.pem; ssl_certificate_key /etc/letsencrypt/live/ketrenos.com/privkey.pem;
root /website; root /website;
index index.html; index index.html;

View File

@ -1,13 +1,10 @@
# PRODUCTION -- pre-built source # PRODUCTION -- pre-built source
location /identities/api/v1/ { location /identities/api/v1/ {
rewrite ^/identities/api/v1/(.*)$ /api/v1/$1 break; rewrite ^/identities/api/v1/(.*)$ https://${host}/api/v1/$1 permanent;
proxy_pass http://localhost/;
proxy_redirect off;
proxy_set_header Host $host;
} }
location /identities { location /identities {
try_files $uri $uri/ =404; try_files $uri $uri/ =404;
alias /website/client/build; alias /website/client/build;
index index.html; index index.html;
} }

View File

@ -135,6 +135,35 @@ router.put('/:id', async (req, res) => {
}); });
router.delete('/:id', async (req, res) => {
console.log(`DELETE ${req.url}`)
if (!req.user.maintainer) {
console.warn(`${req.user.name} attempted to modify photos.`);
return res.status(401).send({ message: "Unauthorized to modify photos." });
}
const { id } = req.params;
if (!id || isNaN(+id)) {
return res.status(400).send({ message: `Invalid identity id ${id}` });
}
await photoDB.sequelize.query(
'UPDATE faces SET distance=0,identityId=NULL ' +
'WHERE identityId=:id', {
replacements: { id }
}
);
await photoDB.sequelize.query(
'DELETE FROM identities ' +
'WHERE identityId=:id', {
replacements: { id }
});
return res.status(200).send({});
});
const addFaceToIdentityDescriptors = (identity, face) => { const addFaceToIdentityDescriptors = (identity, face) => {
}; };
@ -345,9 +374,10 @@ const updateIdentityFaces = async (identity) => {
const faces = await photoDB.sequelize.query( const faces = await photoDB.sequelize.query(
"SELECT " + "SELECT " +
"faces.*,faceDescriptors.* " + "faces.*,faceDescriptors.* " +
"FROM faces,faceDescriptors " +
"WHERE " + "WHERE " +
"faces.identityId=:identityId " + "faces.identityId=:identityId " +
"AND faceDescriptors.id=faces.descriptorsId", { "AND faceDescriptors.id=faces.descriptorId", {
replacements: identity, replacements: identity,
type: photoDB.Sequelize.QueryTypes.SELECT, type: photoDB.Sequelize.QueryTypes.SELECT,
raw: true raw: true
@ -359,7 +389,7 @@ const updateIdentityFaces = async (identity) => {
count = 0; count = 0;
faces.forEach((face) => { faces.forEach((face) => {
if (!descriptors[index]) { if (!identity.descriptors) {
return; return;
} }
if (!face.descriptors) { if (!face.descriptors) {
@ -408,7 +438,7 @@ const updateIdentityFaces = async (identity) => {
} }
let sql = ''; let sql = '';
if (closestId !== undefined && closestId !== identity.faceId) { if (closestId !== -1 && closestId !== identity.faceId) {
sql = `${sql} faceId=:faceId`; sql = `${sql} faceId=:faceId`;
} }
if (!same) { if (!same) {
@ -416,16 +446,14 @@ const updateIdentityFaces = async (identity) => {
sql = `${sql}, `; sql = `${sql}, `;
} }
sql = `${sql} descriptors=:descriptors`; sql = `${sql} descriptors=:descriptors`;
identity.descriptors = average;
} }
if (sql !== '') { if (sql !== '') {
await photoDB.sequelize.select( identity.faceId = closestId;
await photoDB.sequelize.query(
`UPDATE identities SET ${sql} ` + `UPDATE identities SET ${sql} ` +
`WHERE id=:identityId`, { `WHERE id=:identityId`, {
replacements: { replacements: identity
faceId: closestId,
descriptors: average,
identityId: identity.id
}
} }
); );
} }
@ -468,27 +496,36 @@ router.get("/:id?", async (req, res) => {
}); });
await Promise.map(identities, async (identity) => { await Promise.map(identities, async (identity) => {
let where; for (let field in identity) {
/* If id was set, only return a single face */ if (field.match(/.*Name/) && identity[field] === null) {
if (id !== undefined) { identity[field] = '';
if (identity.faceId !== -1) { }
}
let where, limit = '';
/* If id was not set, only return a single face */
if (id === undefined) {
if (identity.faceId !== -1 && identity.faceId !== null) {
where = 'faceId=:faceId'; where = 'faceId=:faceId';
} else { } else {
where = 'identityId=:identityId LIMIT 1'; where = 'identityId=:identityId';
limit = 'LIMIT 1';
} }
} else { } else {
where = 'identityId=:identityId' where = 'identityId=:identityId'
} }
identity.relatedFaces = await photoDB.sequelize.query( identity.relatedFaces = await photoDB.sequelize.query(
'SELECT id as faceId,photoId,distance FROM faces ' + 'SELECT id as faceId,identityId,photoId,distance ' +
`WHERE ${where} ORDER BY distance ASC`, { 'FROM faces ' +
`WHERE ${where} ` +
'ORDER BY distance ASC ' +
limit, {
replacements: identity, replacements: identity,
type: photoDB.Sequelize.QueryTypes.SELECT, type: photoDB.Sequelize.QueryTypes.SELECT,
raw: true raw: true
} }
); );
if (identity.relatedFaces.length !== 0 if (identity.relatedFaces.length !== 0
&& (!identity.faceId || identity.faceId === -1)) { && (!identity.faceId || identity.faceId === -1)) {
await updateIdentityFaces(identity); await updateIdentityFaces(identity);