mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-05 08:02:53 +00:00
保留 reasoning 配置,新增免费模型可用性探测 / 手动恢复、首 SSE 事件超时,元数据改用官方地址。按维护者要求,最终文件树排除测试文件。 验证:本地 Go 回归、go vet / build、Prettier、JS / shell 语法及独立实例管理端验收通过。
27 lines
725 B
Go
27 lines
725 B
Go
package admin
|
|
|
|
import (
|
|
"net/http"
|
|
"opencode2api/internal/httpx"
|
|
)
|
|
|
|
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()})
|
|
}
|
|
|
|
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)
|
|
}
|