package api import ( "context" "net/http" "tera-clone/services/tera-api/internal/startup" "time" ) func (r *Router) handleStartupStatus(w http.ResponseWriter, req *http.Request) { w.Header().Set("Cache-Control", "no-store") state := startup.Status{State: "ready", Ready: true} if r.startupStatus != nil { state = r.startupStatus() } else if r.commandsReady != nil && !r.commandsReady() { state.Ready = false state.State = "starting" } if r.clockBootstrap != nil { state.ClockSyncToken = r.clockBootstrap.Token() } writeJSON(w, http.StatusOK, state) } func (r *Router) handleBootstrapTime(w http.ResponseWriter, req *http.Request) { w.Header().Set("Cache-Control", "no-store") if r.clockBootstrap == nil { writeError(w, http.StatusConflict, "clock_sync_unavailable", "clock initialization is unavailable") return } var input struct { Token string `json:"token"` BrowserTime time.Time `json:"browser_time"` } if !decodeJSON(w, req, &input) { return } ctx, cancel := context.WithTimeout(req.Context(), 5*time.Second) defer cancel() if err := r.clockBootstrap.Sync(ctx, input.Token, input.BrowserTime); err != nil { writeError(w, http.StatusConflict, "clock_sync_pending", "PC time synchronization did not complete; retry or check device time") return } writeJSON(w, http.StatusOK, map[string]bool{"synced": true}) }