1
0
mirror of https://github.com/lexogrine/dota2-react-hud.git synced 2025-12-10 01:52:49 +01:00

fixed hero icons and added signature file

This commit is contained in:
Hubert Walczak 2023-06-27 17:04:39 +02:00
parent 45c8fd0310
commit 8766d43d3e
2 changed files with 76 additions and 1 deletions

75
sign.js Normal file
View File

@ -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();

View File

@ -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(