Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrects missing images #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,12 @@ class CSGOCdn extends EventEmitter {
return;
}

const fileName = large ? `${name}_large.png` : `${name}.png`;
const foundName = name.split('/').pop().toLowerCase();

const fileName = large ? `${foundName}_large.png` : `${foundName}.png`;
const path = this.vpkFiles.find((t) => t.endsWith(fileName));

if (path) return this.getPathURL(path);
if (path) return this.getPathURL(path).replace('\r', '');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is eliminating the carriage return absolutely necessary? If it is, then it should be universally stripped during the parsing of the game files instead of scattered everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's necessary. Because URLs become https://steamcommunity.com/.../abcd.png\r or something like that.

You are right. I will change the replacer positions 👍

}

/**
Expand Down Expand Up @@ -475,7 +477,7 @@ class CSGOCdn extends EventEmitter {
// Get the image url
const cdnName = `${weaponName}_${skinName}`;

return this.itemsGameCDN[cdnName];
return this.itemsGameCDN[cdnName].replace('\r', '');
}

/**
Expand Down Expand Up @@ -543,7 +545,16 @@ class CSGOCdn extends EventEmitter {

if (!match) return;

const stickerName = match[1];
let stickerName = match[1];

const pharantesisWithSpaceIndex = stickerName.indexOf(' (');
const pharantesisWithoutSpaceIndex = stickerName.indexOf('(');

if( pharantesisWithSpaceIndex === -1 && pharantesisWithoutSpaceIndex > -1 ) {
const stickerNameArr = stickerName.split('');
stickerNameArr.splice(pharantesisWithoutSpaceIndex, 0, ' ');
stickerName = stickerNameArr.join('');
}

for (const tag of this.csgoEnglish['inverted'][stickerName] || []) {
const stickerTag = `#${tag}`;
Expand Down Expand Up @@ -614,7 +625,7 @@ class CSGOCdn extends EventEmitter {
const url = this.getStickerURL(kit.sticker_material, true);

if (url) {
return url;
return url.replace('\r', '');
}
}
}
Expand Down Expand Up @@ -713,7 +724,7 @@ class CSGOCdn extends EventEmitter {
const path = (paintKit ? `${weaponClass}_${paintKit}` : weaponClass).toLowerCase();

if (this.itemsGameCDN[path]) {
return this.itemsGameCDN[path];
return this.itemsGameCDN[path].replace('\r', '');
}
}
}
Expand Down Expand Up @@ -753,7 +764,7 @@ class CSGOCdn extends EventEmitter {
const url = this.getPathURL(path);

if (url) {
return url;
return url.replace('\r', '');
}
}
}
Expand Down Expand Up @@ -795,6 +806,10 @@ class CSGOCdn extends EventEmitter {
}
else {
// Other in items
if( marketHashName.indexOf('(Holo-Foil)') > -1 ) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, there was an issue earlier where these were misspellings my Valve. They don't have proper market pages, right? Seems hacky to do this conversion if Valve isn't bothered to do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is a hacky way to do it and not looking the right way. But people who are using this package want to see the correct results. Perhaps we can make hooks or interceptors where users can add their own hacky codes. What do you think about it?

marketHashName = marketHashName.replace('(Holo-Foil)', '(Holo/Foil)');
}

for (const t of this.csgoEnglish['inverted'][marketHashName] || []) {
const tag = `#${t.toLowerCase()}`;
const items = this.itemsGame.items;
Expand Down Expand Up @@ -827,7 +842,7 @@ class CSGOCdn extends EventEmitter {
const url = this.getPathURL(path);

if (url) {
return url;
return url.replace('\r', '');
}
}
}
Expand Down