Update server.js
Browse files
server.js
CHANGED
@@ -157,8 +157,10 @@ app.post('/api/proxy/rebuild/:repoId(*)', async (req, res) => {
|
|
157 |
}
|
158 |
|
159 |
const headers = { 'Authorization': `Bearer ${space.token}`, 'Content-Type': 'application/json' };
|
160 |
-
const
|
161 |
-
console.log(
|
|
|
|
|
162 |
res.json({ success: true, message: `Space ${repoId} 重建成功` });
|
163 |
} catch (error) {
|
164 |
console.error(`重建 space 失败 (${req.params.repoId}):`, error.message);
|
@@ -257,11 +259,19 @@ app.post('/api/v1/action/:token/:spaceId(*)/rebuild', async (req, res) => {
|
|
257 |
}
|
258 |
|
259 |
const headers = { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' };
|
260 |
-
|
|
|
|
|
|
|
261 |
res.json({ success: true, message: `Space ${spaceId} 重建成功` });
|
262 |
} catch (error) {
|
263 |
console.error(`重建 space 失败 (外部 API):`, error.message);
|
264 |
-
|
|
|
|
|
|
|
|
|
|
|
265 |
}
|
266 |
});
|
267 |
|
|
|
157 |
}
|
158 |
|
159 |
const headers = { 'Authorization': `Bearer ${space.token}`, 'Content-Type': 'application/json' };
|
160 |
+
const payload = { factoryReboot: true };
|
161 |
+
console.log(`发送重建请求,payload: ${JSON.stringify(payload)}`);
|
162 |
+
const response = await axios.post(`https://huggingface.co/api/spaces/${repoId}/restart`, payload, { headers });
|
163 |
+
console.log(`重建 Space ${repoId} 成功,状态码: ${response.status}, 响应数据:`, response.data);
|
164 |
res.json({ success: true, message: `Space ${repoId} 重建成功` });
|
165 |
} catch (error) {
|
166 |
console.error(`重建 space 失败 (${req.params.repoId}):`, error.message);
|
|
|
259 |
}
|
260 |
|
261 |
const headers = { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' };
|
262 |
+
const payload = { factoryReboot: true };
|
263 |
+
console.log(`外部 API 发送重建请求,spaceId: ${spaceId}, payload: ${JSON.stringify(payload)}`);
|
264 |
+
const response = await axios.post(`https://huggingface.co/api/spaces/${spaceId}/restart`, payload, { headers });
|
265 |
+
console.log(`外部 API 重建 Space ${spaceId} 成功,状态码: ${response.status}, 响应数据:`, response.data);
|
266 |
res.json({ success: true, message: `Space ${spaceId} 重建成功` });
|
267 |
} catch (error) {
|
268 |
console.error(`重建 space 失败 (外部 API):`, error.message);
|
269 |
+
if (error.response) {
|
270 |
+
console.error(`状态码: ${error.response.status}, 响应数据:`, error.response.data);
|
271 |
+
res.status(error.response.status || 500).json({ success: false, error: error.response.data?.message || error.message });
|
272 |
+
} else {
|
273 |
+
res.status(500).json({ success: false, error: error.message });
|
274 |
+
}
|
275 |
}
|
276 |
});
|
277 |
|