make BOT/SHARED runtime paths env-configurable for containerized deploys
This commit is contained in:
@@ -165,13 +165,13 @@ const log = {
|
|||||||
debug: (...args) => isDev && console.log('[DEBUG]', ...args)
|
debug: (...args) => isDev && console.log('[DEBUG]', ...args)
|
||||||
};
|
};
|
||||||
|
|
||||||
const REPO_ROOT = path.join(__dirname, '..');
|
const REPO_ROOT = process.env.BOT_REPO_ROOT || path.join(__dirname, '..');
|
||||||
const SQUADRON_RECAP_CACHE_DIR = path.join(STORAGE_ROOT, 'RECAPS', 'squadrons');
|
const SQUADRON_RECAP_CACHE_DIR = path.join(STORAGE_ROOT, 'RECAPS', 'squadrons');
|
||||||
const PLAYER_RECAP_CACHE_DIR = path.join(STORAGE_ROOT, 'RECAPS', 'players');
|
const PLAYER_RECAP_CACHE_DIR = path.join(STORAGE_ROOT, 'RECAPS', 'players');
|
||||||
const RECAP_TTL_MS = 24 * 60 * 60 * 1000; // in-progress season TTL
|
const RECAP_TTL_MS = 24 * 60 * 60 * 1000; // in-progress season TTL
|
||||||
const RECAP_RENDER_TIMEOUT_MS = 30_000;
|
const RECAP_RENDER_TIMEOUT_MS = 30_000;
|
||||||
const PYTHON_BIN = path.join(REPO_ROOT, '..', 'SHARED', '.venv', 'bin', 'python');
|
const PYTHON_BIN = process.env.PYTHON_BIN || path.join(REPO_ROOT, '..', 'SHARED', '.venv', 'bin', 'python');
|
||||||
const RECAP_SCRIPT = path.join(REPO_ROOT, 'BOT', 'render_recap.py');
|
const RECAP_SCRIPT = process.env.RECAP_SCRIPT || path.join(REPO_ROOT, 'BOT', 'render_recap.py');
|
||||||
|
|
||||||
function resolveReplaySessionDir(sessionId) {
|
function resolveReplaySessionDir(sessionId) {
|
||||||
const sid = String(sessionId).toLowerCase();
|
const sid = String(sessionId).toLowerCase();
|
||||||
@@ -1927,10 +1927,10 @@ app.get('/api/match/:sessionId/video', async (req, res) => {
|
|||||||
_videoRenderCount++;
|
_videoRenderCount++;
|
||||||
try {
|
try {
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
const pythonBin = path.join(__dirname, '..', '..', 'SHARED', '.venv', 'bin', 'python');
|
const pythonBin = PYTHON_BIN;
|
||||||
execFile(pythonBin, ['-m', 'BOT.render_replay', replayPath, videoPath], {
|
execFile(pythonBin, ['-m', 'BOT.render_replay', replayPath, videoPath], {
|
||||||
timeout: 120000,
|
timeout: 120000,
|
||||||
cwd: path.join(__dirname, '..')
|
cwd: REPO_ROOT
|
||||||
}, (error, stdout, stderr) => {
|
}, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
log.error('[Video] Generation stderr:', stderr);
|
log.error('[Video] Generation stderr:', stderr);
|
||||||
@@ -1990,10 +1990,10 @@ app.get('/api/match/:sessionId/replay-canvas', async (req, res) => {
|
|||||||
_canvasRenderCount++;
|
_canvasRenderCount++;
|
||||||
try {
|
try {
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
const pythonBin = path.join(__dirname, '..', '..', 'SHARED', '.venv', 'bin', 'python');
|
const pythonBin = PYTHON_BIN;
|
||||||
execFile(pythonBin, ['-m', 'BOT.render_replay', replayPath, jsonPath], {
|
execFile(pythonBin, ['-m', 'BOT.render_replay', replayPath, jsonPath], {
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
cwd: path.join(__dirname, '..')
|
cwd: REPO_ROOT
|
||||||
}, (error, stdout, stderr) => {
|
}, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
log.error('[ReplayCanvas] Generation stderr:', stderr);
|
log.error('[ReplayCanvas] Generation stderr:', stderr);
|
||||||
@@ -2026,7 +2026,7 @@ app.get('/api/icons/type/:name', (req, res) => {
|
|||||||
if (!name || !/^[a-zA-Z0-9_\-]+$/.test(name)) {
|
if (!name || !/^[a-zA-Z0-9_\-]+$/.test(name)) {
|
||||||
return res.status(400).json({ error: 'Invalid icon name' });
|
return res.status(400).json({ error: 'Invalid icon name' });
|
||||||
}
|
}
|
||||||
const iconsBase = path.join(__dirname, '..', '..', 'SHARED', 'ICONS');
|
const iconsBase = process.env.SHARED_ICONS_DIR || path.join(REPO_ROOT, '..', 'SHARED', 'ICONS');
|
||||||
// Check: ICONS/ → FALLBACKS/ → MINIS/
|
// Check: ICONS/ → FALLBACKS/ → MINIS/
|
||||||
const candidates = [
|
const candidates = [
|
||||||
path.join(iconsBase, name + '.png'),
|
path.join(iconsBase, name + '.png'),
|
||||||
@@ -2053,7 +2053,7 @@ app.get('/api/match/minimap/:level', (req, res) => {
|
|||||||
if (!level || !/^[a-zA-Z0-9_]+$/.test(level)) {
|
if (!level || !/^[a-zA-Z0-9_]+$/.test(level)) {
|
||||||
return res.status(400).json({ error: 'Invalid level name' });
|
return res.status(400).json({ error: 'Invalid level name' });
|
||||||
}
|
}
|
||||||
const minimapsDir = path.join(__dirname, '..', '..', 'SHARED', 'MAPS', 'MINIMAPS');
|
const minimapsDir = process.env.SHARED_MINIMAPS_DIR || path.join(REPO_ROOT, '..', 'SHARED', 'MAPS', 'MINIMAPS');
|
||||||
const names = req.query.type === 'full'
|
const names = req.query.type === 'full'
|
||||||
? [level + '.png', level + '_map.png']
|
? [level + '.png', level + '_map.png']
|
||||||
: [level + '_tankmap.png', level + '.png', level + '_map.png'];
|
: [level + '_tankmap.png', level + '.png', level + '_map.png'];
|
||||||
|
|||||||
Reference in New Issue
Block a user