ds2api / internal /httpapi /admin /settings /handler_settings_read.go
204848
feat: 添加平台配置支持,包括Android和Web版本及API级别的自定义设置
0c46526
Raw
History Blame Contribute Delete
3.05 kB
package settings
import (
"net/http"
"strings"
authn "ds2api/internal/auth"
"ds2api/internal/config"
"ds2api/internal/promptcompat"
)
func (h *Handler) getSettings(w http.ResponseWriter, _ *http.Request) {
snap := h.Store.Snapshot()
recommended := defaultRuntimeRecommended(len(snap.Accounts), h.Store.RuntimeAccountMaxInflight())
needsSync := config.IsVercel() && snap.VercelSyncHash != "" && snap.VercelSyncHash != h.computeSyncHash()
writeJSON(w, http.StatusOK, map[string]any{
"success": true,
"config_snapshot": map[string]any{
"admin": map[string]any{
"jwt_expire_hours": snap.Admin.JWTExpireHours,
},
"runtime": map[string]any{
"account_max_inflight": snap.Runtime.AccountMaxInflight,
"account_max_queue": snap.Runtime.AccountMaxQueue,
"global_max_inflight": snap.Runtime.GlobalMaxInflight,
"token_refresh_interval_hours": snap.Runtime.TokenRefreshIntervalHours,
"backup_release_count": snap.Runtime.BackupReleaseCount,
},
"responses": snap.Responses,
"embeddings": snap.Embeddings,
"auto_delete": snap.AutoDelete,
"current_input_file": map[string]any{
"enabled": snap.CurrentInputFile.Enabled,
"min_chars": snap.CurrentInputFile.MinChars,
},
"thinking_injection": map[string]any{
"enabled": snap.ThinkingInjection.Enabled,
"prompt": snap.ThinkingInjection.Prompt,
},
"model_aliases": snap.ModelAliases,
"platform": snap.Platform,
},
"admin": map[string]any{
"has_password_hash": strings.TrimSpace(snap.Admin.PasswordHash) != "",
"jwt_expire_hours": h.Store.AdminJWTExpireHours(),
"jwt_valid_after_unix": snap.Admin.JWTValidAfterUnix,
"default_password_warning": authn.UsingDefaultAdminKey(h.Store),
},
"runtime": map[string]any{
"account_max_inflight": h.Store.RuntimeAccountMaxInflight(),
"account_max_queue": h.Store.RuntimeAccountMaxQueue(recommended),
"global_max_inflight": h.Store.RuntimeGlobalMaxInflight(recommended),
"token_refresh_interval_hours": h.Store.RuntimeTokenRefreshIntervalHours(),
"backup_release_count": h.Store.RuntimeBackupReleaseCount(),
},
"responses": snap.Responses,
"embeddings": snap.Embeddings,
"auto_delete": snap.AutoDelete,
"current_input_file": map[string]any{
"enabled": h.Store.CurrentInputFileEnabled(),
"min_chars": h.Store.CurrentInputFileMinChars(),
},
"thinking_injection": map[string]any{
"enabled": h.Store.ThinkingInjectionEnabled(),
"prompt": h.Store.ThinkingInjectionPrompt(),
"default_prompt": promptcompat.DefaultThinkingInjectionPrompt,
},
"model_aliases": snap.ModelAliases,
"platform": map[string]any{
"mode": h.Store.PlatformMode(),
"android_version": snap.Platform.AndroidVersion,
"web_version": snap.Platform.WebVersion,
"android_api_level": snap.Platform.AndroidAPILevel,
},
"env_backed": h.Store.IsEnvBacked(),
"needs_vercel_sync": needsSync,
})
}