Skip to content

Commit

Permalink
Replace jsonpack with gzip compression
Browse files Browse the repository at this point in the history
  • Loading branch information
Vedal987 committed Jun 11, 2024
1 parent 5f3221b commit c31a827
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions ebs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dotenv": "^16.4.5",
"express": "^4.19.2",
"express-ws": "^5.0.2",
"fflate": "^0.8.2",
"jsonpack": "^1.1.5",
"jsonwebtoken": "^9.0.2",
"mysql2": "^3.10.0",
Expand Down
4 changes: 2 additions & 2 deletions ebs/src/modules/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Config } from "common/types";
import { app } from "../index";
import { sendPubSubMessage } from "../util/pubsub";
import { pack } from "jsonpack";
import { strToU8, compressSync, strFromU8 } from "fflate";
import { getBannedUsers } from "../util/db";

let config: Config | undefined;
Expand Down Expand Up @@ -40,7 +40,7 @@ export async function getConfig(): Promise<Config> {
export async function broadcastConfigRefresh(config: Config) {
return sendPubSubMessage({
type: "config_refreshed",
data: pack(config),
data: strFromU8(compressSync(strToU8(JSON.stringify(config)))),
});
}

Expand Down
3 changes: 3 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
"webpack-dev-server": "^5.0.4",
"webpack-merge": "^5.10.0",
"zip-webpack-plugin": "^4.0.1"
},
"dependencies": {
"fflate": "^0.8.2"
}
}
4 changes: 2 additions & 2 deletions frontend/www/src/modules/pubsub.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Config, PubSubMessage } from "common/types";
import { unpack } from "jsonpack";
import { postProcessConfig, setConfig } from "../util/config";
import { renderRedeemButtons } from "./redeems";
import { strToU8, decompressSync, strFromU8 } from "fflate";

Twitch.ext.listen("global", async (_t, _c, message) => {
const pubSubMessage = JSON.parse(message) as PubSubMessage;
Expand All @@ -10,7 +10,7 @@ Twitch.ext.listen("global", async (_t, _c, message) => {

switch (pubSubMessage.type) {
case "config_refreshed":
const config = unpack<Config>(pubSubMessage.data);
const config = JSON.parse(strFromU8(decompressSync(strToU8(pubSubMessage.data)))) as Config;
// console.log(config);
await setConfig(postProcessConfig(config));
await renderRedeemButtons();
Expand Down

0 comments on commit c31a827

Please sign in to comment.