mirror of https://github.com/cloudreve/Cloudreve
consolidate supported thumbnail extensions into site config; remove dedicated API
parent
3d98f78caa
commit
c663c12afb
|
@ -19,6 +19,10 @@ import (
|
||||||
|
|
||||||
const thumbTempFolder = "thumb"
|
const thumbTempFolder = "thumb"
|
||||||
|
|
||||||
|
// BuiltinSupportedExts lists file extensions supported by the built-in
|
||||||
|
// thumbnail generator. Extensions are lowercased and do not include the dot.
|
||||||
|
var BuiltinSupportedExts = []string{"jpg", "jpeg", "png", "gif"}
|
||||||
|
|
||||||
// Thumb 缩略图
|
// Thumb 缩略图
|
||||||
type Thumb struct {
|
type Thumb struct {
|
||||||
src image.Image
|
src image.Image
|
||||||
|
|
|
@ -436,17 +436,3 @@ func ResetThumb(c *gin.Context) {
|
||||||
c.JSON(200, serializer.Response{Data: resp})
|
c.JSON(200, serializer.Response{Data: resp})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ThumbExts gets supported thumbnail extensions
|
|
||||||
func ThumbExts(c *gin.Context) {
|
|
||||||
service := ParametersFromContext[*explorer.ThumbExtsService](c, explorer.ThumbExtsParamCtx{})
|
|
||||||
resp, err := service.Get(c)
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(200, serializer.Err(c, err))
|
|
||||||
c.Abort()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(200, serializer.Response{
|
|
||||||
Data: resp,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
|
@ -614,22 +614,17 @@ func initMasterRouter(dep dependency.Dep) *gin.Engine {
|
||||||
controllers.ServeEntity,
|
controllers.ServeEntity,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// 获取缩略图
|
// get thumb
|
||||||
file.GET("thumb",
|
file.GET("thumb",
|
||||||
middleware.ContextHint(),
|
middleware.ContextHint(),
|
||||||
controllers.FromQuery[explorer.FileThumbService](explorer.FileThumbParameterCtx{}),
|
controllers.FromQuery[explorer.FileThumbService](explorer.FileThumbParameterCtx{}),
|
||||||
controllers.Thumb,
|
controllers.Thumb,
|
||||||
)
|
)
|
||||||
// 重置缩略图
|
// reset thumb
|
||||||
file.POST("thumb/reset",
|
file.POST("thumb/reset",
|
||||||
controllers.FromJSON[explorer.ResetThumbService](explorer.ResetThumbParamCtx{}),
|
controllers.FromJSON[explorer.ResetThumbService](explorer.ResetThumbParamCtx{}),
|
||||||
middleware.ValidateBatchFileCount(dep, explorer.ResetThumbParamCtx{}),
|
middleware.ValidateBatchFileCount(dep, explorer.ResetThumbParamCtx{}),
|
||||||
controllers.ResetThumb,
|
controllers.ResetThumb,
|
||||||
)
|
|
||||||
// 获取支持的缩略图扩展名
|
|
||||||
file.GET("thumb/exts",
|
|
||||||
controllers.FromQuery[explorer.ThumbExtsService](explorer.ThumbExtsParamCtx{}),
|
|
||||||
controllers.ThumbExts,
|
|
||||||
)
|
)
|
||||||
// Delete files
|
// Delete files
|
||||||
file.DELETE("",
|
file.DELETE("",
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
package basic
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cloudreve/Cloudreve/v4/application/dependency"
|
"sort"
|
||||||
"github.com/cloudreve/Cloudreve/v4/inventory"
|
"strings"
|
||||||
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
|
||||||
"github.com/cloudreve/Cloudreve/v4/pkg/setting"
|
"github.com/cloudreve/Cloudreve/v4/application/dependency"
|
||||||
"github.com/cloudreve/Cloudreve/v4/service/user"
|
"github.com/cloudreve/Cloudreve/v4/inventory"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
||||||
"github.com/mojocn/base64Captcha"
|
"github.com/cloudreve/Cloudreve/v4/pkg/setting"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/pkg/thumb"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/service/user"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/mojocn/base64Captcha"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SiteConfig 站点全局设置序列
|
// SiteConfig 站点全局设置序列
|
||||||
|
@ -47,7 +51,10 @@ type SiteConfig struct {
|
||||||
MaxBatchSize int `json:"max_batch_size,omitempty"`
|
MaxBatchSize int `json:"max_batch_size,omitempty"`
|
||||||
ThumbnailWidth int `json:"thumbnail_width,omitempty"`
|
ThumbnailWidth int `json:"thumbnail_width,omitempty"`
|
||||||
ThumbnailHeight int `json:"thumbnail_height,omitempty"`
|
ThumbnailHeight int `json:"thumbnail_height,omitempty"`
|
||||||
CustomProps []types.CustomProps `json:"custom_props,omitempty"`
|
CustomProps []types.CustomProps `json:"custom_props,omitempty"`
|
||||||
|
|
||||||
|
// Thumbnail section
|
||||||
|
ThumbExts []string `json:"thumb_exts,omitempty"`
|
||||||
|
|
||||||
// App settings
|
// App settings
|
||||||
AppPromotion bool `json:"app_promotion,omitempty"`
|
AppPromotion bool `json:"app_promotion,omitempty"`
|
||||||
|
@ -71,10 +78,10 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *GetSettingService) GetSiteConfig(c *gin.Context) (*SiteConfig, error) {
|
func (s *GetSettingService) GetSiteConfig(c *gin.Context) (*SiteConfig, error) {
|
||||||
dep := dependency.FromContext(c)
|
dep := dependency.FromContext(c)
|
||||||
settings := dep.SettingProvider()
|
settings := dep.SettingProvider()
|
||||||
|
|
||||||
switch s.Section {
|
switch s.Section {
|
||||||
case "login":
|
case "login":
|
||||||
legalDocs := settings.LegalDocuments(c)
|
legalDocs := settings.LegalDocuments(c)
|
||||||
return &SiteConfig{
|
return &SiteConfig{
|
||||||
|
@ -115,12 +122,53 @@ func (s *GetSettingService) GetSiteConfig(c *gin.Context) (*SiteConfig, error) {
|
||||||
}, nil
|
}, nil
|
||||||
case "app":
|
case "app":
|
||||||
appSetting := settings.AppSetting(c)
|
appSetting := settings.AppSetting(c)
|
||||||
return &SiteConfig{
|
return &SiteConfig{
|
||||||
AppPromotion: appSetting.Promotion,
|
AppPromotion: appSetting.Promotion,
|
||||||
}, nil
|
}, nil
|
||||||
default:
|
case "thumb":
|
||||||
break
|
// Return supported thumbnail extensions from enabled generators.
|
||||||
}
|
exts := map[string]bool{}
|
||||||
|
if settings.BuiltinThumbGeneratorEnabled(c) {
|
||||||
|
for _, e := range thumb.BuiltinSupportedExts {
|
||||||
|
exts[e] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if settings.FFMpegThumbGeneratorEnabled(c) {
|
||||||
|
for _, e := range settings.FFMpegThumbExts(c) {
|
||||||
|
exts[strings.ToLower(e)] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if settings.VipsThumbGeneratorEnabled(c) {
|
||||||
|
for _, e := range settings.VipsThumbExts(c) {
|
||||||
|
exts[strings.ToLower(e)] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if settings.LibreOfficeThumbGeneratorEnabled(c) {
|
||||||
|
for _, e := range settings.LibreOfficeThumbExts(c) {
|
||||||
|
exts[strings.ToLower(e)] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if settings.MusicCoverThumbGeneratorEnabled(c) {
|
||||||
|
for _, e := range settings.MusicCoverThumbExts(c) {
|
||||||
|
exts[strings.ToLower(e)] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if settings.LibRawThumbGeneratorEnabled(c) {
|
||||||
|
for _, e := range settings.LibRawThumbExts(c) {
|
||||||
|
exts[strings.ToLower(e)] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// map -> sorted slice
|
||||||
|
result := make([]string, 0, len(exts))
|
||||||
|
for e := range exts {
|
||||||
|
result = append(result, e)
|
||||||
|
}
|
||||||
|
sort.Strings(result)
|
||||||
|
return &SiteConfig{ThumbExts: result}, nil
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
u := inventory.UserFromContext(c)
|
u := inventory.UserFromContext(c)
|
||||||
siteBasic := settings.SiteBasic(c)
|
siteBasic := settings.SiteBasic(c)
|
||||||
|
|
|
@ -4,8 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/cloudreve/Cloudreve/v4/application/dependency"
|
"github.com/cloudreve/Cloudreve/v4/application/dependency"
|
||||||
"github.com/cloudreve/Cloudreve/v4/inventory"
|
"github.com/cloudreve/Cloudreve/v4/inventory"
|
||||||
|
@ -113,76 +111,4 @@ func (s *ResetThumbService) Reset(c context.Context) (*ResetThumbResponse, error
|
||||||
return &ResetThumbResponse{}, nil
|
return &ResetThumbResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type (
|
// (Thumb ext list API removed; use site config section "thumb")
|
||||||
// ThumbExtsParamCtx defines context for ThumbExtsService
|
|
||||||
ThumbExtsParamCtx struct{}
|
|
||||||
|
|
||||||
// ThumbExtsService handles getting supported thumbnail extensions
|
|
||||||
ThumbExtsService struct{}
|
|
||||||
|
|
||||||
// ThumbExtsResponse represents the response for supported extensions
|
|
||||||
ThumbExtsResponse struct {
|
|
||||||
Exts []string `json:"exts"`
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get returns all supported thumbnail extensions from enabled generators
|
|
||||||
func (s *ThumbExtsService) Get(c context.Context) (*ThumbExtsResponse, error) {
|
|
||||||
dep := dependency.FromContext(c)
|
|
||||||
settings := dep.SettingProvider()
|
|
||||||
|
|
||||||
extensions := make(map[string]bool)
|
|
||||||
|
|
||||||
// Built-in generator (always supports these if enabled)
|
|
||||||
if settings.BuiltinThumbGeneratorEnabled(c) {
|
|
||||||
for _, ext := range []string{"jpg", "jpeg", "png", "gif"} {
|
|
||||||
extensions[ext] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FFMpeg generator
|
|
||||||
if settings.FFMpegThumbGeneratorEnabled(c) {
|
|
||||||
for _, ext := range settings.FFMpegThumbExts(c) {
|
|
||||||
extensions[strings.ToLower(ext)] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Vips generator
|
|
||||||
if settings.VipsThumbGeneratorEnabled(c) {
|
|
||||||
for _, ext := range settings.VipsThumbExts(c) {
|
|
||||||
extensions[strings.ToLower(ext)] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// LibreOffice generator
|
|
||||||
if settings.LibreOfficeThumbGeneratorEnabled(c) {
|
|
||||||
for _, ext := range settings.LibreOfficeThumbExts(c) {
|
|
||||||
extensions[strings.ToLower(ext)] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Music cover generator
|
|
||||||
if settings.MusicCoverThumbGeneratorEnabled(c) {
|
|
||||||
for _, ext := range settings.MusicCoverThumbExts(c) {
|
|
||||||
extensions[strings.ToLower(ext)] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// LibRaw generator
|
|
||||||
if settings.LibRawThumbGeneratorEnabled(c) {
|
|
||||||
for _, ext := range settings.LibRawThumbExts(c) {
|
|
||||||
extensions[strings.ToLower(ext)] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert map to sorted slice
|
|
||||||
result := make([]string, 0, len(extensions))
|
|
||||||
for ext := range extensions {
|
|
||||||
result = append(result, ext)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort extensions alphabetically using Go's built-in sort
|
|
||||||
sort.Strings(result)
|
|
||||||
|
|
||||||
return &ThumbExtsResponse{Exts: result}, nil
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue