Removing a bunch of bs that is no longer used

This commit is contained in:
shockrah 2021-03-03 16:31:01 -08:00
parent b999907540
commit 9bf4048313
2 changed files with 28 additions and 80 deletions

View File

@ -1,53 +0,0 @@
const auth = require('./auth.js')
/**
* @param {String} id HTML ID
* @param {String} type Base tag type => examples include 'button' 'div'
* @param {Object} attrs Config object with the following valid fields and their types
*
* @returns HTMLElement
*/
exports.new_node = function new_node(id, type, attrs) {
let node = document.createElement(type)
if(id) { node.id = id; }
for(const key in attrs) {
if(key == 'classList') {
attrs['classList'].forEach(cls => node.classList.add(cls))
continue
}
node[key] = attrs[key]
}
return node
}
/**
* {Config} config | configuration object passed from the ipc
* {String} dom_id | element container for the server list itself
* */
exports.build_server_list = function (config, dom_id) {
const channels = require('./channels.js')
if(!config['servers']) { return; }
let container = document.getElementById(dom_id)
for(let server of config['servers']) {
// Request a new token so that further functions don't accidently try to use
// an old token
if(!('jwt' in server)) {
auth.request_new_token(server)
}
const id = server['domain'] || server['ip']
let child = html.new_node(id, 'button', {
'classList': ['btn', 'btn-outline-secondary', 'btn-nav-settings'],
'textContent': server['name'],
'type': 'button',
})
child.addEventListener('click', () => channels.get_channels(server))
container.appendChild(child)
}
}

View File

@ -12,37 +12,38 @@ const fs = require('fs')
* @param {Buffer} Optional body that defaults to an empty string
*
* @returns Response
* @throws HTTPError
*/
exports.Request = async function (method, domain, port, path, params, body=null) {
try {
let url = `https://${domain}:${port}${path}`
const options = {
method: method,
searchParams: params,
responseType: 'json',
throwHttpErrors: false,
}
let url = `https://${domain}:${port}${path}`
const options = {
method: method,
searchParams: params,
responseType: 'json',
body: body,
}
// NOTE: only in dev environments do we use http
if(process.env['DEV_ENV']) {
url = `http://${domain}:${port}${path}`
}
// NOTE: only in dev environments do we use http
if(process.env['DEV_ENV']) {
url = `http://${domain}:${port}${path}`
}
if(body) {
options.body = body
if(method == 'get') {
options.allowGetBody = true
}
}
const resp = await got(url , options)
return new Response(
resp.statusCode,
resp.body,
)
} catch(err) {
return new Response(null, null, err)
}
const resp = await got(url , options)
return new Response(
resp.statusCode,
resp.body,
)
}
/*
* @param {String} proto | http/https
* @param {String} hostname |
* @param {Number} port |
*
* @description Helper macro
*/
exports.BuildUrl = function(proto, hostname, port) {
return `${proto}://${hostname}:${port}`
}