Load plugin from local file first (not remote)

This commit is contained in:
2026-03-21 19:32:13 -04:00
parent 70064f487e
commit e84c794962

View File

@@ -14,31 +14,31 @@ const db = drizzle(connection, { schema });
import * as fs from "fs"; import * as fs from "fs";
import * as path from "path"; import * as path from "path";
// Function to load plugin definition (Remote -> Local Fallback) // Function to load plugin definition (Local first -> Remote fallback)
async function loadNaoPluginDef() { async function loadNaoPluginDef() {
const REMOTE_URL = "https://repo.hristudio.com/plugins/nao6-ros2.json";
const LOCAL_PATH = path.join( const LOCAL_PATH = path.join(
__dirname, __dirname,
"../robot-plugins/plugins/nao6-ros2.json", "../robot-plugins/plugins/nao6-ros2.json",
); );
const REMOTE_URL = "https://repo.hristudio.com/plugins/nao6-ros2.json";
// Always load from local file first (has latest fixes)
try { try {
console.log( console.log(`📁 Loading plugin definition from local file...`);
`🌐 Attempting to fetch plugin definition from ${REMOTE_URL}...`, const rawPlugin = fs.readFileSync(LOCAL_PATH, "utf-8");
console.log("✅ Successfully loaded local plugin definition.");
return JSON.parse(rawPlugin);
} catch (err) {
console.warn(
`⚠️ Local file load failed. Falling back to remote: ${REMOTE_URL}`,
); );
const response = await fetch(REMOTE_URL, { const response = await fetch(REMOTE_URL, {
signal: AbortSignal.timeout(3000), signal: AbortSignal.timeout(5000),
}); // 3s timeout });
if (!response.ok) throw new Error(`HTTP ${response.status}`); if (!response.ok) throw new Error(`HTTP ${response.status}`);
const data = await response.json(); const data = await response.json();
console.log("✅ Successfully fetched plugin definition from remote."); console.log("✅ Successfully fetched plugin definition from remote.");
return data; return data;
} catch (err) {
console.warn(
`⚠️ Remote fetch failed (${err instanceof Error ? err.message : String(err)}). Falling back to local file.`,
);
const rawPlugin = fs.readFileSync(LOCAL_PATH, "utf-8");
return JSON.parse(rawPlugin);
} }
} }