Просмотр исходного кода

fix(channels): fall back to the last known scans when the 24h window is empty (#1243)

SCAN_INTERVAL=0 fleets: the 24h window dies after the last manual scan; now falls back to the last known scans within 30 days. #1214
Nacho 2 месяцев назад
Родитель
Сommit
be2828b426
2 измененных файлов с 25 добавлено и 1 удалено
  1. 12 1
      app/src/pages/ChannelPlan.tsx
  2. 13 0
      server-go/internal/httpapi/wifi_channelplan.go

+ 12 - 1
app/src/pages/ChannelPlan.tsx

@@ -529,7 +529,18 @@ export default function ChannelPlan() {
           <span className="text-caption text-text-muted">
             {lastScanAt > 0
               ? t('channelPlan.lastScan', {
-                  time: new Date(lastScanAt * 1000).toLocaleTimeString(i18n.language, { hour: '2-digit', minute: '2-digit' }),
+                  // #1214: con flotas SCAN_INTERVAL=0 el último scan puede
+                  // ser de hace días (fallback a 30 días): mostrar la fecha
+                  // si no es de hoy, no solo la hora.
+                  time: (() => {
+                    const d = new Date(lastScanAt * 1000)
+                    const today = new Date()
+                    const sameDay = d.toDateString() === today.toDateString()
+                    return sameDay
+                      ? d.toLocaleTimeString(i18n.language, { hour: '2-digit', minute: '2-digit' })
+                      : d.toLocaleDateString(i18n.language, { day: '2-digit', month: '2-digit' }) + ' ' +
+                        d.toLocaleTimeString(i18n.language, { hour: '2-digit', minute: '2-digit' })
+                  })(),
                 })
               : lastRefresh > 0 &&
                 t('channelPlan.lastRefresh', {

+ 13 - 0
server-go/internal/httpapi/wifi_channelplan.go

@@ -104,6 +104,19 @@ func (s *server) registerChannelPlanRoutes(mux *http.ServeMux) {
 			writeError(w, http.StatusInternalServerError, "channel_plan_error")
 			return
 		}
+		// #1214: flotas con NETPULSE_SCAN_INTERVAL=0 no escanean nunca por
+		// intervalo - con la ventana fija de 24h la vista moría en cuanto el
+		// último scan cumplía un día (solo quedaba el bloque propio
+		// sintético y un espectro vacío). Misma filosofía que #1080 con los
+		// radios: mejor el último dato conocido, aunque sea antiguo, que
+		// fingir que no hay nada; el "Escanear ahora" lo renueva al momento.
+		if len(scans) == 0 {
+			scans, err = s.channelPlan.RecentScans(slug, 30*24*time.Hour)
+			if err != nil {
+				writeError(w, http.StatusInternalServerError, "channel_plan_error")
+				return
+			}
+		}
 
 		writeJSON(w, http.StatusOK, map[string]any{
 			"routerId": routerID,