mirror of
https://github.com/spacebarchat/server.git
synced 2026-05-06 04:55:49 +00:00
switch to harmony-erlpack
This commit is contained in:
Generated
BIN
Binary file not shown.
+1
-1
@@ -98,6 +98,7 @@
|
||||
"fido2-lib": "^3.5.9",
|
||||
"file-type": "^22.0.1",
|
||||
"form-data": "^4.0.5",
|
||||
"harmony-erlpack": "^0.0.1",
|
||||
"i18next": "^26.0.6",
|
||||
"i18next-fs-backend": "^2.6.4",
|
||||
"i18next-http-middleware": "^3.9.3",
|
||||
@@ -131,7 +132,6 @@
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@sendgrid/mail": "^8.1.6",
|
||||
"@yukikaze-bot/erlpack": "^1.0.1",
|
||||
"jimp": "^1.6.1",
|
||||
"mailgun.js": "^13.0.0",
|
||||
"node-mailjet": "^6.0.11",
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
*/
|
||||
|
||||
import { CLOSECODES, Payload, WebSocket } from "@spacebar/gateway";
|
||||
import { ErlpackType } from "@spacebar/util";
|
||||
// import { ErlpackType } from "@spacebar/util";
|
||||
import * as erlpack from "harmony-erlpack";
|
||||
import fs from "node:fs/promises";
|
||||
import BigIntJson from "json-bigint";
|
||||
import path from "node:path";
|
||||
@@ -28,12 +29,12 @@ 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);
|
||||
}
|
||||
// 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
|
||||
@@ -61,7 +62,8 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
|
||||
data = bigIntJson.parse(buffer as string);
|
||||
} else if (this.encoding === "etf" && Buffer.isBuffer(buffer) && erlpack) {
|
||||
try {
|
||||
data = erlpack.unpack(buffer);
|
||||
// cast is ~safe: unpack returns the parsed data in the shape it was provided, @yukikaze-bot/erlpack got around this by returning `any` instead of an actual type union.
|
||||
data = erlpack.unpack(buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength)) as unknown as Payload;
|
||||
} catch {
|
||||
console.error(`[Gateway/${this.user_id ?? this.ipAddress}] Failed to decode ETF payload`);
|
||||
return this.close(CLOSECODES.Decode_error);
|
||||
|
||||
@@ -21,12 +21,14 @@ import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import { ErlpackType, JSONReplacer } from "@spacebar/util";
|
||||
let erlpack: ErlpackType | null = null;
|
||||
try {
|
||||
erlpack = require("@yukikaze-bot/erlpack") as ErlpackType;
|
||||
} catch (e) {
|
||||
console.log("Failed to import @yukikaze-bot/erlpack: ", e);
|
||||
}
|
||||
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
|
||||
@@ -58,7 +60,7 @@ export async function Send(socket: WebSocket, data: Payload) {
|
||||
if (socket.encoding === "etf" && erlpack) {
|
||||
// Erlpack doesn't like Date objects, encodes them as {}
|
||||
data = recurseJsonReplace(data);
|
||||
buffer = erlpack.pack(data);
|
||||
buffer = Buffer.from(erlpack.pack(data));
|
||||
}
|
||||
// TODO: encode circular object
|
||||
else if (socket.encoding === "json") buffer = JSON.stringify(data, JSONReplacer);
|
||||
|
||||
Reference in New Issue
Block a user