summaryrefslogtreecommitdiff
path: root/internal/media/util.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-06-30 12:22:10 +0200
committerLibravatar GitHub <noreply@github.com>2022-06-30 12:22:10 +0200
commit9e7d022a06779a03e3eaaadad6cc33423f46892b (patch)
tree7c13c5af98fba382fc75c1dc195bdf0cc9cdd905 /internal/media/util.go
parent[feature] Use default instance thumbnail if instance account header not set (... (diff)
downloadgotosocial-9e7d022a06779a03e3eaaadad6cc33423f46892b.tar.xz
[feature] Cleanup unattached local media (#680)
* add localUnattached db function * add parseOlderThan util function * add pruneunusedlocalattachments to media manager * add unusedlocal pruning to schedule + admin call * set number of days to keep as a const * fix test
Diffstat (limited to 'internal/media/util.go')
-rw-r--r--internal/media/util.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/internal/media/util.go b/internal/media/util.go
index 6dfcede89..9d62619f5 100644
--- a/internal/media/util.go
+++ b/internal/media/util.go
@@ -21,6 +21,7 @@ package media
import (
"errors"
"fmt"
+ "time"
"github.com/h2non/filetype"
"github.com/sirupsen/logrus"
@@ -128,3 +129,19 @@ func (l *logrusWrapper) Info(msg string, keysAndValues ...interface{}) {
func (l *logrusWrapper) Error(err error, msg string, keysAndValues ...interface{}) {
logrus.Error("media manager cron logger: ", err, msg, keysAndValues)
}
+
+func parseOlderThan(olderThanDays int) (time.Time, error) {
+ // convert days into a duration string
+ olderThanHoursString := fmt.Sprintf("%dh", olderThanDays*24)
+
+ // parse the duration string into a duration
+ olderThanHours, err := time.ParseDuration(olderThanHoursString)
+ if err != nil {
+ return time.Time{}, err
+ }
+
+ // 'subtract' that from the time now to give our threshold
+ olderThan := time.Now().Add(-olderThanHours)
+
+ return olderThan, nil
+}