ByMykel / CSGO-API

An unofficial JSON API for Counter-Strike 2 in multiples languages. List of skins, cases, stickers, collections, collectibles, agents, graffiti, keys, patches and music kits.
https://bymykel.github.io/CSGO-API/
MIT License
296 stars 34 forks source link

formatSkinImage broke superconductor image path #111

Closed antal-k closed 8 months ago

antal-k commented 8 months ago
export const formatSkinImage = (url, wear) => {
    if (
        ["SFUI_InvTooltip_Wear_Amount_2", "SFUI_InvTooltip_Wear_Amount_3"].includes(
            wear
        )
    ) {
        url = url.replace("_light_", "_medium_");
    }

    if (["SFUI_InvTooltip_Wear_Amount_4"].includes(wear)) {
        url = url.replace("_light_", "_heavy_");
    }

    // Return the image as it is with _light_
    return url;
};

Generated file name: sporty_gloves_sporty_heavy_blue_light_png.png

Original file name: sporty_gloves_sporty_light_blue_light_png.png

Should be: sporty_gloves_sporty_light_blue_heavy_png.png

Fix can be this way (not the nicest):

export const formatSkinImage = (url, wear) => {
    // some skin have 2 _light_ in the url, we need to replace the last with _medium_ or _heavy_
    const regex = /_light_/g;
    const matches = url.match(regex);

    if (matches && matches.length > 1) {
        // Replace the first _light_ with _ll_
        url = url.replace("_light_", "_ll_");
    }

    if (
        ["SFUI_InvTooltip_Wear_Amount_2", "SFUI_InvTooltip_Wear_Amount_3"].includes(
            wear
        )
    ) {
        url = url.replace("_light_", "_medium_");
    }

    if (["SFUI_InvTooltip_Wear_Amount_4"].includes(wear)) {
        url = url.replace("_light_", "_heavy_");
    }

    return url.replace("_ll_", "_light_");
};
ByMykel commented 8 months ago

I'm gonna make this changes:

export const formatSkinImage = (url, wear) => {
    if (
        [
            "SFUI_InvTooltip_Wear_Amount_2",
            "SFUI_InvTooltip_Wear_Amount_3",
        ].includes(wear)
    ) {
        url = url.replace("_light_png", "_medium_png");
    }

    if (["SFUI_InvTooltip_Wear_Amount_4"].includes(wear)) {
        url = url.replace("_light_png", "_heavy_png");
    }

    // Return the image as it is with _light_
    return url;
};

My brain doesn't work on weekends to use regex.

ByMykel commented 8 months ago

Thank you very much ❤️