From 8766d43d3ee619a086a12ee4091443f25d67a125 Mon Sep 17 00:00:00 2001 From: Hubert Walczak Date: Tue, 27 Jun 2023 17:04:39 +0200 Subject: [PATCH] fixed hero icons and added signature file --- sign.js | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/api/api.ts | 2 +- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 sign.js diff --git a/sign.js b/sign.js new file mode 100644 index 0000000..835e2c9 --- /dev/null +++ b/sign.js @@ -0,0 +1,75 @@ +const path = require('path'); +const fs = require('fs'); +const crypto = require('crypto'); +const jwt = require('jsonwebtoken'); + +const sign = () => { + const getAllFilesToSign = (hudDir) => { + const files = []; + const getFiles = (dir) => { + fs.readdirSync(dir).forEach(file => { + const fileDirectory = path.join(dir, file); + if (fs.statSync(fileDirectory).isDirectory()) return getFiles(fileDirectory); + else if (fileDirectory.endsWith('.js') || fileDirectory.endsWith('.css')) return files.push(fileDirectory); + }) + } + getFiles(hudDir) + return files; + } + + const dir = path.join(__dirname, 'build'); + + const keyFile = path.join(dir, 'key'); + + if (fs.existsSync(keyFile)) { + return true; + } + + const filesToSign = getAllFilesToSign(dir); + const passphrase = crypto.randomBytes(48).toString('hex'); + + filesToSign.push(path.join(dir, 'hud.json')); + + const keys = crypto.generateKeyPairSync('rsa', { + modulusLength: 4096, + publicKeyEncoding: { + type: 'spki', + format: 'pem' + }, + privateKeyEncoding: { + type: 'pkcs8', + format: 'pem', + cipher: 'aes-256-cbc', + passphrase + } + }); + + let success = true; + + const fileToContent = {}; + + filesToSign.forEach(file => { + if (!success) { + return; + } + const content = fs.readFileSync(file, 'utf8'); + try { + const signed = jwt.sign(content, { key: keys.privateKey.toString(), passphrase }, { algorithm: 'RS256' }); + fileToContent[file] = signed; + } catch { + success = false; + } + + }); + + if (!success) return false; + + filesToSign.forEach(file => { + fs.writeFileSync(file, fileToContent[file]); + }); + + fs.writeFileSync(keyFile, keys.publicKey.toString()); + + return success; +} +sign(); \ No newline at end of file diff --git a/src/api/api.ts b/src/api/api.ts index 3f71500..1dcdb16 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -25,7 +25,7 @@ export const getAssetURL = ( return `${apiUrl}static/dota2/heroes/animated/${asset.startsWith("npc_dota_hero_")? asset : `npc_dota_hero_${asset}`}.webm`; } if (assetType === "heroes_icons") { - return `${apiUrl}static/dota2/heroes/icons/${asset}.png`; + return `${apiUrl}static/dota2/heroes/icons/${asset.replace("npc_dota_hero_", "")}.png`; } if (assetType === "items") { return `${apiUrl}static/dota2/${assetType}/${asset.replace(