mirror of
https://github.com/datarhei/core.git
synced 2025-09-26 20:11:29 +08:00
Fix missing filesystem metadata and middlewares
This commit is contained in:
@@ -389,6 +389,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{
|
||||
|
@@ -84,7 +84,7 @@ func (h *FSHandler) PutFile(c echo.Context) error {
|
||||
|
||||
_, created, err := h.fs.Filesystem.WriteFileReader(path, req.Body)
|
||||
if err != nil {
|
||||
return api.Err(http.StatusBadRequest, "%s", err)
|
||||
return api.Err(http.StatusBadRequest, "Bad request", "%s", err)
|
||||
}
|
||||
|
||||
if h.fs.Cache != nil {
|
||||
|
@@ -153,7 +153,8 @@ type server struct {
|
||||
type filesystem struct {
|
||||
fs.FS
|
||||
|
||||
handler *handler.FSHandler
|
||||
handler *handler.FSHandler
|
||||
middleware echo.MiddlewareFunc
|
||||
}
|
||||
|
||||
func NewServer(config Config) (Server, error) {
|
||||
@@ -194,13 +195,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)
|
||||
|
||||
|
@@ -44,7 +44,7 @@ type File interface {
|
||||
|
||||
type ReadFilesystem interface {
|
||||
// Size returns the consumed size and capacity of the filesystem in bytes. The
|
||||
// capacity is negative if the filesystem can consume as much space as it wants.
|
||||
// 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.
|
||||
|
@@ -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
|
||||
@@ -67,7 +67,7 @@ func (r *sizedFilesystem) Resize(size int64) error {
|
||||
|
||||
func (r *sizedFilesystem) WriteFileReader(path string, rd io.Reader) (int64, bool, error) {
|
||||
currentSize, maxSize := r.Size()
|
||||
if maxSize < 0 {
|
||||
if maxSize <= 0 {
|
||||
return r.Filesystem.WriteFileReader(path, rd)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user