Exit cleanup functions, authentication polish, db polish

This commit is contained in:
MrFry 2020-04-07 14:09:34 +02:00
parent fb8e12f8d2
commit c764c4f402
10 changed files with 314 additions and 229 deletions

View file

@ -11,9 +11,22 @@ let authDB
console.clear()
CreateDB()
// authDB.backup(usersDBPath)
// .then(() => {
// logger.Log('backup complete!')
// })
// .catch((err) => {
// logger.Log('backup failed!', logger.GetColor('redbg'))
// console.log(err)
// })
authDB.close()
function CreateDB () {
const dbStruct = utils.ReadJSON(dbStructPath)
// authDB = dbtools.GetDB(':memory:')
authDB = dbtools.GetDB(usersDBPath)
authDB.pragma('synchronous = OFF')
Object.keys(dbStruct).forEach((tableName) => {
const tableData = dbStruct[tableName]
@ -24,11 +37,14 @@ function CreateDB () {
const uids = utils.ReadFile('../dbUsers/keys').split('\n')
uids.forEach((cid, i) => {
if (!cid) { return }
logger.Log(`[ ${i} / ${uids.length} ]`)
try {
dbtools.Insert(authDB, 'users', {
pw: uuidv4(),
oldCID: cid
oldCID: cid,
avaiblePWRequests: 4,
created: new Date().toString()
})
} catch (e) {
logger.Log('Error during inserting', logger.GetColor('redbg'))