mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-05 16:04:01 +00:00
- Dark theme: an auto/light/dark cycle in the topbar, persisted per browser and applied before first paint by an inline head script; the dark palette moves behind data-theme so the runtime choice wins over the media query (#122). - Request routing and upstream attempts tables are paged (50/100/200/500 rows per page) instead of a hard last-100 cap, with translated pager controls (#122). - Free-model refresh status now calls POST /api/models/probe, which marks every automatic model due and wakes the probe loop, then reloads the snapshot; the button re-probes instead of only rereading the cache (#122). - The config page renders long key/proxy lists collapsed behind a 100-chip cap with an expand toggle, so a large proxy pool no longer freezes the page (#146). - New strings translated for en/vi/it; READMEs document the new admin endpoint.
64 lines
2.3 KiB
Go
64 lines
2.3 KiB
Go
package admin
|
|
|
|
import (
|
|
"net/http"
|
|
"opencode2api/internal/httpx"
|
|
)
|
|
|
|
// handleAvailability lists the free models with their probe state, so the
|
|
// availability page can show which ones are disabled and why.
|
|
func (a *Server) handleAvailability(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Cache-Control", "no-store")
|
|
httpx.WriteJSON(w, http.StatusOK, map[string]any{"models": a.manager.AvailabilitySnapshot()})
|
|
}
|
|
|
|
// handleProbeModels marks every automatic free model due and wakes the probe
|
|
// loop, so the availability page's refresh triggers a real re-probe instead
|
|
// of only reloading the cached snapshot. It answers with the current
|
|
// availability list; the fresh results land as the sweep records them.
|
|
func (a *Server) handleProbeModels(w http.ResponseWriter, r *http.Request) {
|
|
a.manager.RequestAvailabilitySweep()
|
|
a.handleAvailability(w, r)
|
|
}
|
|
|
|
// handleRestoreModel returns a disabled free model to manual control, which
|
|
// re-enables it and keeps automatic probes from disabling it again. It answers
|
|
// with the refreshed availability list.
|
|
func (a *Server) handleRestoreModel(w http.ResponseWriter, r *http.Request) {
|
|
var input struct {
|
|
Model string `json:"model"`
|
|
}
|
|
if err := decodeAdminJSON(w, r, &input); err != nil {
|
|
writeAdminError(w, 400, "invalid_request", err.Error())
|
|
return
|
|
}
|
|
if err := a.manager.RestoreModel(input.Model); err != nil {
|
|
writeAdminError(w, 400, "restore_failed", a.manager.Redact(err.Error()))
|
|
return
|
|
}
|
|
a.handleAvailability(w, r)
|
|
}
|
|
|
|
// handleManualModel switches a free model between manual and automatic
|
|
// control: a manual model stays enabled and is not probed, while switching
|
|
// back to automatic schedules a probe. It answers with the refreshed list.
|
|
func (a *Server) handleManualModel(w http.ResponseWriter, r *http.Request) {
|
|
var input struct {
|
|
Model string `json:"model"`
|
|
Manual *bool `json:"manual"`
|
|
}
|
|
if err := decodeAdminJSON(w, r, &input); err != nil {
|
|
writeAdminError(w, 400, "invalid_request", err.Error())
|
|
return
|
|
}
|
|
if input.Manual == nil {
|
|
writeAdminError(w, 400, "invalid_request", "manual is required")
|
|
return
|
|
}
|
|
if err := a.manager.SetManualModel(input.Model, *input.Manual); err != nil {
|
|
writeAdminError(w, 400, "manual_failed", a.manager.Redact(err.Error()))
|
|
return
|
|
}
|
|
a.handleAvailability(w, r)
|
|
}
|