mirror of
https://github.com/spacebarchat/server.git
synced 2026-05-26 07:35:07 +00:00
Clean up erlpack types
This commit is contained in:
+1
-9
@@ -157,14 +157,6 @@ export class SpacebarServer extends Server {
|
||||
|
||||
// new well-known location
|
||||
app.get("/.well-known/spacebar/client", (req, res) => {
|
||||
let erlpackSupported = false;
|
||||
try {
|
||||
require("@yukikaze-bot/erlpack");
|
||||
erlpackSupported = true;
|
||||
} catch (e) {
|
||||
// empty
|
||||
}
|
||||
|
||||
res.json({
|
||||
api: {
|
||||
baseUrl: Config.get().api.endpointPublic?.split("/api/")[0],
|
||||
@@ -178,7 +170,7 @@ export class SpacebarServer extends Server {
|
||||
},
|
||||
gateway: {
|
||||
baseUrl: Config.get().gateway.endpointPublic,
|
||||
encoding: [...(erlpackSupported ? ["etf"] : []), "json"],
|
||||
encoding: ["etf", "json"],
|
||||
compression: ["zstd-stream", "zlib-stream", null],
|
||||
},
|
||||
admin:
|
||||
|
||||
@@ -27,16 +27,9 @@ import { Close } from "./Close";
|
||||
import { Message } from "./Message";
|
||||
import { Deflate, Inflate } from "fast-zlib";
|
||||
import { URL } from "node:url";
|
||||
import { Config, ErlpackType } from "@spacebar/util";
|
||||
import { Config } from "@spacebar/util";
|
||||
import { Decoder, Encoder } from "@toondepauw/node-zstd";
|
||||
|
||||
let erlpack: ErlpackType | null = null;
|
||||
try {
|
||||
erlpack = require("@yukikaze-bot/erlpack") as ErlpackType;
|
||||
} catch (e) {
|
||||
console.log("Failed to import @yukikaze-bot/erlpack: ", e);
|
||||
}
|
||||
|
||||
// TODO: check rate limit
|
||||
// TODO: specify rate limit in config
|
||||
// TODO: check msg max size
|
||||
@@ -108,8 +101,6 @@ export async function Connection(this: WS.Server, socket: WebSocket, request: In
|
||||
return socket.close(CLOSECODES.Decode_error);
|
||||
}
|
||||
|
||||
if (socket.encoding === "etf" && !erlpack) throw new Error("Erlpack is not installed: 'npm i @yukikaze-bot/erlpack'");
|
||||
|
||||
socket.version = Number(searchParams.get("version")) || 8;
|
||||
if (socket.version != 8) {
|
||||
console.error(`[Gateway/${socket.ipAddress}] Invalid API version: ${socket.version}`);
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
|
||||
import { CLOSECODES, Payload, WebSocket } from "@spacebar/gateway";
|
||||
// import { ErlpackType } from "@spacebar/util";
|
||||
import * as erlpack from "harmony-erlpack";
|
||||
import fs from "node:fs/promises";
|
||||
import BigIntJson from "json-bigint";
|
||||
@@ -29,13 +28,6 @@ import { PayloadSchema } from "@spacebar/schemas";
|
||||
|
||||
const bigIntJson = BigIntJson({ storeAsString: true });
|
||||
|
||||
// let erlpack: ErlpackType | null = null;
|
||||
// try {
|
||||
// erlpack = require("@yukikaze-bot/erlpack") as ErlpackType;
|
||||
// } catch (e) {
|
||||
// console.log("Failed to import @yukikaze-bot/erlpack: ", e);
|
||||
// }
|
||||
|
||||
export async function Message(this: WebSocket, buffer: WS.Data) {
|
||||
// TODO: compression
|
||||
let data: Payload;
|
||||
|
||||
@@ -20,16 +20,9 @@ import { Payload, WebSocket } from "@spacebar/gateway";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import { ErlpackType, JSONReplacer } from "@spacebar/util";
|
||||
import { JSONReplacer } from "@spacebar/util";
|
||||
import * as erlpack from "harmony-erlpack";
|
||||
|
||||
// let erlpack: ErlpackType | null = null;
|
||||
// try {
|
||||
// erlpack = require("@yukikaze-bot/erlpack") as ErlpackType;
|
||||
// } catch (e) {
|
||||
// console.log("Failed to import @yukikaze-bot/erlpack: ", e);
|
||||
// }
|
||||
|
||||
// don't care
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const recurseJsonReplace = (json: any) => {
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
/*
|
||||
https://github.com/discord/erlpack/blob/master/js/index.d.ts
|
||||
MIT License
|
||||
Copyright (c) 2017 Discord
|
||||
*/
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
// @fc-license-skip
|
||||
|
||||
export type ErlpackType = {
|
||||
pack: (data: any) => Buffer;
|
||||
unpack: <T = any>(data: Buffer) => T;
|
||||
};
|
||||
@@ -17,6 +17,5 @@
|
||||
*/
|
||||
|
||||
export * from "./OrmUtils";
|
||||
export * from "./Erlpack";
|
||||
export * from "./Jimp";
|
||||
export * from "./Interactions";
|
||||
|
||||
Reference in New Issue
Block a user