✨ webdav(view only)
This commit is contained in:
parent
0b8d3a0a2c
commit
9eab54a7c8
@ -11,10 +11,12 @@ import (
|
|||||||
"github.com/Xhofe/alist/drivers"
|
"github.com/Xhofe/alist/drivers"
|
||||||
"github.com/Xhofe/alist/model"
|
"github.com/Xhofe/alist/model"
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FileSystem struct{}
|
type FileSystem struct{}
|
||||||
@ -46,12 +48,13 @@ func ParsePath(rawPath string) (*model.Account, string, drivers.Driver, error) {
|
|||||||
func (fs *FileSystem) File(rawPath string) (*model.File, error) {
|
func (fs *FileSystem) File(rawPath string) (*model.File, error) {
|
||||||
rawPath = utils.ParsePath(rawPath)
|
rawPath = utils.ParsePath(rawPath)
|
||||||
if model.AccountsCount() > 1 && rawPath == "/" {
|
if model.AccountsCount() > 1 && rawPath == "/" {
|
||||||
|
now := time.Now()
|
||||||
return &model.File{
|
return &model.File{
|
||||||
Name: "root",
|
Name: "root",
|
||||||
Size: 0,
|
Size: 0,
|
||||||
Type: conf.FOLDER,
|
Type: conf.FOLDER,
|
||||||
Driver: "root",
|
Driver: "root",
|
||||||
UpdatedAt: nil,
|
UpdatedAt: &now,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
account, path_, driver, err := ParsePath(rawPath)
|
account, path_, driver, err := ParsePath(rawPath)
|
||||||
@ -77,7 +80,7 @@ func (fs *FileSystem) Files(rawPath string) ([]model.File,error) {
|
|||||||
return driver.Files(path_, account)
|
return driver.Files(path_, account)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FileSystem) Link(rawPath string) (string, error) {
|
func (fs *FileSystem) Link(host, rawPath string) (string, error) {
|
||||||
rawPath = utils.ParsePath(rawPath)
|
rawPath = utils.ParsePath(rawPath)
|
||||||
if model.AccountsCount() > 1 && rawPath == "/" {
|
if model.AccountsCount() > 1 && rawPath == "/" {
|
||||||
// error
|
// error
|
||||||
@ -86,6 +89,14 @@ func (fs *FileSystem) Link(rawPath string) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
if account.Type == "Native" || account.Type == "GoogleDrive" {
|
||||||
|
link := fmt.Sprintf("//%s/d%s", host, rawPath)
|
||||||
|
if conf.CheckDown {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
log.Debugf("proxy link: %s", link)
|
||||||
|
return link, nil
|
||||||
|
}
|
||||||
return driver.Link(path_, account)
|
return driver.Link(path_, account)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,6 +197,7 @@ func (h *Handler) handleOptions(w http.ResponseWriter, r *http.Request, fs *File
|
|||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
allow := "OPTIONS, LOCK, PUT, MKCOL"
|
allow := "OPTIONS, LOCK, PUT, MKCOL"
|
||||||
if exist, fi := isPathExist(ctx, fs, reqPath); exist {
|
if exist, fi := isPathExist(ctx, fs, reqPath); exist {
|
||||||
|
log.Debugf("fi: %+v", fi)
|
||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
allow = "OPTIONS, LOCK, DELETE, PROPPATCH, COPY, MOVE, UNLOCK, PROPFIND"
|
allow = "OPTIONS, LOCK, DELETE, PROPPATCH, COPY, MOVE, UNLOCK, PROPFIND"
|
||||||
} else {
|
} else {
|
||||||
@ -231,7 +232,9 @@ func (h *Handler) handleGetHeadPost(w http.ResponseWriter, r *http.Request, fs *
|
|||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
w.Header().Set("ETag", etag)
|
w.Header().Set("ETag", etag)
|
||||||
link, err := fs.Link(reqPath)
|
log.Debugf("url: %+v", r.URL)
|
||||||
|
host := r.Host
|
||||||
|
link, err := fs.Link(host, reqPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user