From 19cf1da6fb514b6c0d0c65c02ecb64ca7306ba7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=C4=9Fuz=20=C3=96zcan?= Date: Thu, 20 Feb 2020 04:47:52 +0300 Subject: [PATCH 1/2] Corrects missing images (Fixed) Some paths have \r at the end of the path on Windows 10 environment. (Fixed) Some image paths not being found. https://github.com/Step7750/node-csgo-cdn/issues/21 --- index.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 12b858c..457f7a5 100644 --- a/index.js +++ b/index.js @@ -435,7 +435,7 @@ class CSGOCdn extends EventEmitter { const fileName = large ? `${name}_large.png` : `${name}.png`; const path = this.vpkFiles.find((t) => t.endsWith(fileName)); - if (path) return this.getPathURL(path); + if (path) return this.getPathURL(path).replace('\r', ''); } /** @@ -475,7 +475,7 @@ class CSGOCdn extends EventEmitter { // Get the image url const cdnName = `${weaponName}_${skinName}`; - return this.itemsGameCDN[cdnName]; + return this.itemsGameCDN[cdnName].replace('\r', ''); } /** @@ -543,7 +543,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}`; @@ -614,7 +623,7 @@ class CSGOCdn extends EventEmitter { const url = this.getStickerURL(kit.sticker_material, true); if (url) { - return url; + return url.replace('\r', ''); } } } @@ -713,7 +722,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', ''); } } } @@ -753,7 +762,7 @@ class CSGOCdn extends EventEmitter { const url = this.getPathURL(path); if (url) { - return url; + return url.replace('\r', ''); } } } @@ -795,6 +804,10 @@ class CSGOCdn extends EventEmitter { } else { // Other in items + if( marketHashName.indexOf('(Holo-Foil)') > -1 ) { + marketHashName = marketHashName.replace('(Holo-Foil)', '(Holo/Foil)'); + } + for (const t of this.csgoEnglish['inverted'][marketHashName] || []) { const tag = `#${t.toLowerCase()}`; const items = this.itemsGame.items; @@ -827,7 +840,7 @@ class CSGOCdn extends EventEmitter { const url = this.getPathURL(path); if (url) { - return url; + return url.replace('\r', ''); } } } From c896441064d7f1fbd44da817364dd241969e5f58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=C4=9Fuz=20=C3=96zcan?= Date: Thu, 20 Feb 2020 17:25:21 +0300 Subject: [PATCH 2/2] Update index.js --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 457f7a5..0d256c9 100644 --- a/index.js +++ b/index.js @@ -432,7 +432,9 @@ 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).replace('\r', '');