mirror of
https://github.com/datarhei/core.git
synced 2025-10-05 16:07:07 +08:00
Merge branch 'dev' into iam
This commit is contained in:
@@ -476,6 +476,12 @@ func (a *api) start() error {
|
|||||||
return fmt.Errorf("disk filesystem: %w", err)
|
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
|
a.diskfs = diskfs
|
||||||
|
|
||||||
baseMemFS := url.URL{
|
baseMemFS := url.URL{
|
||||||
|
@@ -155,7 +155,8 @@ type server struct {
|
|||||||
type filesystem struct {
|
type filesystem struct {
|
||||||
fs.FS
|
fs.FS
|
||||||
|
|
||||||
handler *handler.FSHandler
|
handler *handler.FSHandler
|
||||||
|
middleware echo.MiddlewareFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(config Config) (Server, error) {
|
func NewServer(config Config) (Server, error) {
|
||||||
@@ -196,13 +197,13 @@ func NewServer(config Config) (Server, error) {
|
|||||||
handler: handler.NewFS(fs),
|
handler: handler.NewFS(fs),
|
||||||
}
|
}
|
||||||
|
|
||||||
s.filesystems[filesystem.Name] = filesystem
|
|
||||||
|
|
||||||
if fs.Filesystem.Type() == "disk" {
|
if fs.Filesystem.Type() == "disk" {
|
||||||
s.middleware.hlsrewrite = mwhlsrewrite.NewHLSRewriteWithConfig(mwhlsrewrite.HLSRewriteConfig{
|
filesystem.middleware = mwhlsrewrite.NewHLSRewriteWithConfig(mwhlsrewrite.HLSRewriteConfig{
|
||||||
PathPrefix: fs.Filesystem.Metadata("base"),
|
PathPrefix: fs.Filesystem.Metadata("base"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.filesystems[filesystem.Name] = filesystem
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := corsPrefixes["/"]; !ok {
|
if _, ok := corsPrefixes["/"]; !ok {
|
||||||
@@ -461,6 +462,14 @@ func (s *server) setRoutes() {
|
|||||||
fs.Use(mwcache)
|
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.GET("", filesystem.handler.GetFile)
|
||||||
fs.HEAD("", filesystem.handler.GetFile)
|
fs.HEAD("", filesystem.handler.GetFile)
|
||||||
|
|
||||||
|
@@ -43,8 +43,8 @@ type File interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ReadFilesystem interface {
|
type ReadFilesystem interface {
|
||||||
// Size returns the consumed size and capacity of the filesystem in bytes. If the
|
// Size returns the consumed size and capacity of the filesystem in bytes. The
|
||||||
// capacity is 0 or smaller 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)
|
Size() (int64, int64)
|
||||||
|
|
||||||
// Files returns the current number of files in the filesystem.
|
// Files returns the current number of files in the filesystem.
|
||||||
|
@@ -22,7 +22,7 @@ type PurgeFilesystem interface {
|
|||||||
type sizedFilesystem struct {
|
type sizedFilesystem struct {
|
||||||
Filesystem
|
Filesystem
|
||||||
|
|
||||||
// Siez is the capacity of the filesystem in bytes
|
// Size is the capacity of the filesystem in bytes
|
||||||
maxSize int64
|
maxSize int64
|
||||||
|
|
||||||
// Set true to automatically delete the oldest files until there's
|
// 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) {
|
func (r *sizedFilesystem) WriteFileSafe(path string, data []byte) (int64, bool, error) {
|
||||||
currentSize, maxSize := r.Size()
|
currentSize, maxSize := r.Size()
|
||||||
if maxSize < 0 {
|
if maxSize <= 0 {
|
||||||
return r.Filesystem.WriteFile(path, data)
|
return r.Filesystem.WriteFile(path, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user