Skip to content

Commit bcc3d48

Browse files
committed
feat: add regular and thumb picture compress format config
1 parent 43b9fa1 commit bcc3d48

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

config/storage.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package config
22

33
type storageConfigs struct {
4-
OriginalType string `toml:"original_type" mapstructure:"original_type" json:"original_type" yaml:"original_type"`
5-
RegularType string `toml:"regular_type" mapstructure:"regular_type" json:"regular_type" yaml:"regular_type"`
6-
ThumbType string `toml:"thumb_type" mapstructure:"thumb_type" json:"thumb_type" yaml:"thumb_type"`
7-
CacheDir string `toml:"cache_dir" mapstructure:"cache_dir" json:"cache_dir" yaml:"cache_dir"`
8-
CacheTTL uint `toml:"cache_ttl" mapstructure:"cache_ttl" json:"cache_ttl" yaml:"cache_ttl"`
9-
Webdav StorageWebdavConfig `toml:"webdav" mapstructure:"webdav" json:"webdav" yaml:"webdav"`
10-
Local StorageLocalConfig `toml:"local" mapstructure:"local" json:"local" yaml:"local"`
11-
Alist StorageAlistConfig `toml:"alist" mapstructure:"alist" json:"alist" yaml:"alist"`
4+
OriginalType string `toml:"original_type" mapstructure:"original_type" json:"original_type" yaml:"original_type"`
5+
RegularType string `toml:"regular_type" mapstructure:"regular_type" json:"regular_type" yaml:"regular_type"`
6+
RegularFormat string `toml:"regular_format" mapstructure:"regular_format" json:"regular_format" yaml:"regular_format"`
7+
ThumbType string `toml:"thumb_type" mapstructure:"thumb_type" json:"thumb_type" yaml:"thumb_type"`
8+
ThumbFormat string `toml:"thumb_format" mapstructure:"thumb_format" json:"thumb_format" yaml:"thumb_format"`
9+
CacheDir string `toml:"cache_dir" mapstructure:"cache_dir" json:"cache_dir" yaml:"cache_dir"`
10+
CacheTTL uint `toml:"cache_ttl" mapstructure:"cache_ttl" json:"cache_ttl" yaml:"cache_ttl"`
11+
Webdav StorageWebdavConfig `toml:"webdav" mapstructure:"webdav" json:"webdav" yaml:"webdav"`
12+
Local StorageLocalConfig `toml:"local" mapstructure:"local" json:"local" yaml:"local"`
13+
Alist StorageAlistConfig `toml:"alist" mapstructure:"alist" json:"alist" yaml:"alist"`
1214
}
1315

1416
type StorageWebdavConfig struct {

config/viper.go

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ func InitConfig() {
7979
// viper.SetDefault("storage.local.enable", true)
8080
viper.SetDefault("storage.local.path", "./manyacg")
8181
viper.SetDefault("storage.alist.token_expire", 86400)
82+
viper.SetDefault("storage.regular_format", "webp")
83+
viper.SetDefault("storage.thumb_format", "webp")
8284

8385
viper.SetDefault("telegram.sleep", 3)
8486
viper.SetDefault("telegram.api_url", "https://api.telegram.org")

storage/storage.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func SaveAll(ctx context.Context, artwork *types.Artwork, picture *types.Picture
8484
common.Logger.Fatalf("Unknown storage type: %s", config.Cfg.Storage.RegularType)
8585
return nil, fmt.Errorf("%w: %s", errs.ErrStorageUnkown, config.Cfg.Storage.RegularType)
8686
}
87-
regularOutputPath := filePath[:len(filePath)-len(filepath.Ext(filePath))] + "_regular.webp"
87+
regularOutputPath := fmt.Sprintf("%s_regular.%s", filePath[:len(filePath)-len(filepath.Ext(filePath))], config.Cfg.Storage.RegularFormat)
8888
if err := common.CompressImageByFFmpeg(filePath, regularOutputPath, types.RegularPhotoSideLength); err != nil {
8989
return nil, err
9090
}
@@ -95,7 +95,7 @@ func SaveAll(ctx context.Context, artwork *types.Artwork, picture *types.Picture
9595
if picture.ID == "" {
9696
picture.ID = primitive.NewObjectID().Hex()
9797
}
98-
regularStorageFileName := picture.ID + "_regular.webp"
98+
regularStorageFileName := picture.ID + "_regular." + config.Cfg.Storage.RegularFormat
9999
regularStoragePath := fmt.Sprintf("/regular/%s/%s/%s", artwork.SourceType, artwork.Artist.UID, regularStorageFileName)
100100

101101
regularDetail, err = regularStorage.Save(ctx, regularOutputPath, regularStoragePath)
@@ -110,7 +110,8 @@ func SaveAll(ctx context.Context, artwork *types.Artwork, picture *types.Picture
110110
common.Logger.Fatalf("Unknown storage type: %s", config.Cfg.Storage.ThumbType)
111111
return nil, fmt.Errorf("%w: %s", errs.ErrStorageUnkown, config.Cfg.Storage.ThumbType)
112112
}
113-
thumbOutputPath := filePath[:len(filePath)-len(filepath.Ext(filePath))] + "_thumb.webp"
113+
// thumbOutputPath := filePath[:len(filePath)-len(filepath.Ext(filePath))] + "_thumb.webp"
114+
thumbOutputPath := fmt.Sprintf("%s_thumb.webp", filePath[:len(filePath)-len(filepath.Ext(filePath))])
114115
if err := common.CompressImageByFFmpeg(filePath, thumbOutputPath, types.ThumbPhotoSideLength); err != nil {
115116
return nil, err
116117
}
@@ -122,7 +123,7 @@ func SaveAll(ctx context.Context, artwork *types.Artwork, picture *types.Picture
122123
if picture.ID == "" {
123124
picture.ID = primitive.NewObjectID().Hex()
124125
}
125-
thumbStorageFileName := picture.ID + "_thumb.webp"
126+
thumbStorageFileName := picture.ID + "_thumb." + config.Cfg.Storage.ThumbFormat
126127
thumbStoragePath := fmt.Sprintf("/thumb/%s/%s/%s", artwork.SourceType, artwork.Artist.UID, thumbStorageFileName)
127128

128129
thumbDetail, err = thumbStorage.Save(ctx, thumbOutputPath, thumbStoragePath)

types/permissions.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@ type Permission string
55
const (
66
PermissionPostArtwork Permission = "post_artwork"
77
PermissionDeleteArtwork Permission = "delete_artwork"
8-
PermissionFetchArtwork Permission = "fetch_artwork"
98
PermissionGetArtworkInfo Permission = "get_artwork_info"
10-
PermissionSearchPicture Permission = "search_picture"
119
PermissionEditArtwork Permission = "edit_artwork"
10+
11+
// deprecated
12+
PermissionFetchArtwork Permission = "fetch_artwork"
13+
PermissionSearchPicture Permission = "search_picture"
1214
)
1315

1416
var AllPermissions = []Permission{
1517
PermissionPostArtwork,
1618
PermissionDeleteArtwork,
17-
PermissionFetchArtwork,
1819
PermissionGetArtworkInfo,
19-
PermissionSearchPicture,
2020
PermissionEditArtwork,
21+
22+
// deprecated
23+
PermissionFetchArtwork,
24+
PermissionSearchPicture,
2125
}

0 commit comments

Comments
 (0)