refactor: restructure codebase for v1 kasm docker release

This commit is contained in:
Kovasky Buezo
2026-07-06 21:19:16 -02:30
parent 8176fce0c7
commit 1c2b963f27
34 changed files with 7589 additions and 8447 deletions
+50
View File
@@ -0,0 +1,50 @@
import crypto from 'crypto';
import sysLogger from '../utils/sysLogger.mjs';
export function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// Insert garbage code
export function insertGarbledText(content) {
const enableGarbledStart = process.env.ENABLE_GARBLED_START === 'true';
const enableGarbledEnd = process.env.ENABLE_GARBLED_END === 'true';
if (!enableGarbledStart && !enableGarbledEnd) {
return content;
}
// Generate random garbage of specified length
function generateGarbledText(length) {
return crypto.randomBytes(length).toString('hex');
}
let garbledContent = content;
// Configuration parameters
const startMinLength = parseInt(process.env.GARBLED_START_MIN_LENGTH) || 1000;
const startMaxLength = parseInt(process.env.GARBLED_START_MAX_LENGTH) || 5000;
const endGarbledLength = parseInt(process.env.GARBLED_END_LENGTH) || 500;
if (enableGarbledStart) {
const startGarbledLength = getRandomInt(startMinLength, startMaxLength);
const byteLength = Math.ceil(startGarbledLength / 2);
// Generate garbage
const startPlaceholder = generateGarbledText(byteLength);
garbledContent = startPlaceholder + '\n\n\n' + garbledContent.trim();
}
if (enableGarbledEnd) {
const byteLength = Math.ceil(endGarbledLength / 2);
const endPlaceholder = generateGarbledText(byteLength);
garbledContent = garbledContent.trim() + '\n\n\n' + endPlaceholder;
}
return garbledContent;
}