From 9a8cff32273ce1492cb65ff099159a0d646847f8 Mon Sep 17 00:00:00 2001 From: Michel Roegl-Brunner Date: Fri, 24 Oct 2025 22:06:34 +0200 Subject: [PATCH] Add missing checkScriptExists method to scriptDownloader.js - Add checkScriptExists method that was missing from JavaScript implementation - This method is required by the checkScriptFiles API endpoint - Method checks if CT script and install script files exist locally - Returns ctExists, installExists, and files array - Fixes issue where UI shows 'Load Script' instead of 'Install' button for downloaded scripts --- src/server/services/scriptDownloader.js | 65 +++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/server/services/scriptDownloader.js b/src/server/services/scriptDownloader.js index 9db3d60..61e33e7 100644 --- a/src/server/services/scriptDownloader.js +++ b/src/server/services/scriptDownloader.js @@ -227,6 +227,71 @@ export class ScriptDownloaderService { // All files exist, script is downloaded return true; } + + async checkScriptExists(script) { + this.initializeConfig(); + const files = []; + let ctExists = false; + let installExists = false; + + try { + // Check scripts based on their install methods + if (script.install_methods?.length) { + for (const method of script.install_methods) { + if (method.script) { + const scriptPath = method.script; + const fileName = scriptPath.split('/').pop(); + + if (fileName) { + let targetDir; + if (scriptPath.startsWith('ct/')) { + targetDir = 'ct'; + } else if (scriptPath.startsWith('tools/')) { + targetDir = 'tools'; + } else if (scriptPath.startsWith('vm/')) { + targetDir = 'vm'; + } else { + targetDir = 'ct'; // Default fallback + } + + const filePath = join(this.scriptsDirectory, targetDir, fileName); + + try { + await access(filePath); + files.push(`${targetDir}/${fileName}`); + + if (scriptPath.startsWith('ct/')) { + ctExists = true; + } + } catch { + // File doesn't exist + } + } + } + } + } + + // Check for install script for CT scripts + const hasCtScript = script.install_methods?.some(method => method.script?.startsWith('ct/')); + if (hasCtScript) { + const installScriptName = `${script.slug}-install.sh`; + const installPath = join(this.scriptsDirectory, 'install', installScriptName); + + try { + await access(installPath); + files.push(`install/${installScriptName}`); + installExists = true; + } catch { + // Install script doesn't exist + } + } + + return { ctExists, installExists, files }; + } catch (error) { + console.error('Error checking script existence:', error); + return { ctExists: false, installExists: false, files: [] }; + } + } } export const scriptDownloaderService = new ScriptDownloaderService();