mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[bugfix] Parse video metadata more accurately; allow Range in fileserver (#1342)
* don't serve unused fields for video attachments * parse video bitrate + duration more accurately * use ServeContent where appropriate to respect Range * abstract temp file seeker into its own function
This commit is contained in:
@@ -20,6 +20,7 @@ package iotools
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// ReadFnCloser takes an io.Reader and wraps it to use the provided function to implement io.Closer.
|
||||
@@ -157,3 +158,35 @@ func StreamWriteFunc(write func(io.Writer) error) io.Reader {
|
||||
|
||||
return pr
|
||||
}
|
||||
|
||||
type tempFileSeeker struct {
|
||||
io.Reader
|
||||
io.Seeker
|
||||
tmp *os.File
|
||||
}
|
||||
|
||||
func (tfs *tempFileSeeker) Close() error {
|
||||
tfs.tmp.Close()
|
||||
return os.Remove(tfs.tmp.Name())
|
||||
}
|
||||
|
||||
// TempFileSeeker converts the provided Reader into a ReadSeekCloser
|
||||
// by using an underlying temporary file. Callers should call the Close
|
||||
// function when they're done with the TempFileSeeker, to release +
|
||||
// clean up the temporary file.
|
||||
func TempFileSeeker(r io.Reader) (io.ReadSeekCloser, error) {
|
||||
tmp, err := os.CreateTemp(os.TempDir(), "gotosocial-")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := io.Copy(tmp, r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &tempFileSeeker{
|
||||
Reader: tmp,
|
||||
Seeker: tmp,
|
||||
tmp: tmp,
|
||||
}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user