Skip to content

Commit

Permalink
Non-functional auto-format refactoring
Browse files Browse the repository at this point in the history
This commit is a no-op refactoring using an automatic Javascript code formatting tool

Signed-off-by: Daniel D’Aquino <[email protected]>
  • Loading branch information
danieldaquino authored and jb55 committed Jan 15, 2024
1 parent d7fc32a commit 17832b5
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 59 deletions.
63 changes: 31 additions & 32 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,50 @@ const config_router = require('./router_config').config_router
const dotenv = require('dotenv')
const express = require('express')

function PurpleApi(opts = {})
{
if (!(this instanceof PurpleApi))
return new PurpleApi(opts)

const queue = {}
const db = lmdb.open({ path: '.' })
const translations = db.openDB('translations')
const accounts = db.openDB('accounts')
const dbs = {translations, accounts}
const router = express()

// translation data
this.translation = {queue}

this.db = db
this.dbs = dbs
this.opts = opts
this.router = router

return this
function PurpleApi(opts = {}) {
if (!(this instanceof PurpleApi))
return new PurpleApi(opts)

const queue = {}
const db = lmdb.open({ path: '.' })
const translations = db.openDB('translations')
const accounts = db.openDB('accounts')
const dbs = { translations, accounts }
const router = express()

// translation data
this.translation = { queue }

this.db = db
this.dbs = dbs
this.opts = opts
this.router = router

return this
}

PurpleApi.prototype.serve = async function pt_serve(port) {
const theport = this.opts.port || port || 8989
const theport = this.opts.port || port || 8989
this.router.listen(theport)
console.log(`Server listening on ${theport}`)
console.log(`Server listening on ${theport}`)
}

PurpleApi.prototype.close = async function pt_close() {
// close lmdb
await this.db.close()
// close lmdb
await this.db.close()
}

PurpleApi.prototype.register_routes = function pt_register_routes() {
config_router(this)
config_router(this)
}

module.exports = PurpleApi

if (require.main == module) {
// Load .env file if it exists
dotenv.config()
let translate = new PurpleApi()
translate.register_routes()
translate.serve(process.env.PORT)
// Load .env file if it exists
dotenv.config()

let translate = new PurpleApi()
translate.register_routes()
translate.serve(process.env.PORT)
}
54 changes: 27 additions & 27 deletions src/user_management.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
const { current_time } = require('./utils')

function check_account(api, pubkey) {
const id = Buffer.from(pubkey)
const account = api.dbs.accounts.get(id)
const id = Buffer.from(pubkey)
const account = api.dbs.accounts.get(id)

if (!account)
return { ok: false, message: 'Account not found' }
if (!account)
return { ok: false, message: 'Account not found' }

if (!account.expiry || current_time() >= account.expiry)
return { ok: false, message: 'Account expired' }
if (!account.expiry || current_time() >= account.expiry)
return { ok: false, message: 'Account expired' }

return { ok: true, message: null }
return { ok: true, message: null }
}

function create_account(api, pubkey, expiry) {
const id = Buffer.from(pubkey)
const account = api.dbs.accounts.get(id)
const id = Buffer.from(pubkey)
const account = api.dbs.accounts.get(id)

if (account)
return { request_error: 'account already exists' }
if (account)
return { request_error: 'account already exists' }

const new_account = {
pubkey: pubkey,
created_at: current_time(),
expiry: expiry,
}
const new_account = {
pubkey: pubkey,
created_at: current_time(),
expiry: expiry,
}

api.dbs.accounts.put(id, new_account)
return { account: new_account, request_error: null }
api.dbs.accounts.put(id, new_account)
return { account: new_account, request_error: null }
}

function get_account_info_payload(account) {
if (!account)
return null

return {
pubkey: account.pubkey,
created_at: account.created_at,
expiry: account.expiry ? account.expiry : null,
active: (account.expiry && current_time() < account.expiry) ? true : false,
}
if (!account)
return null

return {
pubkey: account.pubkey,
created_at: account.created_at,
expiry: account.expiry ? account.expiry : null,
active: (account.expiry && current_time() < account.expiry) ? true : false,
}
}

module.exports = { check_account, create_account, get_account_info_payload }

0 comments on commit 17832b5

Please sign in to comment.