Formatting.

This commit is contained in:
mike12345567 2021-04-27 17:30:19 +01:00
parent 129b827d9f
commit 01a9db76c8
3 changed files with 22 additions and 23 deletions

View File

@ -15,9 +15,9 @@ let CLIENT
*/ */
function init() { function init() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const [ host, port ] = env.REDIS_URL.split(":") const [host, port] = env.REDIS_URL.split(":")
const opts = { const opts = {
connectTimeout: CONNECT_TIMEOUT_MS connectTimeout: CONNECT_TIMEOUT_MS,
} }
if (CLUSTERED) { if (CLUSTERED) {
opts.redisOptions = {} opts.redisOptions = {}
@ -25,7 +25,7 @@ function init() {
opts.redisOptions.password = env.REDIS_PASSWORD opts.redisOptions.password = env.REDIS_PASSWORD
opts.slotsRefreshTimeout = SLOT_REFRESH_MS opts.slotsRefreshTimeout = SLOT_REFRESH_MS
opts.dnsLookup = (address, callback) => callback(null, address) opts.dnsLookup = (address, callback) => callback(null, address)
CLIENT = new Redis.Cluster([ { port, host } ]) CLIENT = new Redis.Cluster([{ port, host }])
} else { } else {
opts.password = env.REDIS_PASSWORD opts.password = env.REDIS_PASSWORD
opts.port = port opts.port = port
@ -58,7 +58,7 @@ function promisifyStream(stream) {
outputKeys.add(key) outputKeys.add(key)
}) })
}) })
stream.on("error", (err) => { stream.on("error", err => {
reject(err) reject(err)
}) })
stream.on("end", async () => { stream.on("end", async () => {
@ -69,10 +69,12 @@ function promisifyStream(stream) {
getPromises.push(CLIENT.get(key)) getPromises.push(CLIENT.get(key))
} }
const jsonArray = await Promise.all(getPromises) const jsonArray = await Promise.all(getPromises)
resolve(keysArray.map(key => ({ resolve(
key: removeDbPrefix(key), keysArray.map(key => ({
value: JSON.parse(jsonArray.shift()), key: removeDbPrefix(key),
}))) value: JSON.parse(jsonArray.shift()),
}))
)
} catch (err) { } catch (err) {
reject(err) reject(err)
} }
@ -91,20 +93,21 @@ class RedisWrapper {
} }
async scan() { async scan() {
const db = this._db, client = this._client const db = this._db,
client = this._client
let stream let stream
if (CLUSTERED) { if (CLUSTERED) {
let node = client.nodes("master") let node = client.nodes("master")
stream = node[0].scanStream({match: db + "-*", count: 100}) stream = node[0].scanStream({ match: db + "-*", count: 100 })
} else { } else {
stream = client.scanStream({match: db + "-*", count: 100}) stream = client.scanStream({ match: db + "-*", count: 100 })
} }
return promisifyStream(stream) return promisifyStream(stream)
} }
async get(key) { async get(key) {
const db = this._db, client = this._client const db = this._db,
client = this._client
let response = await client.get(addDbPrefix(db, key)) let response = await client.get(addDbPrefix(db, key))
// overwrite the prefixed key // overwrite the prefixed key
if (response != null && response.key) { if (response != null && response.key) {
@ -114,8 +117,9 @@ class RedisWrapper {
} }
async store(key, value, expirySeconds = null) { async store(key, value, expirySeconds = null) {
const db = this._db, client = this._client const db = this._db,
if (typeof(value) === "object") { client = this._client
if (typeof value === "object") {
value = JSON.stringify(value) value = JSON.stringify(value)
} }
const prefixedKey = addDbPrefix(db, key) const prefixedKey = addDbPrefix(db, key)
@ -126,7 +130,8 @@ class RedisWrapper {
} }
async delete(key) { async delete(key) {
const db = this._db, client = this._client const db = this._db,
client = this._client
await client.del(addDbPrefix(db, key)) await client.del(addDbPrefix(db, key))
} }

View File

@ -47,7 +47,6 @@ exports.reset = async ctx => {
try { try {
const user = getGlobalUserByEmail(email) const user = getGlobalUserByEmail(email)
if (user) { if (user) {
} }
} catch (err) { } catch (err) {
// don't throw any kind of error to the user, this might give away something // don't throw any kind of error to the user, this might give away something

View File

@ -1,11 +1,7 @@
const nodemailer = require("nodemailer") const nodemailer = require("nodemailer")
const CouchDB = require("../db") const CouchDB = require("../db")
const { StaticDatabases, determineScopedConfig } = require("@budibase/auth").db const { StaticDatabases, determineScopedConfig } = require("@budibase/auth").db
const { const { EmailTemplatePurpose, TemplateTypes, Configs } = require("../constants")
EmailTemplatePurpose,
TemplateTypes,
Configs,
} = require("../constants")
const { getTemplateByPurpose } = require("../constants/templates") const { getTemplateByPurpose } = require("../constants/templates")
const { getSettingsTemplateContext } = require("./templates") const { getSettingsTemplateContext } = require("./templates")
const { processString } = require("@budibase/string-templates") const { processString } = require("@budibase/string-templates")
@ -94,7 +90,6 @@ exports.sendEmail = async (email, purpose, { groupId, userId }) => {
return transport.sendMail(message) return transport.sendMail(message)
} }
exports.verifyConfig = async config => { exports.verifyConfig = async config => {
const transport = createSMTPTransport(config) const transport = createSMTPTransport(config)
await transport.verify() await transport.verify()