2020-08-10 08:18:04 -05:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MediaAPI struct {
|
|
|
|
Matrix *Global `yaml:"-"`
|
|
|
|
|
|
|
|
// The MediaAPI database stores information about files uploaded and downloaded
|
|
|
|
// by local users. It is only accessed by the MediaAPI.
|
2022-09-01 08:15:41 -05:00
|
|
|
Database DatabaseOptions `yaml:"database,omitempty"`
|
2020-08-10 08:18:04 -05:00
|
|
|
|
|
|
|
// The base path to where the media files will be stored. May be relative or absolute.
|
|
|
|
BasePath Path `yaml:"base_path"`
|
|
|
|
|
|
|
|
// The absolute base path to where media files will be stored.
|
|
|
|
AbsBasePath Path `yaml:"-"`
|
|
|
|
|
|
|
|
// The maximum file size in bytes that is allowed to be stored on this server.
|
|
|
|
// Note: if max_file_size_bytes is set to 0, the size is unlimited.
|
|
|
|
// Note: if max_file_size_bytes is not set, it will default to 10485760 (10MB)
|
2022-05-02 03:47:16 -05:00
|
|
|
MaxFileSizeBytes FileSizeBytes `yaml:"max_file_size_bytes,omitempty"`
|
2020-08-10 08:18:04 -05:00
|
|
|
|
|
|
|
// Whether to dynamically generate thumbnails on-the-fly if the requested resolution is not already generated
|
|
|
|
DynamicThumbnails bool `yaml:"dynamic_thumbnails"`
|
|
|
|
|
|
|
|
// The maximum number of simultaneous thumbnail generators. default: 10
|
|
|
|
MaxThumbnailGenerators int `yaml:"max_thumbnail_generators"`
|
|
|
|
|
|
|
|
// A list of thumbnail sizes to be pre-generated for downloaded remote / uploaded content
|
|
|
|
ThumbnailSizes []ThumbnailSize `yaml:"thumbnail_sizes"`
|
|
|
|
}
|
|
|
|
|
2021-07-19 11:58:51 -05:00
|
|
|
// DefaultMaxFileSizeBytes defines the default file size allowed in transfers
|
|
|
|
var DefaultMaxFileSizeBytes = FileSizeBytes(10485760)
|
|
|
|
|
2022-09-01 08:15:41 -05:00
|
|
|
func (c *MediaAPI) Defaults(opts DefaultOpts) {
|
2022-05-13 02:33:55 -05:00
|
|
|
c.MaxFileSizeBytes = DefaultMaxFileSizeBytes
|
|
|
|
c.MaxThumbnailGenerators = 10
|
2022-09-01 08:15:41 -05:00
|
|
|
if opts.Generate {
|
|
|
|
c.ThumbnailSizes = []ThumbnailSize{
|
|
|
|
{
|
|
|
|
Width: 32,
|
|
|
|
Height: 32,
|
|
|
|
ResizeMethod: "crop",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Width: 96,
|
|
|
|
Height: 96,
|
|
|
|
ResizeMethod: "crop",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Width: 640,
|
|
|
|
Height: 480,
|
|
|
|
ResizeMethod: "scale",
|
|
|
|
},
|
|
|
|
}
|
2023-02-14 05:47:47 -06:00
|
|
|
if !opts.SingleDatabase {
|
2022-09-01 08:15:41 -05:00
|
|
|
c.Database.ConnectionString = "file:mediaapi.db"
|
|
|
|
}
|
2021-11-24 05:57:39 -06:00
|
|
|
c.BasePath = "./media_store"
|
|
|
|
}
|
2020-08-10 08:18:04 -05:00
|
|
|
}
|
|
|
|
|
2023-02-14 05:47:47 -06:00
|
|
|
func (c *MediaAPI) Verify(configErrs *ConfigErrors) {
|
2020-08-10 08:18:04 -05:00
|
|
|
checkNotEmpty(configErrs, "media_api.base_path", string(c.BasePath))
|
2022-05-02 03:47:16 -05:00
|
|
|
checkPositive(configErrs, "media_api.max_file_size_bytes", int64(c.MaxFileSizeBytes))
|
2020-08-10 08:18:04 -05:00
|
|
|
checkPositive(configErrs, "media_api.max_thumbnail_generators", int64(c.MaxThumbnailGenerators))
|
|
|
|
|
|
|
|
for i, size := range c.ThumbnailSizes {
|
|
|
|
checkPositive(configErrs, fmt.Sprintf("media_api.thumbnail_sizes[%d].width", i), int64(size.Width))
|
|
|
|
checkPositive(configErrs, fmt.Sprintf("media_api.thumbnail_sizes[%d].height", i), int64(size.Height))
|
|
|
|
}
|
2023-02-14 05:47:47 -06:00
|
|
|
|
2022-09-01 08:15:41 -05:00
|
|
|
if c.Matrix.DatabaseOptions.ConnectionString == "" {
|
|
|
|
checkNotEmpty(configErrs, "media_api.database.connection_string", string(c.Database.ConnectionString))
|
|
|
|
}
|
2020-08-10 08:18:04 -05:00
|
|
|
}
|