2021-08-23 18:40:03 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-11-19 18:54:49 +00:00
|
|
|
"git.deuxfleurs.fr/Deuxfleurs/bagage/s3"
|
2021-11-20 08:53:05 +00:00
|
|
|
"github.com/minio/minio-go/v7"
|
2021-08-23 18:40:03 +00:00
|
|
|
"golang.org/x/net/webdav"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
type WebDav struct {
|
|
|
|
WithConfig *Config
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wd WebDav) WithMC(mc *minio.Client) http.Handler {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
(&webdav.Handler{
|
|
|
|
Prefix: wd.WithConfig.DavPath,
|
2021-11-20 12:42:20 +00:00
|
|
|
FileSystem: s3.NewS3FS(mc, wd.WithConfig.S3Cache),
|
2021-08-23 18:40:03 +00:00
|
|
|
LockSystem: webdav.NewMemLS(),
|
|
|
|
Logger: func(r *http.Request, err error) {
|
|
|
|
log.Printf("INFO: %s %s %s\n", r.RemoteAddr, r.Method, r.URL)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("ERR: %v", err)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}).ServeHTTP(w, r)
|
|
|
|
})
|
|
|
|
}
|