50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
|
|
package controller
|
||
|
|
|
||
|
|
import (
|
||
|
|
"seeyon-filesystem/config"
|
||
|
|
"seeyon-filesystem/utils"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
// StorageController 存储配置控制器
|
||
|
|
type StorageController struct{}
|
||
|
|
|
||
|
|
func NewStorageController() *StorageController {
|
||
|
|
return &StorageController{}
|
||
|
|
}
|
||
|
|
|
||
|
|
// GetCDNConfig 获取CDN配置
|
||
|
|
// GET /api/admin/settings/cdn
|
||
|
|
func (c *StorageController) GetCDNConfig(ctx *gin.Context) {
|
||
|
|
cfg := config.AppConfig.Storage
|
||
|
|
utils.Success(ctx, gin.H{
|
||
|
|
"cdn_host": cfg.CDNHost,
|
||
|
|
"cdn_path_prefix": cfg.CDNPathPrefix,
|
||
|
|
"local_base_path": cfg.LocalBasePath,
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateCDNConfig 更新CDN配置
|
||
|
|
// PUT /api/admin/settings/cdn
|
||
|
|
func (c *StorageController) UpdateCDNConfig(ctx *gin.Context) {
|
||
|
|
var req struct {
|
||
|
|
CDNHost string `json:"cdn_host"`
|
||
|
|
CDNPathPrefix string `json:"cdn_path_prefix"`
|
||
|
|
}
|
||
|
|
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||
|
|
utils.BadRequest(ctx, "参数错误: "+err.Error())
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
// 更新内存配置
|
||
|
|
config.AppConfig.Storage.CDNHost = req.CDNHost
|
||
|
|
config.AppConfig.Storage.CDNPathPrefix = req.CDNPathPrefix
|
||
|
|
|
||
|
|
utils.SuccessWithMessage(ctx, "CDN配置已更新", gin.H{
|
||
|
|
"cdn_host": req.CDNHost,
|
||
|
|
"cdn_path_prefix": req.CDNPathPrefix,
|
||
|
|
"example_url": req.CDNHost + req.CDNPathPrefix + "/2026/07/02/ab/abcdef.txt",
|
||
|
|
})
|
||
|
|
}
|