mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 15:02:25 -05:00
[feature] Customizable media cleaner schedule (#2304)
This commit is contained in:
parent
6fa80f164d
commit
4dc0547dc0
22 changed files with 300 additions and 98 deletions
|
|
@ -97,6 +97,8 @@ type Configuration struct {
|
|||
MediaRemoteCacheDays int `name:"media-remote-cache-days" usage:"Number of days to locally cache media from remote instances. If set to 0, remote media will be kept indefinitely."`
|
||||
MediaEmojiLocalMaxSize bytesize.Size `name:"media-emoji-local-max-size" usage:"Max size in bytes of emojis uploaded to this instance via the admin API."`
|
||||
MediaEmojiRemoteMaxSize bytesize.Size `name:"media-emoji-remote-max-size" usage:"Max size in bytes of emojis to download from other instances."`
|
||||
MediaCleanupFrom string `name:"media-cleanup-from" usage:"Time of day from which to start running media cleanup/prune jobs. Should be in the format 'hh:mm:ss', eg., '15:04:05'."`
|
||||
MediaCleanupEvery time.Duration `name:"media-cleanup-every" usage:"Period to elapse between cleanups, starting from media-cleanup-at."`
|
||||
|
||||
StorageBackend string `name:"storage-backend" usage:"Storage backend to use for media attachments"`
|
||||
StorageLocalBasePath string `name:"storage-local-base-path" usage:"Full path to an already-created directory where gts should store/retrieve media files. Subfolders will be created within this dir."`
|
||||
|
|
|
|||
|
|
@ -76,6 +76,8 @@ var Defaults = Configuration{
|
|||
MediaRemoteCacheDays: 7,
|
||||
MediaEmojiLocalMaxSize: 50 * bytesize.KiB,
|
||||
MediaEmojiRemoteMaxSize: 100 * bytesize.KiB,
|
||||
MediaCleanupFrom: "00:00", // Midnight.
|
||||
MediaCleanupEvery: 24 * time.Hour, // 1/day.
|
||||
|
||||
StorageBackend: "local",
|
||||
StorageLocalBasePath: "/gotosocial/storage",
|
||||
|
|
|
|||
|
|
@ -103,6 +103,8 @@ func (s *ConfigState) AddServerFlags(cmd *cobra.Command) {
|
|||
cmd.Flags().Int(MediaRemoteCacheDaysFlag(), cfg.MediaRemoteCacheDays, fieldtag("MediaRemoteCacheDays", "usage"))
|
||||
cmd.Flags().Uint64(MediaEmojiLocalMaxSizeFlag(), uint64(cfg.MediaEmojiLocalMaxSize), fieldtag("MediaEmojiLocalMaxSize", "usage"))
|
||||
cmd.Flags().Uint64(MediaEmojiRemoteMaxSizeFlag(), uint64(cfg.MediaEmojiRemoteMaxSize), fieldtag("MediaEmojiRemoteMaxSize", "usage"))
|
||||
cmd.Flags().String(MediaCleanupFromFlag(), cfg.MediaCleanupFrom, fieldtag("MediaCleanupFrom", "usage"))
|
||||
cmd.Flags().Duration(MediaCleanupEveryFlag(), cfg.MediaCleanupEvery, fieldtag("MediaCleanupEvery", "usage"))
|
||||
|
||||
// Storage
|
||||
cmd.Flags().String(StorageBackendFlag(), cfg.StorageBackend, fieldtag("StorageBackend", "usage"))
|
||||
|
|
|
|||
|
|
@ -1224,6 +1224,56 @@ func GetMediaEmojiRemoteMaxSize() bytesize.Size { return global.GetMediaEmojiRem
|
|||
// SetMediaEmojiRemoteMaxSize safely sets the value for global configuration 'MediaEmojiRemoteMaxSize' field
|
||||
func SetMediaEmojiRemoteMaxSize(v bytesize.Size) { global.SetMediaEmojiRemoteMaxSize(v) }
|
||||
|
||||
// GetMediaCleanupFrom safely fetches the Configuration value for state's 'MediaCleanupFrom' field
|
||||
func (st *ConfigState) GetMediaCleanupFrom() (v string) {
|
||||
st.mutex.RLock()
|
||||
v = st.config.MediaCleanupFrom
|
||||
st.mutex.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
// SetMediaCleanupFrom safely sets the Configuration value for state's 'MediaCleanupFrom' field
|
||||
func (st *ConfigState) SetMediaCleanupFrom(v string) {
|
||||
st.mutex.Lock()
|
||||
defer st.mutex.Unlock()
|
||||
st.config.MediaCleanupFrom = v
|
||||
st.reloadToViper()
|
||||
}
|
||||
|
||||
// MediaCleanupFromFlag returns the flag name for the 'MediaCleanupFrom' field
|
||||
func MediaCleanupFromFlag() string { return "media-cleanup-from" }
|
||||
|
||||
// GetMediaCleanupFrom safely fetches the value for global configuration 'MediaCleanupFrom' field
|
||||
func GetMediaCleanupFrom() string { return global.GetMediaCleanupFrom() }
|
||||
|
||||
// SetMediaCleanupFrom safely sets the value for global configuration 'MediaCleanupFrom' field
|
||||
func SetMediaCleanupFrom(v string) { global.SetMediaCleanupFrom(v) }
|
||||
|
||||
// GetMediaCleanupEvery safely fetches the Configuration value for state's 'MediaCleanupEvery' field
|
||||
func (st *ConfigState) GetMediaCleanupEvery() (v time.Duration) {
|
||||
st.mutex.RLock()
|
||||
v = st.config.MediaCleanupEvery
|
||||
st.mutex.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
// SetMediaCleanupEvery safely sets the Configuration value for state's 'MediaCleanupEvery' field
|
||||
func (st *ConfigState) SetMediaCleanupEvery(v time.Duration) {
|
||||
st.mutex.Lock()
|
||||
defer st.mutex.Unlock()
|
||||
st.config.MediaCleanupEvery = v
|
||||
st.reloadToViper()
|
||||
}
|
||||
|
||||
// MediaCleanupEveryFlag returns the flag name for the 'MediaCleanupEvery' field
|
||||
func MediaCleanupEveryFlag() string { return "media-cleanup-every" }
|
||||
|
||||
// GetMediaCleanupEvery safely fetches the value for global configuration 'MediaCleanupEvery' field
|
||||
func GetMediaCleanupEvery() time.Duration { return global.GetMediaCleanupEvery() }
|
||||
|
||||
// SetMediaCleanupEvery safely sets the value for global configuration 'MediaCleanupEvery' field
|
||||
func SetMediaCleanupEvery(v time.Duration) { global.SetMediaCleanupEvery(v) }
|
||||
|
||||
// GetStorageBackend safely fetches the Configuration value for state's 'StorageBackend' field
|
||||
func (st *ConfigState) GetStorageBackend() (v string) {
|
||||
st.mutex.RLock()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue