Skip to content

Commit

Permalink
Fix widget.png guild icon loading
Browse files Browse the repository at this point in the history
  • Loading branch information
DEVTomatoCake committed Aug 18, 2024
1 parent f7f16db commit c505db0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/api/routes/guilds/#guild_id/widget.png.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
Copyright (C) 2023 Spacebar and Spacebar Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Expand All @@ -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();

Expand Down Expand Up @@ -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";

Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c505db0

Please sign in to comment.