mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-30 22:26:38 +08:00
7d71f1e4e1
- New internal/repository/logstore abstraction: exported domain interfaces (AccessLogStore/ObservabilityStore/UserAccessLogStore/StatusStore), config-driven provider (Active/Build/Migrating/SetConfigReader), GORM implementation for PostgreSQL/SQLite (incl. hourly rollups computed in real time, migration listers, PG partition maintenance), and a ClickHouse wrapper preserving the native batch path; repository facade delegates to logstore; import-lint test enforces apps never import analyticsrepo. - ClickHouse is now optional: the log DB is either the main DB (postgres when database.enabled, else sqlite) or clickhouse; boot validation + first-run seed; log_database / log_db_migration are protected keys. - New user task 切换日志数据库 (of_log_db_switch): freeze log writes, drain batch writers, copy all 6 raw log tables by id (preserving IDs) with target-partition pre-creation for PG, flip log_database on success, clear the freeze flag on failure. - Per-store retention (log_retention_days_*) with expiry cleanup folded into the daily system_cleanup task; legacy database_auto_cleanup_* and of_database_auto_cleanup decommissioned. - goose migrations: 6 log tables in PG (2 monthly-partitioned) + SQLite, retention config seeds, schedule cleanup; GET /api/v1/admin/status/log-database endpoint; frontend retention settings, switch-task UI and status badge; changelog and docs updated. docs(plan): log database decoupling implementation plan docs(design): log database decoupling design (ClickHouse optional)
147 lines
5.1 KiB
Go
147 lines
5.1 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package option
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/Rain-kl/Wavelet/internal/apps/openflare/apiutil"
|
|
"github.com/Rain-kl/Wavelet/internal/model"
|
|
"github.com/Rain-kl/Wavelet/internal/shared/response"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// GetStatusHandler 获取公开运行状态。
|
|
// @Summary 获取 OpenFlare 公开状态
|
|
// @Description 返回版本、认证源与系统公开配置,无需登录
|
|
// @Tags openflare-option
|
|
// @Produce json
|
|
// @Success 200 {object} response.Any{data=option.statusView} "公开状态"
|
|
// @Failure 400 {object} response.Any "参数错误"
|
|
// @Failure 500 {object} response.Any "内部错误"
|
|
// @Router /api/v1/d/status [get]
|
|
func GetStatusHandler(c *gin.Context) {
|
|
view, err := getStatus(c.Request.Context(), "/api/v1/d")
|
|
if apiutil.AbortBadRequestOnError(c, err) {
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, response.OK(view))
|
|
}
|
|
|
|
// ListOptionsHandler 列出全部配置项。
|
|
// @Summary 列出 OpenFlare 配置项
|
|
// @Description 返回全部非敏感 OpenFlare 配置项,需要管理员权限
|
|
// @Tags openflare-option
|
|
// @Produce json
|
|
// @Security SessionCookie
|
|
// @Success 200 {object} response.Any{data=[]model.OpenFlareOption} "配置项列表"
|
|
// @Failure 400 {object} response.Any "参数错误"
|
|
// @Failure 401 {object} response.Any "未登录"
|
|
// @Failure 404 {object} response.Any "无权限或不存在"
|
|
// @Failure 500 {object} response.Any "内部错误"
|
|
// @Router /api/v1/d/option [get]
|
|
func ListOptionsHandler(c *gin.Context) {
|
|
options, err := listOptions(c.Request.Context())
|
|
if apiutil.AbortBadRequestOnError(c, err) {
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, response.OK(options))
|
|
}
|
|
|
|
// UpdateOptionHandler 更新单个配置项。
|
|
// @Summary 更新 OpenFlare 配置项
|
|
// @Description 更新单个 OpenFlare 配置项,需要管理员权限
|
|
// @Tags openflare-option
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security SessionCookie
|
|
// @Param request body model.OpenFlareOption true "配置项"
|
|
// @Success 200 {object} response.Any "更新成功"
|
|
// @Failure 400 {object} response.Any "参数错误"
|
|
// @Failure 401 {object} response.Any "未登录"
|
|
// @Failure 404 {object} response.Any "无权限或不存在"
|
|
// @Failure 500 {object} response.Any "内部错误"
|
|
// @Router /api/v1/d/option/update [post]
|
|
func UpdateOptionHandler(c *gin.Context) {
|
|
var option model.OpenFlareOption
|
|
if !apiutil.BindJSON(c, &option) {
|
|
return
|
|
}
|
|
if apiutil.AbortBadRequestOnError(c, updateOption(c.Request.Context(), option)) {
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, response.OKNil())
|
|
}
|
|
|
|
// UpdateOptionsBatchHandler 批量更新配置项。
|
|
// @Summary 批量更新 OpenFlare 配置项
|
|
// @Description 批量更新多个 OpenFlare 配置项,需要管理员权限
|
|
// @Tags openflare-option
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security SessionCookie
|
|
// @Param request body option.optionBatchPayload true "批量配置项"
|
|
// @Success 200 {object} response.Any "更新成功"
|
|
// @Failure 400 {object} response.Any "参数错误"
|
|
// @Failure 401 {object} response.Any "未登录"
|
|
// @Failure 404 {object} response.Any "无权限或不存在"
|
|
// @Failure 500 {object} response.Any "内部错误"
|
|
// @Router /api/v1/d/option/update-batch [post]
|
|
func UpdateOptionsBatchHandler(c *gin.Context) {
|
|
var payload optionBatchPayload
|
|
if !apiutil.BindJSON(c, &payload) {
|
|
return
|
|
}
|
|
if apiutil.AbortBadRequestOnError(c, updateOptionsBatch(c.Request.Context(), payload)) {
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, response.OKNil())
|
|
}
|
|
|
|
// LookupGeoIPHandler 查询 GeoIP 信息。
|
|
// @Summary GeoIP 地址查询
|
|
// @Description 按提供商与 IP 查询地理位置信息,需要管理员权限
|
|
// @Tags openflare-option
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security SessionCookie
|
|
// @Param request body option.geoIPLookupRequest true "查询参数"
|
|
// @Success 200 {object} response.Any{data=option.geoIPLookupView} "GeoIP 查询结果"
|
|
// @Failure 400 {object} response.Any "参数错误"
|
|
// @Failure 401 {object} response.Any "未登录"
|
|
// @Failure 404 {object} response.Any "无权限或不存在"
|
|
// @Failure 500 {object} response.Any "内部错误"
|
|
// @Router /api/v1/d/option/geoip/lookup [post]
|
|
func LookupGeoIPHandler(c *gin.Context) {
|
|
var request geoIPLookupRequest
|
|
if !apiutil.BindJSON(c, &request) {
|
|
return
|
|
}
|
|
view, err := lookupGeoIP(c.Request.Context(), request.Provider, request.IP)
|
|
if apiutil.AbortBadRequestOnError(c, err) {
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, response.OK(view))
|
|
}
|
|
|
|
// SyncUptimeKumaHandler 同步 Uptime Kuma 监控。
|
|
// @Summary 同步 Uptime Kuma
|
|
// @Description 将 OpenFlare 节点同步到 Uptime Kuma,需要管理员权限
|
|
// @Tags openflare-option
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security SessionCookie
|
|
// @Success 200 {object} response.Any{data=string} "同步成功"
|
|
// @Failure 400 {object} response.Any "参数错误"
|
|
// @Failure 401 {object} response.Any "未登录"
|
|
// @Failure 404 {object} response.Any "无权限或不存在"
|
|
// @Failure 500 {object} response.Any "内部错误"
|
|
// @Router /api/v1/d/uptimekuma/sync [post]
|
|
func SyncUptimeKumaHandler(c *gin.Context) {
|
|
if apiutil.AbortBadRequestOnError(c, syncUptimeKuma(c.Request.Context())) {
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, response.OK("同步成功"))
|
|
}
|