diff --git a/app/api/api.go b/app/api/api.go index 8937b74e..457a5e9a 100644 --- a/app/api/api.go +++ b/app/api/api.go @@ -476,6 +476,12 @@ func (a *api) start() error { return fmt.Errorf("disk filesystem: %w", err) } + if diskfsRoot, err := filepath.Abs(cfg.Storage.Disk.Dir); err != nil { + return err + } else { + diskfs.SetMetadata("base", diskfsRoot) + } + a.diskfs = diskfs baseMemFS := url.URL{ diff --git a/http/server.go b/http/server.go index 3cdd7a5d..cbc7f69f 100644 --- a/http/server.go +++ b/http/server.go @@ -155,7 +155,8 @@ type server struct { type filesystem struct { fs.FS - handler *handler.FSHandler + handler *handler.FSHandler + middleware echo.MiddlewareFunc } func NewServer(config Config) (Server, error) { @@ -196,13 +197,13 @@ func NewServer(config Config) (Server, error) { handler: handler.NewFS(fs), } - s.filesystems[filesystem.Name] = filesystem - if fs.Filesystem.Type() == "disk" { - s.middleware.hlsrewrite = mwhlsrewrite.NewHLSRewriteWithConfig(mwhlsrewrite.HLSRewriteConfig{ + filesystem.middleware = mwhlsrewrite.NewHLSRewriteWithConfig(mwhlsrewrite.HLSRewriteConfig{ PathPrefix: fs.Filesystem.Metadata("base"), }) } + + s.filesystems[filesystem.Name] = filesystem } if _, ok := corsPrefixes["/"]; !ok { @@ -461,6 +462,14 @@ func (s *server) setRoutes() { fs.Use(mwcache) } + if filesystem.middleware != nil { + fs.Use(filesystem.middleware) + } + + if s.middleware.session != nil { + fs.Use(s.middleware.session) + } + fs.GET("", filesystem.handler.GetFile) fs.HEAD("", filesystem.handler.GetFile) diff --git a/io/fs/fs.go b/io/fs/fs.go index f7b990b3..d8b8553b 100644 --- a/io/fs/fs.go +++ b/io/fs/fs.go @@ -43,8 +43,8 @@ type File interface { } type ReadFilesystem interface { - // Size returns the consumed size and capacity of the filesystem in bytes. If the - // capacity is 0 or smaller if the filesystem can consume as much space as it wants. + // Size returns the consumed size and capacity of the filesystem in bytes. The + // capacity is zero or negative if the filesystem can consume as much space as it wants. Size() (int64, int64) // Files returns the current number of files in the filesystem. diff --git a/io/fs/sized.go b/io/fs/sized.go index e97bcbb8..366ef6f5 100644 --- a/io/fs/sized.go +++ b/io/fs/sized.go @@ -22,7 +22,7 @@ type PurgeFilesystem interface { type sizedFilesystem struct { Filesystem - // Siez is the capacity of the filesystem in bytes + // Size is the capacity of the filesystem in bytes maxSize int64 // Set true to automatically delete the oldest files until there's @@ -106,7 +106,7 @@ func (r *sizedFilesystem) WriteFile(path string, data []byte) (int64, bool, erro func (r *sizedFilesystem) WriteFileSafe(path string, data []byte) (int64, bool, error) { currentSize, maxSize := r.Size() - if maxSize < 0 { + if maxSize <= 0 { return r.Filesystem.WriteFile(path, data) }