ai优化,删除未使用代码,提取重复代码。
This commit is contained in:
+10
-17
@@ -237,19 +237,19 @@ func GetThemeFiles(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// resolveThemeFilePath 根据主题名和文件名解析实际文件路径
|
||||
func resolveThemeFilePath(themeName, filename string) string {
|
||||
if filename == themeName+".css" {
|
||||
return filepath.Join("static", "css", filename)
|
||||
}
|
||||
return filepath.Join("templates", themeName, filename)
|
||||
}
|
||||
|
||||
// 获取主题文件内容
|
||||
func GetThemeFile(c *gin.Context) {
|
||||
themeName := c.Param("theme")
|
||||
filename := c.Param("file")
|
||||
|
||||
var filePath string
|
||||
|
||||
// 判断是模板文件还是 CSS 文件
|
||||
if filename == themeName+".css" {
|
||||
filePath = filepath.Join("static", "css", filename)
|
||||
} else {
|
||||
filePath = filepath.Join("templates", themeName, filename)
|
||||
}
|
||||
filePath := resolveThemeFilePath(themeName, filename)
|
||||
|
||||
if _, err := os.Stat(filePath); os.IsNotExist(err) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
@@ -288,14 +288,7 @@ func SaveThemeFile(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var filePath string
|
||||
|
||||
// 判断是模板文件还是 CSS 文件
|
||||
if filename == themeName+".css" {
|
||||
filePath = filepath.Join("static", "css", filename)
|
||||
} else {
|
||||
filePath = filepath.Join("templates", themeName, filename)
|
||||
}
|
||||
filePath := resolveThemeFilePath(themeName, filename)
|
||||
|
||||
// 保存文件
|
||||
if err := os.WriteFile(filePath, []byte(req.Content), 0600); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user