From 457926e8cb36f56c9aaee0ec083301433fca7529 Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Fri, 13 Mar 2026 10:27:34 +0800 Subject: [PATCH] feat(dashboard): set global default file apps (close cloudreve/cloudreve#2304) --- assets | 2 +- inventory/setting.go | 1 + inventory/types/types.go | 2 ++ pkg/setting/provider.go | 11 +++++++++++ service/basic/site.go | 26 ++++++++++++++------------ 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/assets b/assets index 194c0c3f..4672a94e 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 194c0c3f227e9a49a475d3436acf356ed6ac97f7 +Subproject commit 4672a94eefb3def04c6dede3f4193947c7671899 diff --git a/inventory/setting.go b/inventory/setting.go index 0e366a6b..3e2aef1c 100644 --- a/inventory/setting.go +++ b/inventory/setting.go @@ -684,6 +684,7 @@ var DefaultSettings = map[string]string{ "fts_tika_exts": "pdf,doc,docx,xls,xlsx,ppt,pptx,odt,ods,odp,rtf,txt,md,html,htm,epub,csv", "fts_tika_max_file_size": "26214400", "fts_chunk_size": "2000", + "viewer_default_apps": "{}", } var RedactedSettings = map[string]struct{}{ diff --git a/inventory/types/types.go b/inventory/types/types.go index 839389ee..3f082681 100644 --- a/inventory/types/types.go +++ b/inventory/types/types.go @@ -330,6 +330,8 @@ type ( Viewers []Viewer `json:"viewers"` } + DefaultViewerMapping map[string]string + NewFileTemplate struct { Ext string `json:"ext"` DisplayName string `json:"display_name"` diff --git a/pkg/setting/provider.go b/pkg/setting/provider.go index d9d1f43e..a95eaa24 100644 --- a/pkg/setting/provider.go +++ b/pkg/setting/provider.go @@ -234,6 +234,8 @@ type ( FTSTikaExtractor(ctx context.Context) *FTSTikaExtractorSetting // FTSChunkSize returns the maximum chunk size in bytes for full-text search indexing. FTSChunkSize(ctx context.Context) int + // DefaultViewerMapping returns the default viewer mapping. + DefaultViewerMapping(ctx context.Context) types.DefaultViewerMapping } UseFirstSiteUrlCtxKey = struct{} ) @@ -325,6 +327,15 @@ func (s *settingProvider) Avatar(ctx context.Context) *Avatar { } } +func (s *settingProvider) DefaultViewerMapping(ctx context.Context) types.DefaultViewerMapping { + raw := s.getString(ctx, "viewer_default_apps", "{}") + var mapping types.DefaultViewerMapping + if err := json.Unmarshal([]byte(raw), &mapping); err != nil { + return types.DefaultViewerMapping{} + } + return mapping +} + func (s *settingProvider) FileViewers(ctx context.Context) []types.ViewerGroup { raw := s.getString(ctx, "file_viewers", "[]") var viewers []types.ViewerGroup diff --git a/service/basic/site.go b/service/basic/site.go index 2e222524..865b1206 100644 --- a/service/basic/site.go +++ b/service/basic/site.go @@ -43,18 +43,19 @@ type SiteConfig struct { PrivacyPolicyUrl string `json:"privacy_policy_url,omitempty"` // Explorer section - Icons string `json:"icons,omitempty"` - EmojiPreset string `json:"emoji_preset,omitempty"` - MapProvider setting.MapProvider `json:"map_provider,omitempty"` - GoogleMapTileType setting.MapGoogleTileType `json:"google_map_tile_type,omitempty"` - MapboxAK string `json:"mapbox_ak,omitempty"` - FileViewers []types.ViewerGroup `json:"file_viewers,omitempty"` - MaxBatchSize int `json:"max_batch_size,omitempty"` - ThumbnailWidth int `json:"thumbnail_width,omitempty"` - ThumbnailHeight int `json:"thumbnail_height,omitempty"` - CustomProps []types.CustomProps `json:"custom_props,omitempty"` - ShowEncryptionStatus bool `json:"show_encryption_status,omitempty"` - FullTextSearch bool `json:"full_text_search,omitempty"` + Icons string `json:"icons,omitempty"` + EmojiPreset string `json:"emoji_preset,omitempty"` + MapProvider setting.MapProvider `json:"map_provider,omitempty"` + GoogleMapTileType setting.MapGoogleTileType `json:"google_map_tile_type,omitempty"` + MapboxAK string `json:"mapbox_ak,omitempty"` + FileViewers []types.ViewerGroup `json:"file_viewers,omitempty"` + DefaultViewerMapping types.DefaultViewerMapping `json:"default_viewer_mapping,omitempty"` + MaxBatchSize int `json:"max_batch_size,omitempty"` + ThumbnailWidth int `json:"thumbnail_width,omitempty"` + ThumbnailHeight int `json:"thumbnail_height,omitempty"` + CustomProps []types.CustomProps `json:"custom_props,omitempty"` + ShowEncryptionStatus bool `json:"show_encryption_status,omitempty"` + FullTextSearch bool `json:"full_text_search,omitempty"` // Thumbnail section ThumbExts []string `json:"thumb_exts,omitempty"` @@ -113,6 +114,7 @@ func (s *GetSettingService) GetSiteConfig(c *gin.Context) (*SiteConfig, error) { return &SiteConfig{ MaxBatchSize: maxBatchSize, FileViewers: fileViewers, + DefaultViewerMapping: settings.DefaultViewerMapping(c), Icons: explorerSettings.Icons, MapProvider: mapSettings.Provider, GoogleMapTileType: mapSettings.GoogleTileType,