mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-25 03:33:33 +01:00
var -> let
Signed-off-by: TheArcaneBrony <myrainbowdash949@gmail.com>
This commit is contained in:
parent
b3657f2cc8
commit
32b93c857f
@ -4,7 +4,7 @@ const WebSocket = require("ws");
|
||||
const endpoint = process.env.GATEWAY || "ws://localhost:3001";
|
||||
const connections = Number(process.env.CONNECTIONS) || 50;
|
||||
const token = process.env.TOKEN;
|
||||
var cores = 1;
|
||||
let cores = 1;
|
||||
try {
|
||||
cores = Number(process.env.THREADS) || os.cpus().length;
|
||||
} catch {
|
||||
|
@ -232,15 +232,15 @@ const processFile = async (name) => {
|
||||
|
||||
console.log();
|
||||
|
||||
var existing = await fs.readdir(CACHE_PATH);
|
||||
let existing = await fs.readdir(CACHE_PATH);
|
||||
while (existing.length > 0) {
|
||||
var file = existing.shift();
|
||||
let file = existing.shift();
|
||||
|
||||
process.stdout.write(
|
||||
`Patching existing ${file}. Remaining: ${existing.length}. \r`,
|
||||
);
|
||||
|
||||
var text = await fs.readFile(path.join(CACHE_PATH, file));
|
||||
let text = await fs.readFile(path.join(CACHE_PATH, file));
|
||||
if (file.includes(".js") || file.includes(".css")) {
|
||||
text = doPatch(text.toString());
|
||||
await fs.writeFile(path.join(CACHE_PATH, file), text.toString());
|
||||
@ -260,7 +260,7 @@ const processFile = async (name) => {
|
||||
|
||||
let promises = [];
|
||||
|
||||
for (var i = 0; i < assets.length; i++) {
|
||||
for (let i = 0; i < assets.length; i++) {
|
||||
const asset = assets[i];
|
||||
|
||||
if (existsSync(path.join(CACHE_PATH, `${asset}.js`))) {
|
||||
|
@ -15,7 +15,7 @@ const specification = JSON.parse(
|
||||
);
|
||||
|
||||
function combineSchemas(schemas) {
|
||||
var definitions = {};
|
||||
let definitions = {};
|
||||
|
||||
for (const name in schemas) {
|
||||
definitions = {
|
||||
|
@ -8,7 +8,7 @@ const { Rights } = require("..");
|
||||
const allRights = new Rights(1).bitfield;
|
||||
console.log(`All rights:`, allRights);
|
||||
|
||||
var discordLike = allRights;
|
||||
let discordLike = allRights;
|
||||
discordLike -= Rights.FLAGS.OPERATOR;
|
||||
discordLike -= Rights.FLAGS.MANAGE_APPLICATIONS;
|
||||
discordLike -= Rights.FLAGS.MANAGE_MESSAGES;
|
||||
|
@ -41,7 +41,7 @@ const Excluded = [
|
||||
];
|
||||
|
||||
function modify(obj) {
|
||||
for (var k in obj) {
|
||||
for (let k in obj) {
|
||||
if (typeof obj[k] === "object" && obj[k] !== null) {
|
||||
modify(obj[k]);
|
||||
}
|
||||
@ -65,7 +65,7 @@ function main() {
|
||||
);
|
||||
console.log(schemas);
|
||||
|
||||
var definitions = {};
|
||||
let definitions = {};
|
||||
|
||||
for (const name of schemas) {
|
||||
const part = TJS.generateSchema(program, name, settings, [], generator);
|
||||
@ -100,11 +100,11 @@ function main() {
|
||||
main();
|
||||
|
||||
function walk(dir) {
|
||||
var results = [];
|
||||
var list = fs.readdirSync(dir);
|
||||
let results = [];
|
||||
let list = fs.readdirSync(dir);
|
||||
list.forEach(function (file) {
|
||||
file = dir + "/" + file;
|
||||
var stat = fs.statSync(file);
|
||||
let stat = fs.statSync(file);
|
||||
if (stat && stat.isDirectory()) {
|
||||
/* Recurse into a subdirectory */
|
||||
results = results.concat(walk(file));
|
||||
|
@ -19,19 +19,19 @@ setInterval(() => {
|
||||
getUsers();
|
||||
}, 60 * 1000);
|
||||
async function generate() {
|
||||
var accounts = await JSON.parse(fs.readFileSync("accounts.json"));
|
||||
let accounts = await JSON.parse(fs.readFileSync("accounts.json"));
|
||||
console.log(accounts);
|
||||
var account = await register();
|
||||
let account = await register();
|
||||
accounts.push(account);
|
||||
fs.writeFileSync("accounts.json", JSON.stringify(accounts));
|
||||
console.log(accounts.length);
|
||||
var y = await login(account);
|
||||
let y = await login(account);
|
||||
sendMessage(y);
|
||||
}
|
||||
async function getUsers() {
|
||||
var accounts = await JSON.parse(fs.readFileSync("accounts.json"));
|
||||
let accounts = await JSON.parse(fs.readFileSync("accounts.json"));
|
||||
accounts.forEach(async (x) => {
|
||||
var y = await login(x);
|
||||
let y = await login(x);
|
||||
console.log(y);
|
||||
sendMessage(y);
|
||||
});
|
||||
|
@ -1,14 +1,14 @@
|
||||
const fetch = require("node-fetch");
|
||||
const fs = require("fs");
|
||||
var config = require("../../config.json");
|
||||
let config = require("../../config.json");
|
||||
module.exports = login;
|
||||
async function login(account) {
|
||||
var body = {
|
||||
let body = {
|
||||
fingerprint: "805826570869932034.wR8vi8lGlFBJerErO9LG5NViJFw",
|
||||
login: account.email,
|
||||
password: account.password,
|
||||
};
|
||||
var x = await fetch(config.url + "/auth/login", {
|
||||
let x = await fetch(config.url + "/auth/login", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
|
@ -1,14 +1,14 @@
|
||||
const fetch = require("node-fetch");
|
||||
const fs = require("fs");
|
||||
var config = require("../../config.json");
|
||||
let config = require("../../config.json");
|
||||
module.exports = sendMessage;
|
||||
async function sendMessage(account) {
|
||||
var body = {
|
||||
let body = {
|
||||
fingerprint: "805826570869932034.wR8vi8lGlFBJerErO9LG5NViJFw",
|
||||
content: "Test",
|
||||
tts: false,
|
||||
};
|
||||
var x = await fetch(
|
||||
let x = await fetch(
|
||||
config.url + "/channels/" + config["text-channel"] + "/messages",
|
||||
{
|
||||
method: "POST",
|
||||
|
@ -1,21 +1,21 @@
|
||||
const fetch = require("node-fetch");
|
||||
const fs = require("fs");
|
||||
var config = require("../../config.json");
|
||||
let config = require("../../config.json");
|
||||
module.exports = generate;
|
||||
async function generate() {
|
||||
var mail = (Math.random() + 10).toString(36).substring(2);
|
||||
let mail = (Math.random() + 10).toString(36).substring(2);
|
||||
mail =
|
||||
mail +
|
||||
"." +
|
||||
(Math.random() + 10).toString(36).substring(2) +
|
||||
"@stresstest.com";
|
||||
var password =
|
||||
let password =
|
||||
(Math.random() * 69).toString(36).substring(-7) +
|
||||
(Math.random() * 69).toString(36).substring(-7) +
|
||||
(Math.random() * 69).toString(36).substring(-8);
|
||||
console.log(mail);
|
||||
console.log(password);
|
||||
var body = {
|
||||
let body = {
|
||||
fingerprint: "805826570869932034.wR8vi8lGlFBJerErO9LG5NViJFw",
|
||||
email: mail,
|
||||
username: "Fosscord Stress Test",
|
||||
@ -26,7 +26,7 @@ async function generate() {
|
||||
gift_code_sku_id: null,
|
||||
captcha_key: null,
|
||||
};
|
||||
var x = await fetch(config.url + "/auth/register", {
|
||||
let x = await fetch(config.url + "/auth/register", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
|
@ -45,7 +45,7 @@ export class FosscordServer extends Server {
|
||||
this.app.use(
|
||||
morgan("combined", {
|
||||
skip: (req, res) => {
|
||||
var skip = !(
|
||||
let skip = !(
|
||||
process.env["LOG_REQUESTS"]?.includes(
|
||||
res.statusCode.toString(),
|
||||
) ?? false
|
||||
|
@ -74,7 +74,7 @@ router.patch(
|
||||
"/",
|
||||
route({ body: "ChannelModifySchema", permission: "MANAGE_CHANNELS" }),
|
||||
async (req: Request, res: Response) => {
|
||||
var payload = req.body as ChannelModifySchema;
|
||||
let payload = req.body as ChannelModifySchema;
|
||||
const { channel_id } = req.params;
|
||||
if (payload.icon)
|
||||
payload.icon = await handleFile(
|
||||
|
@ -41,7 +41,7 @@ router.patch(
|
||||
}),
|
||||
async (req: Request, res: Response) => {
|
||||
const { message_id, channel_id } = req.params;
|
||||
var body = req.body as MessageCreateSchema;
|
||||
let body = req.body as MessageCreateSchema;
|
||||
|
||||
const message = await Message.findOneOrFail({
|
||||
where: { id: message_id, channel_id },
|
||||
@ -109,7 +109,7 @@ router.put(
|
||||
}),
|
||||
async (req: Request, res: Response) => {
|
||||
const { channel_id, message_id } = req.params;
|
||||
var body = req.body as MessageCreateSchema;
|
||||
let body = req.body as MessageCreateSchema;
|
||||
const attachments: Attachment[] = [];
|
||||
|
||||
const rights = await getRights(req.user_id);
|
||||
|
@ -196,7 +196,7 @@ router.delete(
|
||||
"/:emoji/:user_id",
|
||||
route({}),
|
||||
async (req: Request, res: Response) => {
|
||||
var { message_id, channel_id, user_id } = req.params;
|
||||
let { message_id, channel_id, user_id } = req.params;
|
||||
|
||||
const emoji = getEmoji(req.params.emoji);
|
||||
|
||||
|
@ -51,7 +51,7 @@ router.get("/", async (req: Request, res: Response) => {
|
||||
if (limit < 1 || limit > 100)
|
||||
throw new HTTPError("limit must be between 1 and 100", 422);
|
||||
|
||||
var halfLimit = Math.floor(limit / 2);
|
||||
let halfLimit = Math.floor(limit / 2);
|
||||
|
||||
const permissions = await getPermission(
|
||||
req.user_id,
|
||||
@ -61,7 +61,7 @@ router.get("/", async (req: Request, res: Response) => {
|
||||
permissions.hasThrow("VIEW_CHANNEL");
|
||||
if (!permissions.has("READ_MESSAGE_HISTORY")) return res.json([]);
|
||||
|
||||
var query: FindManyOptions<Message> & { where: { id?: any } } = {
|
||||
let query: FindManyOptions<Message> & { where: { id?: any } } = {
|
||||
order: { timestamp: "DESC" },
|
||||
take: limit,
|
||||
where: { channel_id },
|
||||
@ -129,7 +129,7 @@ router.get("/", async (req: Request, res: Response) => {
|
||||
which causes erorrs when, say, the `application` property is `null`.
|
||||
**/
|
||||
|
||||
// for (var curr in x) {
|
||||
// for (let curr in x) {
|
||||
// if (x[curr] === null)
|
||||
// delete x[curr];
|
||||
// }
|
||||
@ -174,7 +174,7 @@ router.post(
|
||||
}),
|
||||
async (req: Request, res: Response) => {
|
||||
const { channel_id } = req.params;
|
||||
var body = req.body as MessageCreateSchema;
|
||||
let body = req.body as MessageCreateSchema;
|
||||
const attachments: Attachment[] = [];
|
||||
|
||||
const channel = await Channel.findOneOrFail({
|
||||
@ -202,7 +202,7 @@ router.post(
|
||||
}
|
||||
|
||||
if (!req.rights.has(Rights.FLAGS.BYPASS_RATE_LIMITS)) {
|
||||
var limits = Config.get().limits;
|
||||
let limits = Config.get().limits;
|
||||
if (limits.absoluteRate.register.enabled) {
|
||||
const count = await Message.count({
|
||||
where: {
|
||||
@ -227,7 +227,7 @@ router.post(
|
||||
}
|
||||
|
||||
const files = (req.files as Express.Multer.File[]) ?? [];
|
||||
for (var currFile of files) {
|
||||
for (let currFile of files) {
|
||||
try {
|
||||
const file = await uploadFile(
|
||||
`/attachments/${channel.id}`,
|
||||
|
@ -25,7 +25,7 @@ router.put(
|
||||
const { channel_id, overwrite_id } = req.params;
|
||||
const body = req.body as ChannelPermissionOverwriteSchema;
|
||||
|
||||
var channel = await Channel.findOneOrFail({
|
||||
let channel = await Channel.findOneOrFail({
|
||||
where: { id: channel_id },
|
||||
});
|
||||
if (!channel.guild_id) throw new HTTPError("Channel not found", 404);
|
||||
@ -39,7 +39,7 @@ router.put(
|
||||
} else throw new HTTPError("type not supported", 501);
|
||||
|
||||
//@ts-ignore
|
||||
var overwrite: ChannelPermissionOverwrite =
|
||||
let overwrite: ChannelPermissionOverwrite =
|
||||
channel.permission_overwrites?.find((x) => x.id === overwrite_id);
|
||||
if (!overwrite) {
|
||||
// @ts-ignore
|
||||
|
@ -50,7 +50,7 @@ router.post(
|
||||
|
||||
// TODO: send the deletion event bite-by-bite to prevent client stress
|
||||
|
||||
var query: FindManyOptions<Message> & { where: { id?: any } } = {
|
||||
let query: FindManyOptions<Message> & { where: { id?: any } } = {
|
||||
order: { id: "ASC" },
|
||||
// take: limit,
|
||||
where: {
|
||||
|
@ -34,7 +34,7 @@ router.post(
|
||||
if (webhook_count > maxWebhooks)
|
||||
throw DiscordApiErrors.MAXIMUM_WEBHOOKS.withParams(maxWebhooks);
|
||||
|
||||
var { avatar, name } = req.body as WebhookCreateSchema;
|
||||
let { avatar, name } = req.body as WebhookCreateSchema;
|
||||
name = trimSpecial(name);
|
||||
|
||||
// TODO: move this
|
||||
|
@ -8,8 +8,8 @@ const router = Router();
|
||||
|
||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||
const { offset, limit, categories } = req.query;
|
||||
var showAllGuilds = Config.get().guild.discovery.showAllGuilds;
|
||||
var configLimit = Config.get().guild.discovery.limit;
|
||||
let showAllGuilds = Config.get().guild.discovery.showAllGuilds;
|
||||
let configLimit = Config.get().guild.discovery.limit;
|
||||
let guilds;
|
||||
if (categories == undefined) {
|
||||
guilds = showAllGuilds
|
||||
|
@ -8,7 +8,7 @@ const router = Router();
|
||||
|
||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||
const { limit, personalization_disabled } = req.query;
|
||||
var showAllGuilds = Config.get().guild.discovery.showAllGuilds;
|
||||
let showAllGuilds = Config.get().guild.discovery.showAllGuilds;
|
||||
|
||||
const genLoadId = (size: Number) =>
|
||||
[...Array(size)]
|
||||
|
@ -18,7 +18,7 @@ const router = Router();
|
||||
// discord prefixes this route with /delete instead of using the delete method
|
||||
// docs are wrong https://discord.com/developers/docs/resources/guild#delete-guild
|
||||
router.post("/", route({}), async (req: Request, res: Response) => {
|
||||
var { guild_id } = req.params;
|
||||
let { guild_id } = req.params;
|
||||
|
||||
const guild = await Guild.findOneOrFail({
|
||||
where: { id: guild_id },
|
||||
|
@ -50,7 +50,7 @@ router.patch(
|
||||
"MANAGE_GUILDS",
|
||||
);
|
||||
|
||||
var guild = await Guild.findOneOrFail({
|
||||
let guild = await Guild.findOneOrFail({
|
||||
where: { id: guild_id },
|
||||
relations: ["emojis", "roles", "stickers"],
|
||||
});
|
||||
@ -92,7 +92,7 @@ router.patch(
|
||||
"DISCOVERABLE",
|
||||
];
|
||||
|
||||
for (var feature of diff) {
|
||||
for (let feature of diff) {
|
||||
if (MUTABLE_FEATURES.includes(feature)) continue;
|
||||
|
||||
throw FosscordApiErrors.FEATURE_IS_IMMUTABLE.withParams(
|
||||
|
@ -91,19 +91,19 @@ router.put("/", route({}), async (req: Request, res: Response) => {
|
||||
// TODO: join others by controller
|
||||
}
|
||||
|
||||
var guild = await Guild.findOneOrFail({
|
||||
let guild = await Guild.findOneOrFail({
|
||||
where: { id: guild_id },
|
||||
});
|
||||
|
||||
var emoji = await Emoji.find({
|
||||
let emoji = await Emoji.find({
|
||||
where: { guild_id: guild_id },
|
||||
});
|
||||
|
||||
var roles = await Role.find({
|
||||
let roles = await Role.find({
|
||||
where: { guild_id: guild_id },
|
||||
});
|
||||
|
||||
var stickers = await Sticker.find({
|
||||
let stickers = await Sticker.find({
|
||||
where: { guild_id: guild_id },
|
||||
});
|
||||
|
||||
|
@ -8,8 +8,8 @@ router.patch(
|
||||
"/",
|
||||
route({ body: "MemberNickChangeSchema" }),
|
||||
async (req: Request, res: Response) => {
|
||||
var { guild_id, member_id } = req.params;
|
||||
var permissionString: PermissionResolvable = "MANAGE_NICKNAMES";
|
||||
let { guild_id, member_id } = req.params;
|
||||
let permissionString: PermissionResolvable = "MANAGE_NICKNAMES";
|
||||
if (member_id === "@me") {
|
||||
member_id = req.user_id;
|
||||
permissionString = "CHANGE_NICKNAME";
|
||||
|
@ -44,7 +44,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
||||
if (!permissions.has("READ_MESSAGE_HISTORY"))
|
||||
return res.json({ messages: [], total_results: 0 });
|
||||
|
||||
var query: FindManyOptions<Message> = {
|
||||
let query: FindManyOptions<Message> = {
|
||||
order: {
|
||||
timestamp: sort_order
|
||||
? (sort_order.toUpperCase() as "ASC" | "DESC")
|
||||
@ -78,7 +78,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
||||
});
|
||||
const ids = [];
|
||||
|
||||
for (var channel of channels) {
|
||||
for (let channel of channels) {
|
||||
const perm = await getPermission(
|
||||
req.user_id,
|
||||
req.params.guild_id,
|
||||
|
@ -11,16 +11,16 @@ export const inactiveMembers = async (
|
||||
days: number,
|
||||
roles: string[] = [],
|
||||
) => {
|
||||
var date = new Date();
|
||||
let date = new Date();
|
||||
date.setDate(date.getDate() - days);
|
||||
//Snowflake should have `generateFromTime` method? Or similar?
|
||||
var minId = BigInt(date.valueOf() - Snowflake.EPOCH) << BigInt(22);
|
||||
let minId = BigInt(date.valueOf() - Snowflake.EPOCH) << BigInt(22);
|
||||
|
||||
/**
|
||||
idea: ability to customise the cutoff variable
|
||||
possible candidates: public read receipt, last presence, last VC leave
|
||||
**/
|
||||
var members = await Member.find({
|
||||
let members = await Member.find({
|
||||
where: [
|
||||
{
|
||||
guild_id,
|
||||
@ -65,7 +65,7 @@ export const inactiveMembers = async (
|
||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||
const days = parseInt(req.query.days as string);
|
||||
|
||||
var roles = req.query.include_roles;
|
||||
let roles = req.query.include_roles;
|
||||
if (typeof roles === "string") roles = [roles]; //express will return array otherwise
|
||||
|
||||
const members = await inactiveMembers(
|
||||
@ -84,7 +84,7 @@ router.post(
|
||||
async (req: Request, res: Response) => {
|
||||
const days = parseInt(req.body.days);
|
||||
|
||||
var roles = req.query.include_roles;
|
||||
let roles = req.query.include_roles;
|
||||
if (typeof roles === "string") roles = [roles];
|
||||
|
||||
const { guild_id } = req.params;
|
||||
|
@ -26,7 +26,7 @@ const TemplateGuildProjection: (keyof Guild)[] = [
|
||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||
const { guild_id } = req.params;
|
||||
|
||||
var templates = await Template.find({
|
||||
let templates = await Template.find({
|
||||
where: { source_guild_id: guild_id },
|
||||
});
|
||||
|
||||
|
@ -19,7 +19,7 @@ router.patch(
|
||||
route({ body: "VoiceStateUpdateSchema" }),
|
||||
async (req: Request, res: Response) => {
|
||||
const body = req.body as VoiceStateUpdateSchema;
|
||||
var { guild_id, user_id } = req.params;
|
||||
let { guild_id, user_id } = req.params;
|
||||
if (user_id === "@me") user_id = req.user_id;
|
||||
|
||||
const perms = await getPermission(
|
||||
|
@ -28,7 +28,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
||||
if (!guild.widget_enabled) throw new HTTPError("Widget Disabled", 404);
|
||||
|
||||
// Fetch existing widget invite for widget channel
|
||||
var invite = await Invite.findOne({
|
||||
let invite = await Invite.findOne({
|
||||
where: { channel_id: guild.widget_channel_id },
|
||||
});
|
||||
|
||||
|
@ -35,8 +35,8 @@ router.get(
|
||||
relations: ["connected_accounts"],
|
||||
});
|
||||
|
||||
var mutual_guilds: object[] = [];
|
||||
var premium_guild_since;
|
||||
let mutual_guilds: object[] = [];
|
||||
let premium_guild_since;
|
||||
|
||||
if (with_mutual_guilds == "true") {
|
||||
const requested_member = await Member.find({
|
||||
|
@ -18,7 +18,7 @@ router.get(
|
||||
"/",
|
||||
route({ test: { response: { body: "UserRelationsResponse" } } }),
|
||||
async (req: Request, res: Response) => {
|
||||
var mutual_relations: object[] = [];
|
||||
let mutual_relations: object[] = [];
|
||||
const requested_relations = await User.findOneOrFail({
|
||||
where: { id: req.params.id },
|
||||
relations: ["relationships"],
|
||||
@ -35,7 +35,7 @@ router.get(
|
||||
rmem.type === 1 &&
|
||||
rmem.to_id !== req.user_id
|
||||
) {
|
||||
var relation_user = await User.getPublicUser(rmem.to_id);
|
||||
let relation_user = await User.getPublicUser(rmem.to_id);
|
||||
|
||||
mutual_relations.push({
|
||||
id: relation_user.id,
|
||||
|
@ -25,7 +25,7 @@ router.patch(
|
||||
const body = req.body as UserGuildSettingsSchema;
|
||||
|
||||
if (body.channel_overrides) {
|
||||
for (var channel in body.channel_overrides) {
|
||||
for (let channel in body.channel_overrides) {
|
||||
Channel.findOneOrFail({ where: { id: channel } });
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ router.patch(
|
||||
});
|
||||
|
||||
// Populated on password change
|
||||
var newToken: string | undefined;
|
||||
let newToken: string | undefined;
|
||||
|
||||
if (body.avatar)
|
||||
body.avatar = await handleFile(
|
||||
@ -102,7 +102,7 @@ router.patch(
|
||||
}
|
||||
|
||||
if (body.username) {
|
||||
var check_username = body?.username?.replace(/\s/g, "");
|
||||
let check_username = body?.username?.replace(/\s/g, "");
|
||||
if (!check_username) {
|
||||
throw FieldErrors({
|
||||
username: {
|
||||
|
@ -20,7 +20,7 @@ router.post(
|
||||
|
||||
const user = await User.findOneOrFail({ where: { id: req.user_id } });
|
||||
|
||||
var codes: BackupCode[];
|
||||
let codes: BackupCode[];
|
||||
if (regenerate) {
|
||||
await BackupCode.update(
|
||||
{ user: { id: req.user_id } },
|
||||
|
@ -33,7 +33,7 @@ router.post(
|
||||
});
|
||||
}
|
||||
|
||||
var codes: BackupCode[];
|
||||
let codes: BackupCode[];
|
||||
if (regenerate) {
|
||||
await BackupCode.update(
|
||||
{ user: { id: req.user_id } },
|
||||
|
@ -157,7 +157,7 @@ async function updateRelationship(
|
||||
select: userProjection,
|
||||
});
|
||||
|
||||
var relationship = user.relationships.find((x) => x.to_id === id);
|
||||
let relationship = user.relationships.find((x) => x.to_id === id);
|
||||
const friendRequest = friend.relationships.find(
|
||||
(x) => x.to_id === req.user_id,
|
||||
);
|
||||
@ -201,13 +201,13 @@ async function updateRelationship(
|
||||
if (user.relationships.length >= maxFriends)
|
||||
throw DiscordApiErrors.MAXIMUM_FRIENDS.withParams(maxFriends);
|
||||
|
||||
var incoming_relationship = Relationship.create({
|
||||
let incoming_relationship = Relationship.create({
|
||||
nickname: undefined,
|
||||
type: RelationshipType.incoming,
|
||||
to: user,
|
||||
from: friend,
|
||||
});
|
||||
var outgoing_relationship = Relationship.create({
|
||||
let outgoing_relationship = Relationship.create({
|
||||
nickname: undefined,
|
||||
type: RelationshipType.outgoing,
|
||||
to: friend,
|
||||
|
@ -8,7 +8,7 @@ config();
|
||||
import { FosscordServer } from "./Server";
|
||||
import cluster from "cluster";
|
||||
import os from "os";
|
||||
var cores = 1;
|
||||
let cores = 1;
|
||||
try {
|
||||
cores = Number(process.env.THREADS) || os.cpus().length;
|
||||
} catch {
|
||||
@ -28,7 +28,7 @@ if (cluster.isPrimary && process.env.NODE_ENV == "production") {
|
||||
cluster.fork();
|
||||
});
|
||||
} else {
|
||||
var port = Number(process.env.PORT) || 3001;
|
||||
let port = Number(process.env.PORT) || 3001;
|
||||
|
||||
const server = new FosscordServer({ port });
|
||||
server.start().catch(console.error);
|
||||
|
@ -126,11 +126,11 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
|
||||
throw new HTTPError("Empty messages are not allowed", 50006);
|
||||
}
|
||||
|
||||
var content = opts.content;
|
||||
var mention_channel_ids = [] as string[];
|
||||
var mention_role_ids = [] as string[];
|
||||
var mention_user_ids = [] as string[];
|
||||
var mention_everyone = false;
|
||||
let content = opts.content;
|
||||
let mention_channel_ids = [] as string[];
|
||||
let mention_role_ids = [] as string[];
|
||||
let mention_user_ids = [] as string[];
|
||||
let mention_everyone = false;
|
||||
|
||||
if (content) {
|
||||
// TODO: explicit-only mentions
|
||||
@ -181,7 +181,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
|
||||
// TODO: cache link result in db
|
||||
export async function postHandleMessage(message: Message) {
|
||||
const content = message.content?.replace(/ *\`[^)]*\` */g, ""); // remove markdown
|
||||
var links = content?.match(LINK_REGEX);
|
||||
let links = content?.match(LINK_REGEX);
|
||||
if (!links) return;
|
||||
|
||||
const data = { ...message };
|
||||
@ -214,8 +214,8 @@ export async function postHandleMessage(message: Message) {
|
||||
// tried to use shorthand but types didn't like me L
|
||||
if (!Array.isArray(res)) res = [res];
|
||||
|
||||
for (var embed of res) {
|
||||
var cache = EmbedCache.create({
|
||||
for (let embed of res) {
|
||||
let cache = EmbedCache.create({
|
||||
url: link,
|
||||
embed: embed,
|
||||
});
|
||||
|
@ -43,7 +43,7 @@ export interface RouteOptions {
|
||||
}
|
||||
|
||||
export function route(opts: RouteOptions) {
|
||||
var validate: AnyValidateFunction<any> | undefined;
|
||||
let validate: AnyValidateFunction<any> | undefined;
|
||||
if (opts.body) {
|
||||
validate = ajv.getSchema(opts.body);
|
||||
if (!validate) throw new Error(`Body schema ${opts.body} not found`);
|
||||
|
@ -20,7 +20,7 @@ const blocklist: string[] = []; // TODO: update ones passwordblocklist is stored
|
||||
export function checkPassword(password: string): number {
|
||||
const { minLength, minNumbers, minUpperCase, minSymbols } =
|
||||
Config.get().register.password;
|
||||
var strength = 0;
|
||||
let strength = 0;
|
||||
|
||||
// checks for total password len
|
||||
if (password.length >= minLength - 1) {
|
||||
|
@ -28,7 +28,7 @@ export function initStats() {
|
||||
// osu.mem.info(),
|
||||
// osu.netstat.inOut(),
|
||||
// ]);
|
||||
// var networkUsage = "";
|
||||
// let networkUsage = "";
|
||||
// if (typeof network === "object") {
|
||||
// networkUsage = `| [Network]: in ${network.total.inputMb}mb | out ${network.total.outputMb}mb`;
|
||||
// }
|
||||
|
@ -35,8 +35,8 @@ router.post(
|
||||
Config.get()?.cdn.endpointPublic || "http://localhost:3003";
|
||||
|
||||
await storage.set(path, buffer);
|
||||
var width;
|
||||
var height;
|
||||
let width;
|
||||
let height;
|
||||
if (mimetype.includes("image")) {
|
||||
const dimensions = imageSize(buffer);
|
||||
if (dimensions) {
|
||||
|
@ -33,7 +33,7 @@ router.post(
|
||||
const { buffer, mimetype, size, originalname, fieldname } = req.file;
|
||||
const { user_id } = req.params;
|
||||
|
||||
var hash = crypto
|
||||
let hash = crypto
|
||||
.createHash("md5")
|
||||
.update(Snowflake.generate())
|
||||
.digest("hex");
|
||||
@ -59,7 +59,7 @@ router.post(
|
||||
);
|
||||
|
||||
router.get("/:user_id", async (req: Request, res: Response) => {
|
||||
var { user_id } = req.params;
|
||||
let { user_id } = req.params;
|
||||
user_id = user_id.split(".")[0]; // remove .file extension
|
||||
const path = `avatars/${user_id}`;
|
||||
|
||||
@ -74,7 +74,7 @@ router.get("/:user_id", async (req: Request, res: Response) => {
|
||||
});
|
||||
|
||||
export const getAvatar = async (req: Request, res: Response) => {
|
||||
var { user_id, hash } = req.params;
|
||||
let { user_id, hash } = req.params;
|
||||
hash = hash.split(".")[0]; // remove .file extension
|
||||
const path = `avatars/${user_id}/${hash}`;
|
||||
|
||||
|
@ -33,7 +33,7 @@ router.post(
|
||||
const { buffer, mimetype, size, originalname, fieldname } = req.file;
|
||||
const { role_id } = req.params;
|
||||
|
||||
var hash = crypto
|
||||
let hash = crypto
|
||||
.createHash("md5")
|
||||
.update(Snowflake.generate())
|
||||
.digest("hex");
|
||||
@ -58,7 +58,7 @@ router.post(
|
||||
);
|
||||
|
||||
router.get("/:role_id", async (req: Request, res: Response) => {
|
||||
var { role_id } = req.params;
|
||||
let { role_id } = req.params;
|
||||
//role_id = role_id.split(".")[0]; // remove .file extension
|
||||
const path = `role-icons/${role_id}`;
|
||||
|
||||
@ -73,7 +73,7 @@ router.get("/:role_id", async (req: Request, res: Response) => {
|
||||
});
|
||||
|
||||
router.get("/:role_id/:hash", async (req: Request, res: Response) => {
|
||||
var { role_id, hash } = req.params;
|
||||
let { role_id, hash } = req.params;
|
||||
//hash = hash.split(".")[0]; // remove .file extension
|
||||
const path = `role-icons/${role_id}/${hash}`;
|
||||
|
||||
|
@ -10,7 +10,7 @@ import ExifTransformer from "exif-be-gone";
|
||||
function getPath(path: string) {
|
||||
// STORAGE_LOCATION has a default value in start.ts
|
||||
const root = process.env.STORAGE_LOCATION || "../";
|
||||
var filename = join(root, path);
|
||||
let filename = join(root, path);
|
||||
|
||||
if (path.indexOf("\0") !== -1 || !filename.startsWith(root))
|
||||
throw new Error("invalid path");
|
||||
|
@ -9,7 +9,7 @@ import { Message } from "./Message";
|
||||
import { Deflate, Inflate } from "fast-zlib";
|
||||
import { URL } from "url";
|
||||
import { Config } from "@fosscord/util";
|
||||
var erlpack: any;
|
||||
let erlpack: any;
|
||||
try {
|
||||
erlpack = require("@yukikaze-bot/erlpack");
|
||||
} catch (error) {}
|
||||
|
@ -9,14 +9,14 @@ import path from "path";
|
||||
import fs from "fs/promises";
|
||||
const bigIntJson = BigIntJson({ storeAsString: true });
|
||||
|
||||
var erlpack: any;
|
||||
let erlpack: any;
|
||||
try {
|
||||
erlpack = require("@yukikaze-bot/erlpack");
|
||||
} catch (error) {}
|
||||
|
||||
export async function Message(this: WebSocket, buffer: WS.Data) {
|
||||
// TODO: compression
|
||||
var data: Payload;
|
||||
let data: Payload;
|
||||
|
||||
if (
|
||||
(buffer instanceof Buffer && buffer[0] === 123) || // ASCII 123 = `{`. Bad check for JSON
|
||||
@ -82,7 +82,7 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
|
||||
: undefined;
|
||||
|
||||
try {
|
||||
var ret = await OPCodeHandler.call(this, data);
|
||||
let ret = await OPCodeHandler.call(this, data);
|
||||
Sentry.withScope((scope) => {
|
||||
scope.setSpan(transaction);
|
||||
scope.setUser({ id: this.user_id });
|
||||
|
@ -49,7 +49,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
|
||||
|
||||
try {
|
||||
const { jwtSecret } = Config.get().security;
|
||||
var { decoded } = await checkToken(identify.token, jwtSecret); // will throw an error if invalid
|
||||
let { decoded } = await checkToken(identify.token, jwtSecret); // will throw an error if invalid
|
||||
} catch (error) {
|
||||
console.error("invalid token", error);
|
||||
return this.close(CLOSECODES.Authentication_failed);
|
||||
@ -127,7 +127,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
|
||||
return this.close(CLOSECODES.Invalid_shard);
|
||||
}
|
||||
}
|
||||
var users: PublicUser[] = [];
|
||||
let users: PublicUser[] = [];
|
||||
|
||||
const merged_members = members.map((x: Member) => {
|
||||
return [
|
||||
@ -145,7 +145,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
|
||||
guilds = guilds.map((guild) => {
|
||||
if (user.bot) {
|
||||
setTimeout(() => {
|
||||
var promise = Send(this, {
|
||||
let promise = Send(this, {
|
||||
op: OPCODES.Dispatch,
|
||||
t: EVENTEnum.GuildCreate,
|
||||
s: this.sequence++,
|
||||
|
@ -108,7 +108,7 @@ async function getMembers(guild_id: string, range: [number, number]) {
|
||||
(a.activities.length - b.activities.length) * 2
|
||||
);
|
||||
});
|
||||
var session: Session | undefined = sessions.first();
|
||||
let session: Session | undefined = sessions.first();
|
||||
|
||||
if (session?.status == "offline") {
|
||||
session.status = member?.user?.settings?.status || "online";
|
||||
|
@ -6,7 +6,7 @@ import { Server } from "./Server";
|
||||
import { config } from "dotenv";
|
||||
config();
|
||||
|
||||
var port = Number(process.env.PORT);
|
||||
let port = Number(process.env.PORT);
|
||||
if (isNaN(port)) port = 3002;
|
||||
|
||||
const server = new Server({
|
||||
|
@ -1,4 +1,4 @@
|
||||
var erlpack: any;
|
||||
let erlpack: any;
|
||||
try {
|
||||
erlpack = require("@yukikaze-bot/erlpack");
|
||||
} catch (error) {
|
||||
|
@ -201,7 +201,7 @@ export class Channel extends BaseClass {
|
||||
!guild.features.includes("ALLOW_INVALID_CHANNEL_NAMES") &&
|
||||
channel.name
|
||||
) {
|
||||
for (var character of InvisibleCharacters)
|
||||
for (let character of InvisibleCharacters)
|
||||
if (channel.name.includes(character))
|
||||
throw new HTTPError(
|
||||
"Channel name cannot include invalid characters",
|
||||
|
@ -355,9 +355,9 @@ export class Guild extends BaseClass {
|
||||
for (const channel of body.channels?.sort((a, b) =>
|
||||
a.parent_id ? 1 : -1,
|
||||
)) {
|
||||
var id = ids.get(channel.id) || Snowflake.generate();
|
||||
let id = ids.get(channel.id) || Snowflake.generate();
|
||||
|
||||
var parent_id = ids.get(channel.parent_id);
|
||||
let parent_id = ids.get(channel.parent_id);
|
||||
|
||||
await Channel.createChannel(
|
||||
{ ...channel, guild_id, id, parent_id },
|
||||
|
@ -18,7 +18,7 @@ export function enableAutoUpdate(opts: {
|
||||
downloadType?: "zip";
|
||||
}) {
|
||||
if (!opts.checkInterval) return;
|
||||
var interval = 1000 * 60 * 60 * 24;
|
||||
let interval = 1000 * 60 * 60 * 24;
|
||||
if (typeof opts.checkInterval === "number")
|
||||
opts.checkInterval = 1000 * interval;
|
||||
|
||||
|
@ -6,8 +6,8 @@ import { ConfigValue } from "../config";
|
||||
// TODO: yaml instead of json
|
||||
const overridePath = process.env.CONFIG_PATH ?? "";
|
||||
|
||||
var config: ConfigValue;
|
||||
var pairs: ConfigEntity[];
|
||||
let config: ConfigValue;
|
||||
let pairs: ConfigEntity[];
|
||||
|
||||
// TODO: use events to inform about config updates
|
||||
// Config keys are separated with _
|
||||
@ -89,7 +89,7 @@ function applyConfig(val: ConfigValue) {
|
||||
}
|
||||
|
||||
function pairsToConfig(pairs: ConfigEntity[]) {
|
||||
var value: any = {};
|
||||
let value: any = {};
|
||||
|
||||
pairs.forEach((p) => {
|
||||
const keys = p.key.split("_");
|
||||
|
@ -7,7 +7,7 @@ import path from "path";
|
||||
// UUID extension option is only supported with postgres
|
||||
// We want to generate all id's with Snowflakes that's why we have our own BaseEntity class
|
||||
|
||||
var dbConnection: DataSource | undefined;
|
||||
let dbConnection: DataSource | undefined;
|
||||
|
||||
// For typeorm cli
|
||||
if (!process.env) {
|
||||
|
@ -11,7 +11,7 @@ import { BitField } from "./BitField";
|
||||
import "missing-native-js-functions";
|
||||
import { BitFieldResolvable, BitFlag } from "./BitField";
|
||||
|
||||
var HTTPError: any;
|
||||
let HTTPError: any;
|
||||
|
||||
try {
|
||||
HTTPError = require("lambert-server").HTTPError;
|
||||
@ -242,9 +242,9 @@ export async function getPermission(
|
||||
} = {},
|
||||
) {
|
||||
if (!user_id) throw new HTTPError("User not found");
|
||||
var channel: Channel | undefined;
|
||||
var member: Member | undefined;
|
||||
var guild: Guild | undefined;
|
||||
let channel: Channel | undefined;
|
||||
let member: Member | undefined;
|
||||
let guild: Guild | undefined;
|
||||
|
||||
if (channel_id) {
|
||||
channel = await Channel.findOneOrFail({
|
||||
@ -293,7 +293,7 @@ export async function getPermission(
|
||||
if (!recipient_ids?.length) recipient_ids = null;
|
||||
|
||||
// TODO: remove guild.roles and convert recipient_ids to recipients
|
||||
var permission = Permissions.finalPermission({
|
||||
let permission = Permissions.finalPermission({
|
||||
user: {
|
||||
id: user_id,
|
||||
roles: member?.roles.map((x) => x.id) || [],
|
||||
|
@ -3,7 +3,7 @@ import "missing-native-js-functions";
|
||||
import { BitFieldResolvable, BitFlag } from "./BitField";
|
||||
import { User } from "../entities";
|
||||
|
||||
var HTTPError: any;
|
||||
let HTTPError: any;
|
||||
|
||||
try {
|
||||
HTTPError = require("lambert-server").HTTPError;
|
||||
|
@ -87,10 +87,10 @@ export class Snowflake {
|
||||
|
||||
static generateWorkerProcess() {
|
||||
// worker process - returns a number
|
||||
var time = BigInt(Date.now() - Snowflake.EPOCH) << BigInt(22);
|
||||
var worker = Snowflake.workerId << 17n;
|
||||
var process = Snowflake.processId << 12n;
|
||||
var increment = Snowflake.INCREMENT++;
|
||||
let time = BigInt(Date.now() - Snowflake.EPOCH) << BigInt(22);
|
||||
let worker = Snowflake.workerId << 17n;
|
||||
let process = Snowflake.processId << 12n;
|
||||
let increment = Snowflake.INCREMENT++;
|
||||
return BigInt(time | worker | process | increment);
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import WS from "ws";
|
||||
import { VoiceOPCodes } from "../util";
|
||||
import { onClose } from "./Close";
|
||||
import { onMessage } from "./Message";
|
||||
var erlpack: any;
|
||||
let erlpack: any;
|
||||
try {
|
||||
erlpack = require("@yukikaze-bot/erlpack");
|
||||
} catch (error) {}
|
||||
|
@ -12,7 +12,7 @@ const PayloadSchema = {
|
||||
|
||||
export async function onMessage(this: WebSocket, buffer: Buffer) {
|
||||
try {
|
||||
var data: Payload = JSON.parse(buffer.toString());
|
||||
let data: Payload = JSON.parse(buffer.toString());
|
||||
if (data.op !== VoiceOPCodes.IDENTIFY && !this.user_id)
|
||||
return this.close(CLOSECODES.Not_authenticated);
|
||||
|
||||
|
@ -14,7 +14,7 @@ export async function onVideo(this: WebSocket, payload: Payload) {
|
||||
|
||||
const id = "stream" + this.user_id;
|
||||
|
||||
var stream = this.client.in.stream!;
|
||||
let stream = this.client.in.stream!;
|
||||
if (!stream) {
|
||||
stream = this.client.transport!.createIncomingStream(
|
||||
// @ts-ignore
|
||||
@ -88,7 +88,7 @@ function attachTrack(
|
||||
);
|
||||
outTrack.attachTo(track);
|
||||
this.client.out.stream!.addTrack(outTrack);
|
||||
var ssrcs = this.client.out.tracks.get(user_id)!;
|
||||
let ssrcs = this.client.out.tracks.get(user_id)!;
|
||||
if (!ssrcs)
|
||||
ssrcs = this.client.out.tracks
|
||||
.set(user_id, { audio_ssrc: 0, rtx_ssrc: 0, video_ssrc: 0 })
|
||||
@ -116,7 +116,7 @@ function handleSSRC(this: WebSocket, type: "audio" | "video", ssrcs: SSRCs) {
|
||||
const transport = this.client.transport!;
|
||||
|
||||
const id = type + ssrcs.media;
|
||||
var track = stream.getTrack(id);
|
||||
let track = stream.getTrack(id);
|
||||
if (!track) {
|
||||
console.log("createIncomingStreamTrack", id);
|
||||
track = transport.createIncomingStreamTrack(type, { id, ssrcs });
|
||||
|
@ -11,7 +11,7 @@ export const PublicIP = process.env.PUBLIC_IP || "127.0.0.1";
|
||||
|
||||
try {
|
||||
const range = process.env.WEBRTC_PORT_RANGE || "4000";
|
||||
var ports = range.split("-");
|
||||
let ports = range.split("-");
|
||||
const min = Number(ports[0]);
|
||||
const max = Number(ports[1]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user