Skip to content

Commit

Permalink
feature/post overhaul cleanup (#141)
Browse files Browse the repository at this point in the history
* a quick fix of sorts

* updates to live video

* lint fix 🧹

* tooltip fix?

* update delete modal for processes

* removing shrinkwraps + card view in processlist

* shrinkwraps
  • Loading branch information
jjjpanda authored Feb 4, 2022
1 parent 26134be commit 7c8d466
Show file tree
Hide file tree
Showing 132 changed files with 6,337 additions and 9,591 deletions.
84 changes: 42 additions & 42 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
module.exports = {
"ignorePatterns": [
"command/frontend/js/lib/*",
"command/dist/app.js",
"node_modules"
],
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 13,
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"never"
]
}
"ignorePatterns": [
"command/frontend/js/lib/*",
"command/dist/app.js",
"node_modules"
],
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 13,
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"never"
]
}
}
52 changes: 26 additions & 26 deletions chimera/prepareDatabase.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
require("dotenv").config()
const Pool = require('pg').Pool
const Pool = require("pg").Pool
const pool = new Pool({
user: process.env.database_USER,
host: process.env.database_HOST,
database: process.env.database_NAME,
password: process.env.database_PASSWORD,
port: process.env.database_PORT,
user: process.env.database_USER,
host: process.env.database_HOST,
database: process.env.database_NAME,
password: process.env.database_PASSWORD,
port: process.env.database_PORT,
})

const creationTasks = [
{
query: `CREATE TABLE frame_files(ID SERIAL PRIMARY KEY, timestamp TIMESTAMP, camera NUMERIC(10), name VARCHAR, size NUMERIC);`,
description: "frame files table"
},
{
query: `CREATE TABLE frame_deletes(ID SERIAL PRIMARY KEY, timestamp TIMESTAMP, camera NUMERIC(10), size NUMERIC, count NUMERIC);`,
description: "frame deletions table"
},
{
query: `CREATE TABLE auth(ID SERIAL PRIMARY KEY, username VARCHAR(10) UNIQUE, hash VARCHAR);`,
description: "authorization table"
}
{
query: "CREATE TABLE frame_files(ID SERIAL PRIMARY KEY, timestamp TIMESTAMP, camera NUMERIC(10), name VARCHAR, size NUMERIC);",
description: "frame files table"
},
{
query: "CREATE TABLE frame_deletes(ID SERIAL PRIMARY KEY, timestamp TIMESTAMP, camera NUMERIC(10), size NUMERIC, count NUMERIC);",
description: "frame deletions table"
},
{
query: "CREATE TABLE auth(ID SERIAL PRIMARY KEY, username VARCHAR(10) UNIQUE, hash VARCHAR);",
description: "authorization table"
}
]

Promise.allSettled(creationTasks.map(({query}) => {
return pool.query(query)
return pool.query(query)
})).then(values => {
let issues = false
values.forEach((value, index) => {
const tableExists = value.status == "fulfilled" || (value.status == "rejected" && value.reason && value.reason.code == `42P07`)
if(!tableExists) issues = true
console.log(`${creationTasks[index].description} ${tableExists ? `✔️` : `❌`}`)
})
process.exit(issues ? 1 : 0)
let issues = false
values.forEach((value, index) => {
const tableExists = value.status == "fulfilled" || (value.status == "rejected" && value.reason && value.reason.code == "42P07")
if(!tableExists) issues = true
console.log(`${creationTasks[index].description} ${tableExists ? "✔️" : "❌"}`)
})
process.exit(issues ? 1 : 0)
})
12 changes: 6 additions & 6 deletions chimera/register.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require("dotenv").config()
const { auth } = require("lib")

const Pool = require('pg').Pool
const Pool = require("pg").Pool
const pool = new Pool({
user: process.env.database_USER,
host: process.env.database_HOST,
database: process.env.database_NAME,
password: process.env.database_PASSWORD,
port: process.env.database_PORT,
user: process.env.database_USER,
host: process.env.database_HOST,
database: process.env.database_NAME,
password: process.env.database_PASSWORD,
port: process.env.database_PORT,
})

const stdout = process.stdout
Expand Down
109 changes: 53 additions & 56 deletions chimera/splitAndValidateEnvVars.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
require("dotenv").config()
const fs = require('fs')
const fs = require("fs")
const path = require("path")

let env = {
command: "",
gateway: "",
lib: "",
livestream: "",
memory: "",
schedule: "",
storage: ""
command: "",
gateway: "",
lib: "",
livestream: "",
memory: "",
schedule: "",
storage: ""
}

let allEnvPresent = true

const writeVarLine = (varName) => {
if(varName in process.env){
return `${varName} = ${process.env[varName]}\n`;
}
else{
console.log("MISSING ENV VAR", varName)
allEnvPresent = false
}
if(varName in process.env){
return `${varName} = ${process.env[varName]}\n`
}
else{
console.log("MISSING ENV VAR", varName)
allEnvPresent = false
}
}

