akf-forum/lib.js

35 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-09-21 23:06:14 +03:00
const RL = require('express-rate-limit');
const nodemailer = require("nodemailer");
const config = require("./config.json");
2023-05-08 17:41:16 +03:00
const crypto = require("crypto");
const { readdirSync } = require('fs');
2023-05-08 17:41:16 +03:00
require("dotenv").config();
2022-09-21 23:54:48 +03:00
module.exports = {
themes: readdirSync("./themes").filter(f => f !== "common").map(f => require(`./themes/${f}`)),
2022-09-21 23:54:48 +03:00
threadEnum: ["OPEN", "APPROVAL", "DELETED"],
2022-10-09 21:23:31 +03:00
userEnum: ["ACTIVE", "APPROVAL", "DELETED", "BANNED"],
2022-09-21 23:54:48 +03:00
RL(windowMs = 60_000, max = 1) {
return RL({
windowMs, max, standardHeaders: true, legacyHeaders: false,
handler: (req, res, next, opts) => !req.user?.admin ? res.error(opts.statusCode, "You are begin ratelimited") : next()
})
},
2023-05-08 17:41:16 +03:00
getGravatar(email, size) {
return `https://www.gravatar.com/avatar/${crypto.createHash('md5').update(email).digest("hex")}?d=mp${size ? `&size=${size}` : ''}`;
},
2023-05-08 17:16:12 +03:00
// eslint-disable-next-line no-useless-escape
emailRegEx: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
}
2022-09-21 23:54:48 +03:00
if (config.email_auth)
module.exports.transporter = nodemailer.createTransport({
service: process.env.EMAIL_SERVICE, direct: true, secure: true,
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS
}
});