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
restart: always
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
volumes:
- /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)
location /identities/api/v1/ {
rewrite ^/identities/api/v1/(.*)$ /api/v1/$1 break;
proxy_pass http://localhost/;
proxy_pass http://localhost:8123;
proxy_redirect off;
proxy_set_header Host $host;
proxy_ssl_verify off;
}
location /identities {
@ -17,5 +18,6 @@ location /identities {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_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 {
listen 80 default_server;
listen [::]:80 default_server;
# return 301 https://$host$request_uri;
#}
return 301 https://$host$request_uri;
}
#server {
# listen 443 ssl;
server {
listen 443 ssl;
client_max_body_size 5g;
# ssl on;
ssl on;
# ssl_certificate /etc/letsencrypt/live/ketrenos.com/fullchain.pem;
# ssl_certificate_key /etc/letsencrypt/live/ketrenos.com/privkey.pem;
ssl_certificate /etc/letsencrypt/live/ketrenos.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/ketrenos.com/privkey.pem;
root /website;
index index.html;

View File

@ -1,9 +1,6 @@
# PRODUCTION -- pre-built source
location /identities/api/v1/ {
rewrite ^/identities/api/v1/(.*)$ /api/v1/$1 break;
proxy_pass http://localhost/;
proxy_redirect off;
proxy_set_header Host $host;
rewrite ^/identities/api/v1/(.*)$ https://${host}/api/v1/$1 permanent;
}
location /identities {

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) => {
};
@ -345,9 +374,10 @@ const updateIdentityFaces = async (identity) => {
const faces = await photoDB.sequelize.query(
"SELECT " +
"faces.*,faceDescriptors.* " +
"FROM faces,faceDescriptors " +
"WHERE " +
"faces.identityId=:identityId " +
"AND faceDescriptors.id=faces.descriptorsId", {
"AND faceDescriptors.id=faces.descriptorId", {
replacements: identity,
type: photoDB.Sequelize.QueryTypes.SELECT,
raw: true
@ -359,7 +389,7 @@ const updateIdentityFaces = async (identity) => {
count = 0;
faces.forEach((face) => {
if (!descriptors[index]) {
if (!identity.descriptors) {
return;
}
if (!face.descriptors) {
@ -408,7 +438,7 @@ const updateIdentityFaces = async (identity) => {
}
let sql = '';
if (closestId !== undefined && closestId !== identity.faceId) {
if (closestId !== -1 && closestId !== identity.faceId) {
sql = `${sql} faceId=:faceId`;
}
if (!same) {
@ -416,16 +446,14 @@ const updateIdentityFaces = async (identity) => {
sql = `${sql}, `;
}
sql = `${sql} descriptors=:descriptors`;
identity.descriptors = average;
}
if (sql !== '') {
await photoDB.sequelize.select(
identity.faceId = closestId;
await photoDB.sequelize.query(
`UPDATE identities SET ${sql} ` +
`WHERE id=:identityId`, {
replacements: {
faceId: closestId,
descriptors: average,
identityId: identity.id
}
replacements: identity
}
);
}
@ -468,27 +496,36 @@ router.get("/:id?", async (req, res) => {
});
await Promise.map(identities, async (identity) => {
let where;
/* If id was set, only return a single face */
if (id !== undefined) {
if (identity.faceId !== -1) {
for (let field in identity) {
if (field.match(/.*Name/) && identity[field] === null) {
identity[field] = '';
}
}
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';
} else {
where = 'identityId=:identityId LIMIT 1';
where = 'identityId=:identityId';
limit = 'LIMIT 1';
}
} else {
where = 'identityId=:identityId'
}
identity.relatedFaces = await photoDB.sequelize.query(
'SELECT id as faceId,photoId,distance FROM faces ' +
`WHERE ${where} ORDER BY distance ASC`, {
'SELECT id as faceId,identityId,photoId,distance ' +
'FROM faces ' +
`WHERE ${where} ` +
'ORDER BY distance ASC ' +
limit, {
replacements: identity,
type: photoDB.Sequelize.QueryTypes.SELECT,
raw: true
}
);
if (identity.relatedFaces.length !== 0
&& (!identity.faceId || identity.faceId === -1)) {
await updateIdentityFaces(identity);