From eba7bec0308d86af358433e203b0520d720d65e4 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Thu, 28 Aug 2025 09:47:02 +0200 Subject: [PATCH] fix: fetch task infos from correct node --- index.js | 16 ++++++++++++++++ public/api-client.js | 7 +++++-- public/view-models.js | 3 ++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index eda1bca..53b5e15 100644 --- a/index.js +++ b/index.js @@ -357,6 +357,22 @@ app.get('/api/cluster/members', async (req, res) => { // API endpoint to get task status app.get('/api/tasks/status', async (req, res) => { try { + const { ip } = req.query; + + if (ip) { + try { + const nodeClient = new SporeApiClient(`http://${ip}`); + const taskStatus = await nodeClient.getTaskStatus(); + return res.json(taskStatus); + } catch (innerError) { + console.error('Error fetching task status from specific node:', innerError); + return res.status(500).json({ + error: 'Failed to fetch task status from node', + message: innerError.message + }); + } + } + if (!sporeClient) { return res.status(503).json({ error: 'Service unavailable', diff --git a/public/api-client.js b/public/api-client.js index 0f64648..67a261c 100644 --- a/public/api-client.js +++ b/public/api-client.js @@ -85,9 +85,12 @@ class ApiClient { } } - async getTasksStatus() { + async getTasksStatus(ip) { try { - const response = await fetch(`${this.baseUrl}/api/tasks/status`, { + const url = ip + ? `${this.baseUrl}/api/tasks/status?ip=${encodeURIComponent(ip)}` + : `${this.baseUrl}/api/tasks/status`; + const response = await fetch(url, { method: 'GET', headers: { 'Accept': 'application/json' diff --git a/public/view-models.js b/public/view-models.js index 089c984..711bdd1 100644 --- a/public/view-models.js +++ b/public/view-models.js @@ -249,7 +249,8 @@ class NodeDetailsViewModel extends ViewModel { // Load tasks data with state preservation async loadTasksData() { try { - const response = await window.apiClient.getTasksStatus(); + const ip = this.get('nodeIp'); + const response = await window.apiClient.getTasksStatus(ip); this.set('tasks', response || []); } catch (error) { console.error('Failed to load tasks:', error);