[feature] Clean up/uncache remote media (#407)

* Add whereNotEmptyAndNotNull

* Add GetRemoteOlderThanDays

* Add GetRemoteOlderThanDays

* Add PruneRemote to Manager interface

* Start implementing PruneRemote

* add new attachment + status to tests

* fix up and test GetRemoteOlderThan

* fix bad import

* PruneRemote: return number pruned

* add Cached column to mediaattachment

* update + test pruneRemote

* update mediaTest

* use Cached column

* upstep bun to latest version

* embed structs in mediaAttachment

* migrate mediaAttachment to new format

* don't default cached to true

* select only remote media

* update db dependencies

* step bun back to last working version

* update pruneRemote to use Cached field

* fix storage path of test attachments

* add recache logic to manager

* fix trimmed aspect ratio

* test prune and recache

* return errwithcode

* tidy up different paths for emoji vs attachment

* fix incorrect thumbnail type being stored

* expose TransportController to media processor

* implement tee-ing recached content

* add thoughts of dog to test fedi attachments

* test get remote files

* add comment on PruneRemote

* add postData cleanup to recache

* test thumbnail fetching

* add incredible diagram

* go mod tidy

* buffer pipes for recache streaming

* test for client stops reading after 1kb

* add media-remote-cache-days to config

* add cron package

* wrap logrus so it's available to cron

* start and stop cron jobs gracefully
This commit is contained in:
tobi 2022-03-07 11:08:26 +01:00 committed by GitHub
commit 07727753b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
424 changed files with 637100 additions and 176498 deletions

View file

@ -19,6 +19,7 @@ import (
"unicode"
"unsafe"
guuid "github.com/google/uuid"
"golang.org/x/sys/unix"
"modernc.org/libc/errno"
"modernc.org/libc/fcntl"
@ -36,6 +37,7 @@ import (
"modernc.org/libc/termios"
"modernc.org/libc/time"
"modernc.org/libc/unistd"
"modernc.org/libc/uuid/uuid"
"modernc.org/libc/wctype"
)
@ -908,42 +910,6 @@ func Xfileno(t *TLS, stream uintptr) int32 {
return -1
}
// int mkstemps(char *template, int suffixlen);
func Xmkstemps(t *TLS, template uintptr, suffixlen int32) int32 {
panic(todo(""))
}
// int mkstemps(char *template, int suffixlen);
func Xmkstemps64(t *TLS, template uintptr, suffixlen int32) int32 {
len := uintptr(Xstrlen(t, template))
x := template + uintptr(len-6) - uintptr(suffixlen)
for i := uintptr(0); i < 6; i++ {
if *(*byte)(unsafe.Pointer(x + i)) != 'X' {
if dmesgs {
dmesg("%v: FAIL", origin(1))
}
t.setErrno(errno.EINVAL)
return -1
}
}
fd, err := tempFile(template, x)
if err != nil {
if dmesgs {
dmesg("%v: %v FAIL", origin(1), err)
}
t.setErrno(err)
return -1
}
return int32(fd)
}
// int mkstemp(char *template);
func Xmkstemp(t *TLS, template uintptr) int32 {
return Xmkstemps64(t, template, 0)
}
func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) (r *fts.FTSENT) {
var statp uintptr
if stat != nil {
@ -1214,14 +1180,16 @@ func Xfork(t *TLS) int32 {
return -1
}
var emptyStr = [1]byte{}
// char *setlocale(int category, const char *locale);
func Xsetlocale(t *TLS, category int32, locale uintptr) uintptr {
return 0 //TODO
return uintptr(unsafe.Pointer(&emptyStr)) //TODO
}
// char *nl_langinfo(nl_item item);
func Xnl_langinfo(t *TLS, item langinfo.Nl_item) uintptr {
panic(todo(""))
return uintptr(unsafe.Pointer(&emptyStr)) //TODO
}
// FILE *popen(const char *command, const char *type);
@ -2002,3 +1970,61 @@ func Xungetc(t *TLS, c int32, stream uintptr) int32 {
func Xissetugid(t *TLS) int32 {
panic(todo(""))
}
var progname uintptr
// const char *getprogname(void);
func Xgetprogname(t *TLS) uintptr {
if progname != 0 {
return progname
}
var err error
progname, err = CString(filepath.Base(os.Args[0]))
if err != nil {
t.setErrno(err)
return 0
}
return progname
}
// void uuid_copy(uuid_t dst, uuid_t src);
func Xuuid_copy(t *TLS, dst, src uintptr) {
*(*uuid.Uuid_t)(unsafe.Pointer(dst)) = *(*uuid.Uuid_t)(unsafe.Pointer(src))
}
// int uuid_parse( char *in, uuid_t uu);
func Xuuid_parse(t *TLS, in uintptr, uu uintptr) int32 {
r, err := guuid.Parse(GoString(in))
if err != nil {
return -1
}
copy((*RawMem)(unsafe.Pointer(uu))[:unsafe.Sizeof(uuid.Uuid_t{})], r[:])
return 0
}
// struct __float2 { float __sinval; float __cosval; };
// struct __float2 __sincosf_stret(float);
func X__sincosf_stret(t *TLS, f float32) struct{ F__sinval, F__cosval float32 } {
panic(todo(""))
}
// struct __double2 { double __sinval; double __cosval; };
// struct __double2 __sincos_stret(double);
func X__sincos_stret(t *TLS, f float64) struct{ F__sinval, F__cosval float64 } {
panic(todo(""))
}
// struct __float2 __sincospif_stret(float);
func X__sincospif_stret(t *TLS, f float32) struct{ F__sinval, F__cosval float32 } {
panic(todo(""))
}
// struct _double2 __sincospi_stret(double);
func X__sincospi_stret(t *TLS, f float64) struct{ F__sinval, F__cosval float64 } {
panic(todo(""))
}