Skip to content

Commit

Permalink
fully remove getDimensions and now-unused dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Oct 17, 2023
1 parent cb47a4e commit 17dbb9c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 45 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"chalk": "^4.1.2",
"discord.js": "^14.13.0",
"gif-encoder-2": "^1.0.5",
"image-size": "^1.0.2",
"jszip": "^3.10.1",
"linux-os-info": "^2.0.0",
"moment": "^2.29.4",
Expand Down
17 changes: 0 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions src/helpers/functions/getTexture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ import { EmbedBuilder } from "@client";
import TokenJson from "@json/tokens.json";
import { Contributor, Tokens } from "@interfaces";
import axios from "axios";
import getDimensions from "@images/getDimensions";
import { APIEmbedField, AttachmentBuilder, Guild } from "discord.js";
import { magnify, magnifyToAttachment } from "@images/magnify";
import { ISizeCalculationResult } from "image-size/dist/types/interface";
import { colors } from "@utility/colors";
import { Texture, Contribution } from "@interfaces";
import { animateToAttachment } from "@images/animate";
import minecraftSorter from "@utility/minecraftSorter";
import formatName from "@utility/formatName";
import { textureButtons } from "@utility/buttons";
import { loadImage } from "@napi-rs/canvas";
import { Image, loadImage } from "@napi-rs/canvas";

/**
* Create a full texture embed with provided information
Expand Down Expand Up @@ -67,10 +65,9 @@ export const getTexture = async (options: {
}

// test if url isn't a 404
let dimension: ISizeCalculationResult;
let image: Image;
try {
// getDimensions also validates a url
dimension = await getDimensions(textureURL);
image = await loadImage(textureURL);
} catch (err) {
const errorEmbed = new EmbedBuilder()
.setTitle("Image not found!")
Expand All @@ -82,7 +79,7 @@ export const getTexture = async (options: {

embed
.setURL(`https://webapp.faithfulpack.net/#/gallery/java/32x/latest/all/?show=${texture.id}`)
.addFields({ name: "Resolution", value: `${dimension.width}×${dimension.height}` })
.addFields({ name: "Resolution", value: `${image.width}×${image.height}` })
.setThumbnail(textureURL)
.setImage(`attachment://${animated ? "animated.gif" : "magnified.png"}`);

Expand Down
5 changes: 2 additions & 3 deletions src/helpers/functions/textureComparison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
Message,
} from "@client";
import { addPathsToEmbed } from "@functions/getTexture";
import getDimensions from "@images/getDimensions";
import { Texture } from "@interfaces";
import axios from "axios";
import { ActionRowBuilder, ButtonBuilder } from "discord.js";
Expand Down Expand Up @@ -60,8 +59,8 @@ export default async function textureComparison(

const defaultURL = `${client.tokens.apiUrl}textures/${id}/url/default/latest`;

const dimension = await getDimensions(defaultURL);
if (dimension.width * dimension.height * displayed.flat().length > 262144) return null;
const baseImage = await loadImage(defaultURL);
if (baseImage.width * baseImage.height * displayed.flat().length > 262144) return null;

// get texture urls into 2d array using the parsed display
const loadedImages = [];
Expand Down
17 changes: 0 additions & 17 deletions src/helpers/images/getDimensions.ts

This file was deleted.

0 comments on commit 17dbb9c

Please sign in to comment.