diff --git a/src/api/Server.ts b/src/api/Server.ts
index 1e5786ed..a2e63f46 100644
--- a/src/api/Server.ts
+++ b/src/api/Server.ts
@@ -21,7 +21,7 @@ import { Authentication, CORS, ImageProxy, BodyParser, ErrorHandler, initRateLim
import { Request, Response, Router } from "express";
import { Server, ServerOptions } from "lambert-server";
import morgan from "morgan";
-import path from "path";
+import path from "node:path";
import { red } from "picocolors";
import { initInstance } from "./util/handlers/Instance";
import { route } from "./util";
diff --git a/src/api/middlewares/ImageProxy.ts b/src/api/middlewares/ImageProxy.ts
index e950ea85..66d39bd6 100644
--- a/src/api/middlewares/ImageProxy.ts
+++ b/src/api/middlewares/ImageProxy.ts
@@ -19,7 +19,7 @@
import { Config, JimpType } from "@spacebar/util";
import { Request, Response } from "express";
import { yellow } from "picocolors";
-import crypto from "crypto";
+import crypto from "node:crypto";
let sharp: undefined | false | { default: typeof import("sharp") } = undefined;
diff --git a/src/api/middlewares/Translation.ts b/src/api/middlewares/Translation.ts
index 3ca204b6..1d8e0984 100644
--- a/src/api/middlewares/Translation.ts
+++ b/src/api/middlewares/Translation.ts
@@ -16,8 +16,8 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import fs from "fs";
-import path from "path";
+import fs from "node:fs";
+import path from "node:path";
import i18next from "i18next";
import i18nextMiddleware from "i18next-http-middleware";
import i18nextBackend from "i18next-fs-backend";
diff --git a/src/api/routes/auth/login.ts b/src/api/routes/auth/login.ts
index 466d264a..64211de8 100644
--- a/src/api/routes/auth/login.ts
+++ b/src/api/routes/auth/login.ts
@@ -19,7 +19,7 @@
import { route, verifyCaptcha } from "@spacebar/api";
import { Config, FieldErrors, User, WebAuthn, generateToken, generateWebAuthnTicket } from "@spacebar/util";
import bcrypt from "bcrypt";
-import crypto from "crypto";
+import crypto from "node:crypto";
import { Request, Response, Router } from "express";
import { LoginSchema } from "@spacebar/schemas";
diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts
index a484c35c..b117e3ac 100644
--- a/src/api/routes/channels/#channel_id/messages/index.ts
+++ b/src/api/routes/channels/#channel_id/messages/index.ts
@@ -47,7 +47,7 @@ import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
import multer from "multer";
import { FindManyOptions, FindOperator, LessThan, MoreThan, MoreThanOrEqual } from "typeorm";
-import { URL } from "url";
+import { URL } from "node:url";
import {
AcknowledgeDeleteSchema,
isTextChannel,
@@ -438,19 +438,22 @@ router.post(
// Only one recipients should be closed here, since in group DMs the recipient is deleted not closed
await Promise.all(
- channel.recipients?.map((recipient) => {
- if (recipient.closed) {
- recipient.closed = false;
- return Promise.all([
- recipient.save(),
- emitEvent({
- event: "CHANNEL_CREATE",
- data: channel_dto.excludedRecipients([recipient.user_id]),
- user_id: recipient.user_id,
- }),
- ]);
- }
- }) || [],
+ channel.recipients
+ ?.map((recipient) => {
+ if (recipient.closed) {
+ recipient.closed = false;
+ return Promise.all([
+ recipient.save(),
+ emitEvent({
+ event: "CHANNEL_CREATE",
+ data: channel_dto.excludedRecipients([recipient.user_id]),
+ user_id: recipient.user_id,
+ }),
+ ]);
+ }
+ return null;
+ })
+ .filter((x) => x !== null) || [],
);
}
diff --git a/src/api/routes/channels/#channel_id/webhooks.ts b/src/api/routes/channels/#channel_id/webhooks.ts
index ee801db7..ed2dd0ea 100644
--- a/src/api/routes/channels/#channel_id/webhooks.ts
+++ b/src/api/routes/channels/#channel_id/webhooks.ts
@@ -18,7 +18,7 @@
import { route } from "@spacebar/api";
import { Channel, Config, DiscordApiErrors, User, Webhook, handleFile, trimSpecial, ValidateName, Application } from "@spacebar/util";
-import crypto from "crypto";
+import crypto from "node:crypto";
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
import { isTextChannel, WebhookCreateSchema, WebhookType } from "@spacebar/schemas";
diff --git a/src/api/routes/guilds/#guild_id/shield.svg.ts b/src/api/routes/guilds/#guild_id/shield.svg.ts
index bb5e1c7d..983e5a35 100644
--- a/src/api/routes/guilds/#guild_id/shield.svg.ts
+++ b/src/api/routes/guilds/#guild_id/shield.svg.ts
@@ -20,8 +20,8 @@ import { route } from "@spacebar/api";
import { DiscordApiErrors, Guild, Member } from "@spacebar/util";
import { Request, Response, Router } from "express";
import { makeBadge } from "badge-maker";
-import path from "path";
-import fs from "fs";
+import path from "node:path";
+import fs from "node:fs";
const router: Router = Router({ mergeParams: true });
diff --git a/src/api/routes/guilds/#guild_id/widget.json.ts b/src/api/routes/guilds/#guild_id/widget.json.ts
index 945a0db0..0df3f3c0 100644
--- a/src/api/routes/guilds/#guild_id/widget.json.ts
+++ b/src/api/routes/guilds/#guild_id/widget.json.ts
@@ -108,8 +108,8 @@ async function getWidgetJsonData(guild_id: string) {
// Fetch voice channels, and the @everyone permissions object
const channels: { id: string; name: string; position: number }[] = [];
- (await Channel.getOrderedChannels(guild.id, guild)).filter((doc) => {
- if (doc.type !== ChannelType.GUILD_VOICE) return false;
+ (await Channel.getOrderedChannels(guild.id, guild)).forEach((doc) => {
+ if (doc.type !== ChannelType.GUILD_VOICE) return;
// Only return voice channels where @everyone has the CONNECT permission
if (doc.permission_overwrites === undefined || Permissions.channelPermission(doc.permission_overwrites, Permissions.FLAGS.CONNECT) === Permissions.FLAGS.CONNECT) {
channels.push({
diff --git a/src/api/routes/guilds/#guild_id/widget.png.ts b/src/api/routes/guilds/#guild_id/widget.png.ts
index ee623214..000c1b45 100644
--- a/src/api/routes/guilds/#guild_id/widget.png.ts
+++ b/src/api/routes/guilds/#guild_id/widget.png.ts
@@ -21,9 +21,9 @@
import { route } from "@spacebar/api";
import { DiscordApiErrors, Guild } from "@spacebar/util";
import { Request, Response, Router } from "express";
-import fs from "fs";
+import fs from "node:fs";
import { HTTPError } from "lambert-server";
-import path from "path";
+import path from "node:path";
import { storage } from "@spacebar/cdn";
const router: Router = Router({ mergeParams: true });
diff --git a/src/api/routes/interactions/index.ts b/src/api/routes/interactions/index.ts
index 33375b14..599a364e 100644
--- a/src/api/routes/interactions/index.ts
+++ b/src/api/routes/interactions/index.ts
@@ -16,7 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import { randomBytes } from "crypto";
+import { randomBytes } from "node:crypto";
import { InteractionFailureReason, InteractionSchema } from "@spacebar/schemas";
import { route } from "@spacebar/api";
import { Request, Response, Router } from "express";
diff --git a/src/api/routes/reporting/index.ts b/src/api/routes/reporting/index.ts
index 20103c95..76b5169a 100644
--- a/src/api/routes/reporting/index.ts
+++ b/src/api/routes/reporting/index.ts
@@ -19,11 +19,11 @@
import { route } from "@spacebar/api";
import { Request, Response, Router } from "express";
import { ReportMenuType, ReportMenuTypeNames } from "../../../schemas/api/reports/ReportMenu";
-import path from "path";
+import path from "node:path";
import { HTTPError } from "lambert-server";
import { CreateReportSchema } from "../../../schemas/api/reports/CreateReport";
import { FieldErrors } from "@spacebar/util";
-import fs from "fs";
+import fs from "node:fs";
const router = Router({ mergeParams: true });
if (process.env.LOG_ROUTES !== "false") console.log("[Server] Registering reporting menu routes...");
diff --git a/src/api/start.ts b/src/api/start.ts
index 44e028a0..bb5b23ce 100644
--- a/src/api/start.ts
+++ b/src/api/start.ts
@@ -24,9 +24,9 @@ process.on("unhandledRejection", console.error);
import { config } from "dotenv";
config({ quiet: true });
import { SpacebarServer } from "./Server";
-import cluster from "cluster";
-import os from "os";
-import fs from "fs";
+import cluster from "node:cluster";
+import os from "node:os";
+import fs from "node:fs";
let cores = 1;
try {
cores = Number(process.env.THREADS) || os.cpus().length;
diff --git a/src/api/util/handlers/Instance.ts b/src/api/util/handlers/Instance.ts
index 6b8d1ec6..f899d07d 100644
--- a/src/api/util/handlers/Instance.ts
+++ b/src/api/util/handlers/Instance.ts
@@ -17,7 +17,7 @@
*/
import { Session, TimeSpan } from "@spacebar/util";
-import { setInterval } from "timers";
+import { setInterval } from "node:timers";
export async function initInstance() {
// TODO: clean up database and delete tombstone data
diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts
index ea42283f..3ebf50e4 100644
--- a/src/api/util/handlers/Message.ts
+++ b/src/api/util/handlers/Message.ts
@@ -16,13 +16,12 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import { EmbedHandlers, randomString, fillMessageUrlEmbeds } from "@spacebar/api";
+import { randomString, fillMessageUrlEmbeds } from "@spacebar/api";
import {
Application,
Attachment,
Channel,
Config,
- EmbedCache,
emitEvent,
EVERYONE_MENTION,
getPermission,
@@ -31,7 +30,6 @@ import {
HERE_MENTION,
Message,
MessageCreateEvent,
- MessageUpdateEvent,
Role,
ROLE_MENTION,
Sticker,
@@ -41,7 +39,6 @@ import {
Webhook,
handleFile,
Permissions,
- normalizeUrl,
DiscordApiErrors,
CloudAttachment,
ReadState,
@@ -49,7 +46,6 @@ import {
Session,
MessageFlags,
FieldErrors,
- Snowflake,
getDatabase,
} from "@spacebar/util";
import { HTTPError } from "lambert-server";
@@ -70,7 +66,6 @@ import {
UnfurledMediaItem,
BaseMessageComponents,
v1CompTypes,
- PartialUser,
} from "@spacebar/schemas";
const allow_empty = false;
// TODO: check webhook, application, system author, stickers
diff --git a/src/api/util/utility/EmbedHandlers.ts b/src/api/util/utility/EmbedHandlers.ts
index b799e623..e9165a13 100644
--- a/src/api/util/utility/EmbedHandlers.ts
+++ b/src/api/util/utility/EmbedHandlers.ts
@@ -19,7 +19,7 @@
import { arrayDistinctBy, arrayGroupBy, Config, EmbedCache, emitEvent, Message, MessageUpdateEvent, normalizeUrl, OrmUtils, sleep } from "@spacebar/util";
import { Embed, EmbedImage, EmbedType } from "@spacebar/schemas";
import * as cheerio from "cheerio";
-import crypto from "crypto";
+import crypto from "node:crypto";
import { yellow } from "picocolors";
import probe from "probe-image-size";
import { FindOptionsWhere, In } from "typeorm";
diff --git a/src/api/util/utility/RandomInviteID.ts b/src/api/util/utility/RandomInviteID.ts
index d7f2c629..ec54a9fc 100644
--- a/src/api/util/utility/RandomInviteID.ts
+++ b/src/api/util/utility/RandomInviteID.ts
@@ -17,7 +17,7 @@
*/
import { Snowflake } from "@spacebar/util";
-import crypto from "crypto";
+import crypto from "node:crypto";
// TODO: 'random'? seriously? who named this?
// And why is this even here? Just use cryto.randomBytes?
|