const isFolderCheck = (varName) => {
try {
return fs.lstatSync(process.env[varName]).isDirectory()
}
catch(e) {
return false
}
try {
return fs.lstatSync(process.env[varName]).isDirectory()
}
catch(e) {
return false
}
}

const confirmPath = (varName, shouldBeFolder=false) => {
const isAbsolutePath = path.isAbsolute(process.env[varName])
if(process.env[varName].length != 0 && !isAbsolutePath){
console.log(varName, "SHOULD BE AN ABSOLUTE PATH")
allEnvPresent = false
return
}
const isFolder = isFolderCheck(varName)
if(shouldBeFolder && !isFolder){
console.log(varName, "SHOULD BE A FOLDER")
allEnvPresent = false
return
}
if(!shouldBeFolder && isFolder){
console.log(varName, "SHOULD BE A FILE")
allEnvPresent = false
return
}
return
const isAbsolutePath = path.isAbsolute(process.env[varName])
if(process.env[varName].length != 0 && !isAbsolutePath){
console.log(varName, "SHOULD BE AN ABSOLUTE PATH")
allEnvPresent = false
return
}
const isFolder = isFolderCheck(varName)
if(shouldBeFolder && !isFolder){
console.log(varName, "SHOULD BE A FOLDER")
allEnvPresent = false
return
}
if(!shouldBeFolder && isFolder){
console.log(varName, "SHOULD BE A FILE")
allEnvPresent = false
return
}
return
}

env.command += writeVarLine("NODE_ENV")

writeVarLine('chimeraInstances')
writeVarLine("chimeraInstances")

env.command += writeVarLine("cameras")
env.storage += writeVarLine("cameras")
Expand Down Expand Up @@ -119,9 +119,6 @@ confirmPath("storage_FOLDERPATH", true)

writeVarLine("storage_MOTION_CONF_FILEPATH")

env.command += writeVarLine("storage_fileStatsUpdateTime")
env.storage += writeVarLine("storage_fileStatsUpdateTime")

env.storage += writeVarLine("ffmpeg_FILEPATH")
confirmPath("ffmpeg_FILEPATH")

Expand Down Expand Up @@ -163,20 +160,20 @@ env.storage += writeVarLine("database_PORT")
env.command += writeVarLine("database_PORT")

if(allEnvPresent){
Promise.all(Object.entries(env)
.map(([key, value]) => new Promise((resolve, reject) => {
fs.writeFile(`${key}/.env`, value, (err) => {
if(!err) resolve()
else reject()
})
}))
).then(() => {
process.exit(0)
}, () => {
process.exit(1)
})
Promise.all(Object.entries(env)
.map(([key, value]) => new Promise((resolve, reject) => {
fs.writeFile(`${key}/.env`, value, (err) => {
if(!err) resolve()
else reject()
})
}))
).then(() => {
process.exit(0)
}, () => {
process.exit(1)
})
}
else{
process.exit(1)
process.exit(1)
}

18 changes: 9 additions & 9 deletions command/__mocks__/axios.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module.exports = {
default: {
create: () => ({
post: (url, data, other) => {
return new Promise(resolve => {
resolve(data)
})
}
})
}
default: {
create: () => ({
post: (url, data, other) => {
return new Promise(resolve => {
resolve(data)
})
}
})
}
}
24 changes: 12 additions & 12 deletions command/__mocks__/memory.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module.exports = {
client: (name) => ({
emit: (event, ...args) => {
if(event == "savePassword"){
args[1]()
}
else if(event == "verifyPassword"){
args[1](false)
}
},
on: () => {}
}),
server: () => {}
client: (name) => ({
emit: (event, ...args) => {
if(event == "savePassword"){
args[1]()
}
else if(event == "verifyPassword"){
args[1](false)
}
},
on: () => {}
}),
server: () => {}
}
18 changes: 9 additions & 9 deletions command/__mocks__/pg.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const bcrypt = jest.requireActual("bcryptjs")
const hashedMockedPassword = bcrypt.hashSync('mockedPassword', bcrypt.genSaltSync(10))
const hashedMockedPassword = bcrypt.hashSync("mockedPassword", bcrypt.genSaltSync(10))

const queryObject = {
query: (str, callback) => callback(null, {rows: [{hash: hashedMockedPassword}]})
query: (str, callback) => callback(null, {rows: [{hash: hashedMockedPassword}]})
}
const mockedPool = {
connect: () => {
return queryObject
},
...queryObject,
end: jest.fn(),
on: jest.fn()
connect: () => {
return queryObject
},
...queryObject,
end: jest.fn(),
on: jest.fn()
}

const pg = {
Pool: jest.fn(() => mockedPool)
Pool: jest.fn(() => mockedPool)
}

module.exports = pg
Loading

0 comments on commit 7c8d466

Please sign in to comment.