feat: update webda

v3
veypi 1 month ago
parent 401b8c6305
commit 42115a4cee

@ -0,0 +1,16 @@
#
# Makefile
# Copyright (C) 2024 veypi <i@veypi.com>
# 2024-10-22 16:36
# Distributed under terms of the GPL license.
#
cfg=~/.config/oa.yaml
run:
@go run main.go -f ${cfg}
dbrest:
@go run main.go -f ${cfg} db drop
@go run main.go -f ${cfg} db migrate
@go run main.go -f ${cfg} db init

@ -131,7 +131,7 @@ func userPost(x *rest.X) (any, error) {
if opts.Icon != nil {
data.Icon = *opts.Icon
} else {
data.Icon = fmt.Sprintf("/media/icon/%d.jpg", rand.New(rand.NewSource(time.Now().UnixNano())).Intn(230))
data.Icon = fmt.Sprintf("https://public.veypi.com/img/avatar/%04d.jpg", rand.New(rand.NewSource(time.Now().UnixNano())).Intn(220))
}
if opts.Email != nil {
data.Email = *opts.Email

@ -0,0 +1,32 @@
//
// app.go
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-10-22 15:42
// Distributed under terms of the GPL license.
//
package fs
import (
"net/http"
"oa/cfg"
"oa/libs/webdav"
"os"
"github.com/veypi/utils"
"github.com/veypi/utils/logv"
)
func NewAppFs(prefix string) func(http.ResponseWriter, *http.Request) {
apPath := utils.PathJoin(cfg.Config.FsPath, "app")
if !utils.FileExists(apPath) {
logv.AssertError(os.MkdirAll(apPath, 0744))
}
client := webdav.NewWebdav(apPath)
client.Prefix = prefix
client.GenSubPathFunc = func(r *http.Request) string {
return ""
}
return client.ServeHTTP
}

@ -0,0 +1,22 @@
//
// fs.go
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-10-22 15:51
// Distributed under terms of the GPL license.
//
package fs
import (
"net/http"
"oa/libs/webdav"
)
func NewFs(dir_path, prefix string) *webdav.Handler {
client := webdav.NewWebdav(dir_path)
client.Prefix = prefix
client.GenSubPathFunc = func(r *http.Request) string {
return ""
}
return client
}

@ -0,0 +1,32 @@
//
// user.go
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-10-22 15:49
// Distributed under terms of the GPL license.
//
package fs
import (
"net/http"
"oa/cfg"
"oa/libs/webdav"
"os"
"github.com/veypi/utils"
"github.com/veypi/utils/logv"
)
func NewUserFs(prefix string) func(http.ResponseWriter, *http.Request) {
tmp := utils.PathJoin(cfg.Config.FsPath, "u")
if !utils.FileExists(tmp) {
logv.AssertError(os.MkdirAll(tmp, 0744))
}
client := webdav.NewWebdav(tmp)
client.Prefix = prefix
client.GenSubPathFunc = func(r *http.Request) string {
return ""
}
return client.ServeHTTP
}

@ -11,21 +11,27 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"oa/builtin/webdav"
"oa/builtin/fs"
"oa/cfg"
"github.com/veypi/OneBD/rest"
"github.com/veypi/utils/logv"
)
func Enable(app *rest.Application) {
if cfg.Config.FsPath != "" {
r := app.Router().SubRouter("fs")
r.Any("/app/*", fs.NewAppFs("/fs/app"))
r.Any("/u/*", fs.NewUserFs("/fs/u"))
}
tsPorxy := httputil.NewSingleHostReverseProxy(logv.AssertFuncErr(url.Parse("http://v.v:8428")))
fsProxy := webdav.NewWebdav("/home/v/cache/")
fsProxy := fs.NewFs("/home/v/cache/", "")
app.SetMux(func(w http.ResponseWriter, r *http.Request) func(http.ResponseWriter, *http.Request) {
if r.Host == "ts.oa.v" || r.Header.Get("mux") == "ts" {
return tsPorxy.ServeHTTP
} else if r.Host == "fs.oa.v" {
return fsProxy
return fsProxy.ServeHTTP
}
return nil
})

@ -19,13 +19,8 @@ type config struct {
DSN string `json:"dsn"`
ID string `json:"id"`
Key string `json:"key"`
MediaPath string `json:"media"`
FsPath string `json:"fs"`
AccessUrl string `json:"access_url"`
Influxdb struct {
Host string `json:"host"`
Port string `json:"port"`
Token string `json:"token"`
} `json:"influxdb"`
}
var Config = &config{}

@ -135,7 +135,12 @@
<path
d="M946.5 505L560.1 118.8l-25.9-25.9c-12.3-12.2-32.1-12.2-44.4 0L77.5 505c-12.3 12.3-18.9 28.6-18.8 46 0.4 35.2 29.7 63.3 64.9 63.3h42.5V940h691.8V614.3h43.4c17.1 0 33.2-6.7 45.3-18.8 12.1-12.1 18.7-28.2 18.7-45.3 0-17-6.7-33.1-18.8-45.2zM568 868H456V664h112v204z m217.9-325.7V868H632V640c0-22.1-17.9-40-40-40H432c-22.1 0-40 17.9-40 40v228H238.1V542.3h-96l370-369.7 23.1 23.1L882 542.3h-96.1z"
p-id="3060"></path>
</svg></a>/{{ range .path }}{{if .}}<span><a class="path_tag">{{.}}</a></span>/{{end}}{{end}}
</svg></a>
&nbsp;/
{{ range .path }}{{if .}}
<span><a class="path_tag">{{.}}</a></span>
/
{{end}}{{end}}
</div>
<div class="container">
<div class="core">

@ -18,7 +18,7 @@ import (
"time"
)
func NewWebdav(p string) func(http.ResponseWriter, *http.Request) {
func NewWebdav(p string) *Handler {
fs := &Handler{
FileSystem: Dir(p),
LockSystem: NewMemLS(),
@ -27,7 +27,7 @@ func NewWebdav(p string) func(http.ResponseWriter, *http.Request) {
return ""
},
}
return fs.ServeHTTP
return fs
}
type Handler struct {

@ -32,7 +32,7 @@ import (
// In the long term, this package should use the standard library's version
// only, and the internal fork deleted, once
// https://github.com/golang/go/issues/13400 is resolved.
ixml "oa/builtin/webdav/internal/xml"
ixml "oa/libs/webdav/internal/xml"
)
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_lockinfo

@ -16,7 +16,7 @@ import (
"strings"
"testing"
ixml "oa/builtin/webdav/internal/xml"
ixml "oa/libs/webdav/internal/xml"
)
func TestReadLockInfo(t *testing.T) {

@ -21,10 +21,10 @@ type App struct {
type AppUser struct {
BaseModel
AppID string `json:"app_id" methods:"get,list,post,patch,delete" parse:"path"`
App *App `json:"-" gorm:"foreignKey:AppID;references:ID"`
App *App `json:"app" gorm:"foreignKey:AppID;references:ID"`
UserID string `json:"user_id" methods:"get,*list,post" parse:"json"`
User *User `json:"-" gorm:"foreignKey:UserID;references:ID"`
User *User `json:"user" gorm:"foreignKey:UserID;references:ID"`
Status string `json:"status" methods:"post,*patch,*list" parse:"json"`
}

@ -50,6 +50,9 @@ func init() {
func InitDBData() error {
app := &App{}
app.ID = cfg.Config.ID
app.Name = "OA"
app.Icon = "/favicon.ico"
app.Key = cfg.Config.Key
logv.AssertError(cfg.DB().Where("id = ?", app.ID).Attrs(app).FirstOrCreate(app).Error)
initRole := map[string]map[string]uint{
"user": {"admin": 5, "normal": 1},

Loading…
Cancel
Save