1package config 2 3import ( 4 "fmt" 5) 6 7type MediaAPI struct { 8 Matrix *Global `yaml:"-"` 9 10 InternalAPI InternalAPIOptions `yaml:"internal_api"` 11 ExternalAPI ExternalAPIOptions `yaml:"external_api"` 12 13 // The MediaAPI database stores information about files uploaded and downloaded 14 // by local users. It is only accessed by the MediaAPI. 15 Database DatabaseOptions `yaml:"database"` 16 17 // The base path to where the media files will be stored. May be relative or absolute. 18 BasePath Path `yaml:"base_path"` 19 20 // The absolute base path to where media files will be stored. 21 AbsBasePath Path `yaml:"-"` 22 23 // The maximum file size in bytes that is allowed to be stored on this server. 24 // Note: if max_file_size_bytes is set to 0, the size is unlimited. 25 // Note: if max_file_size_bytes is not set, it will default to 10485760 (10MB) 26 MaxFileSizeBytes *FileSizeBytes `yaml:"max_file_size_bytes,omitempty"` 27 28 // Whether to dynamically generate thumbnails on-the-fly if the requested resolution is not already generated 29 DynamicThumbnails bool `yaml:"dynamic_thumbnails"` 30 31 // The maximum number of simultaneous thumbnail generators. default: 10 32 MaxThumbnailGenerators int `yaml:"max_thumbnail_generators"` 33 34 // A list of thumbnail sizes to be pre-generated for downloaded remote / uploaded content 35 ThumbnailSizes []ThumbnailSize `yaml:"thumbnail_sizes"` 36} 37 38// DefaultMaxFileSizeBytes defines the default file size allowed in transfers 39var DefaultMaxFileSizeBytes = FileSizeBytes(10485760) 40 41func (c *MediaAPI) Defaults() { 42 c.InternalAPI.Listen = "http://localhost:7774" 43 c.InternalAPI.Connect = "http://localhost:7774" 44 c.ExternalAPI.Listen = "http://[::]:8074" 45 c.Database.Defaults(5) 46 c.Database.ConnectionString = "file:mediaapi.db" 47 48 c.MaxFileSizeBytes = &DefaultMaxFileSizeBytes 49 c.MaxThumbnailGenerators = 10 50 c.BasePath = "./media_store" 51} 52 53func (c *MediaAPI) Verify(configErrs *ConfigErrors, isMonolith bool) { 54 checkURL(configErrs, "media_api.internal_api.listen", string(c.InternalAPI.Listen)) 55 checkURL(configErrs, "media_api.internal_api.connect", string(c.InternalAPI.Connect)) 56 if !isMonolith { 57 checkURL(configErrs, "media_api.external_api.listen", string(c.ExternalAPI.Listen)) 58 } 59 checkNotEmpty(configErrs, "media_api.database.connection_string", string(c.Database.ConnectionString)) 60 61 checkNotEmpty(configErrs, "media_api.base_path", string(c.BasePath)) 62 checkPositive(configErrs, "media_api.max_file_size_bytes", int64(*c.MaxFileSizeBytes)) 63 checkPositive(configErrs, "media_api.max_thumbnail_generators", int64(c.MaxThumbnailGenerators)) 64 65 for i, size := range c.ThumbnailSizes { 66 checkPositive(configErrs, fmt.Sprintf("media_api.thumbnail_sizes[%d].width", i), int64(size.Width)) 67 checkPositive(configErrs, fmt.Sprintf("media_api.thumbnail_sizes[%d].height", i), int64(size.Height)) 68 } 69} 70