1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-22 10:22:39 +01:00

Fix widget.png guild icon loading

This commit is contained in:
TomatoCake 2024-08-18 13:28:24 +02:00
parent f7f16db37e
commit c505db0723

View File

@ -24,6 +24,7 @@ import { Request, Response, Router } from "express";
import fs from "fs";
import { HTTPError } from "lambert-server";
import path from "path";
import { storage } from "../../../../cdn/util/Storage";
const router: Router = Router();
@ -51,7 +52,7 @@ router.get(
if (!guild.widget_enabled) throw new HTTPError("Unknown Guild", 404);
// Fetch guild information
const icon = guild.icon;
const icon = "avatars/" + guild_id + "/" + guild.icon;
const name = guild.name;
const presence = guild.presence_count + " ONLINE";
@ -69,8 +70,7 @@ router.get(
}
// Setup canvas
const { createCanvas } = require("canvas");
const { loadImage } = require("canvas");
const { createCanvas, loadImage } = require("canvas");
const sizeOf = require("image-size");
// TODO: Widget style templates need Spacebar branding
@ -211,8 +211,8 @@ async function drawIcon(
scale: number,
icon: string,
) {
const img = new (require("canvas").Image)();
img.src = icon;
const { loadImage } = require("canvas");
const img = await loadImage(await storage.get(icon));
// Do some canvas clipping magic!
canvas.save();