mirror of
https://github.com/openziti/zrok.git
synced 2025-06-24 03:31:57 +02:00
align http/s webdav with zrok wrapper (#438)
This commit is contained in:
parent
b65d785881
commit
b6629d7fb4
@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,6 +31,22 @@ func NewWebDAVTarget(cfg *WebDAVTargetConfig) (*WebDAVTarget, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *WebDAVTarget) Inventory() ([]*Object, error) {
|
func (t *WebDAVTarget) Inventory() ([]*Object, error) {
|
||||||
|
rootFi, err := t.dc.Stat(context.Background(), t.cfg.URL.Path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !rootFi.IsDir {
|
||||||
|
base := filepath.Base(t.cfg.URL.Path)
|
||||||
|
t.cfg.URL.Path = filepath.Dir(t.cfg.URL.Path)
|
||||||
|
return []*Object{{
|
||||||
|
Path: "/" + base,
|
||||||
|
IsDir: false,
|
||||||
|
Size: rootFi.Size,
|
||||||
|
Modified: rootFi.ModTime,
|
||||||
|
}}, nil
|
||||||
|
}
|
||||||
|
|
||||||
fis, err := t.dc.Readdir(context.Background(), "", true)
|
fis, err := t.dc.Readdir(context.Background(), "", true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -50,15 +67,15 @@ func (t *WebDAVTarget) Inventory() ([]*Object, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *WebDAVTarget) Mkdir(path string) error {
|
func (t *WebDAVTarget) Mkdir(path string) error {
|
||||||
return t.dc.Mkdir(context.Background(), path)
|
return t.dc.Mkdir(context.Background(), filepath.Join(t.cfg.URL.Path, path))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *WebDAVTarget) ReadStream(path string) (io.ReadCloser, error) {
|
func (t *WebDAVTarget) ReadStream(path string) (io.ReadCloser, error) {
|
||||||
return t.dc.Open(context.Background(), path)
|
return t.dc.Open(context.Background(), filepath.Join(t.cfg.URL.Path, path))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *WebDAVTarget) WriteStream(path string, rs io.Reader, _ os.FileMode) error {
|
func (t *WebDAVTarget) WriteStream(path string, rs io.Reader, _ os.FileMode) error {
|
||||||
ws, err := t.dc.Create(context.Background(), path)
|
ws, err := t.dc.Create(context.Background(), filepath.Join(t.cfg.URL.Path, path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -71,5 +88,5 @@ func (t *WebDAVTarget) WriteStream(path string, rs io.Reader, _ os.FileMode) err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *WebDAVTarget) SetModificationTime(path string, mtime time.Time) error {
|
func (t *WebDAVTarget) SetModificationTime(path string, mtime time.Time) error {
|
||||||
return t.dc.Touch(context.Background(), path, mtime)
|
return t.dc.Touch(context.Background(), filepath.Join(t.cfg.URL.Path, path), mtime)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user