refactor: extract models/routes and env-based server config
- Move API request/response structs into new lib/models package - Centralize Gin route registration in lib/routing to simplify wiring - Add lib/server config helper to allow WARPBOX_BOX_POLL_INTERVAL_MS override - Improves modularity and makes polling behavior configurable per environmentrefactor: extract models/routes and env-based server config - Move API request/response structs into new lib/models package - Centralize Gin route registration in lib/routing to simplify wiring - Add lib/server config helper to allow WARPBOX_BOX_POLL_INTERVAL_MS override - Improves modularity and makes polling behavior configurable per environment
This commit is contained in:
@@ -48,7 +48,7 @@ async function refreshBoxStatus() {
|
||||
const boxID = boxPanel.dataset.boxId;
|
||||
const response = await fetch(`/box/${boxID}/status`);
|
||||
if (!response.ok) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
@@ -63,10 +63,16 @@ async function refreshBoxStatus() {
|
||||
}
|
||||
|
||||
if (boxPanel) {
|
||||
const pollMS = Number.parseInt(boxPanel.dataset.pollMs, 10) || 5000;
|
||||
const timer = setInterval(async () => {
|
||||
const hasLoadingFiles = await refreshBoxStatus();
|
||||
if (!hasLoadingFiles) {
|
||||
clearInterval(timer);
|
||||
try {
|
||||
const hasLoadingFiles = await refreshBoxStatus();
|
||||
if (!hasLoadingFiles) {
|
||||
clearInterval(timer);
|
||||
}
|
||||
} catch (error) {
|
||||
// Keep polling through temporary network/server hiccups; otherwise
|
||||
// an in-progress file can appear stuck forever after one bad poll.
|
||||
}
|
||||
}, 1500);
|
||||
}, pollMS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user