chore (refactoring): complete migration to pkg :)

This commit is contained in:
mickael-kerjean
2026-08-21 13:29:17 +10:00
committed by MickaelK
parent adb0435b7d
commit d28da99498
75 changed files with 275 additions and 357 deletions
+15
View File
@@ -8,6 +8,8 @@ import (
"github.com/mickael-kerjean/filestash/server/pkg/kernel"
"github.com/mickael-kerjean/filestash/server/pkg/mime"
"github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/mickael-kerjean/filestash/server/pkg/share"
"github.com/mickael-kerjean/filestash/server/pkg/files"
)
type App = core.App
@@ -176,6 +178,19 @@ var (
WhiteLabelText = env.WhiteLabelText
)
// files
var (
NewBackend = files.NewBackend
GetHome = files.GetHome
)
// share
var (
ShareAll = share.ShareAll
ShareList = share.ShareList
ShareDelete = share.ShareDelete
ShareUpsert = share.ShareUpsert
)
// admin.go
var NewAdminToken = admin.NewAdminToken
+1 -1
View File
@@ -15,11 +15,11 @@ var (
PublicCORS = middleware.PublicCORS
SecureHeaders = middleware.SecureHeaders
SecureOrigin = middleware.SecureOrigin
LoggedInOnly = middleware.LoggedInOnly
BodyParser = middleware.BodyParser
PluginInjector = middleware.PluginInjector
RateLimiter = middleware.RateLimiter
AdminOnly = admin.AdminOnly
LoggedInOnly = session.LoggedInOnly
SessionTry = session.Try
SessionStart = session.Start
CanManageShare = share.CanManageShare(session.Start, session.FromRequest)
-22
View File
@@ -1,22 +0,0 @@
package model
import (
_ "github.com/mickael-kerjean/filestash/server/pkg/admin"
"github.com/mickael-kerjean/filestash/server/pkg/files"
"github.com/mickael-kerjean/filestash/server/pkg/share"
"github.com/mickael-kerjean/filestash/server/pkg/sqlite"
)
var DB = sqlite.DB
var (
NewBackend = files.NewBackend
GetHome = files.GetHome
)
var (
ShareAll = share.All
ShareList = share.List
ShareDelete = share.Delete
ShareUpsert = share.Upsert
)
+2 -1
View File
@@ -4,7 +4,8 @@ import (
"net/http"
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
type option func(*http.Cookie)
+2 -3
View File
@@ -15,15 +15,14 @@ func main() {
cmd.Stdout = b
cmd.Run()
f, err := os.OpenFile("constants_generated.go", os.O_CREATE|os.O_WRONLY, os.ModePerm)
f, err := os.OpenFile("constants_generated.go", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
return
}
defer f.Close()
f.Write([]byte(fmt.Sprintf(`
package env
f.Write([]byte(fmt.Sprintf(`package env
var (
BUILD_REF = "%s"
+4 -4
View File
@@ -6,7 +6,7 @@ import (
"log"
"net/http"
"github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
"github.com/mickael-kerjean/filestash/server/pkg/extension/adapter/runtime"
)
@@ -17,14 +17,14 @@ type middlewareState struct {
next *bool
}
func MiddlewareExtension(wasm []byte) (func(common.HandlerFunc) common.HandlerFunc, error) {
func MiddlewareExtension(wasm []byte) (func(HandlerFunc) HandlerFunc, error) {
rt, err := runtime.New(wasm, middlewareExports())
if err != nil {
return nil, err
}
return func(next common.HandlerFunc) common.HandlerFunc {
return func(app *common.App, w http.ResponseWriter, r *http.Request) {
return func(next HandlerFunc) HandlerFunc {
return func(app *App, w http.ResponseWriter, r *http.Request) {
callNext := false
err := rt.Call(r.Context(), "middleware", middlewareKey{}, &middlewareState{r: r, w: w, next: &callNext})
if errors.Is(err, runtime.ErrNoExport) || callNext {
+4 -4
View File
@@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
"github.com/mickael-kerjean/filestash/server/pkg/extension/adapter/runtime"
)
@@ -13,14 +13,14 @@ type workflowActionKey struct{}
type workflowActionState struct {
rt *runtime.Runtime
manifest common.WorkflowSpecs
manifest WorkflowSpecs
params map[string]string
input map[string]string
output map[string]string
err error
}
func WorkflowActionExtension(wasm []byte) (common.IAction, error) {
func WorkflowActionExtension(wasm []byte) (IAction, error) {
was := &workflowActionState{}
rt, err := runtime.New(wasm, workflowActionExports())
if err != nil {
@@ -63,7 +63,7 @@ func workflowActionExports() runtime.Option {
})
}
func (this *workflowActionState) Manifest() common.WorkflowSpecs {
func (this *workflowActionState) Manifest() WorkflowSpecs {
this.rt.Call(context.Background(), "manifest", workflowActionKey{}, this)
return this.manifest
}
+3 -1
View File
@@ -8,7 +8,9 @@ import (
"os"
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/mickael-kerjean/filestash/server/pkg/extension/adapter"
)
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"regexp"
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
var ListOfPlugins = struct {
+3 -1
View File
@@ -1,7 +1,9 @@
package files
import (
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
)
func init() {
+3 -1
View File
@@ -4,7 +4,9 @@ import (
"net/http"
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
)
+6 -1
View File
@@ -10,7 +10,12 @@ import (
"strconv"
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/mime"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
)
+3 -1
View File
@@ -11,7 +11,9 @@ import (
"strings"
"time"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
)
+3 -1
View File
@@ -10,7 +10,9 @@ import (
"strconv"
"time"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
)
+3 -1
View File
@@ -5,7 +5,9 @@ import (
"fmt"
"net/http"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func MetaGet(ctx *App, w http.ResponseWriter, r *http.Request) {
+3 -1
View File
@@ -3,7 +3,9 @@ package files
import (
"net/http"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
)
+3 -1
View File
@@ -3,7 +3,9 @@ package files
import (
"net/http"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
)
+3 -1
View File
@@ -3,7 +3,9 @@ package files
import (
"net/http"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
)
+3 -1
View File
@@ -16,7 +16,9 @@ import (
"strings"
"sync"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
)
+3 -1
View File
@@ -4,7 +4,9 @@ import (
"net/http"
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
)
+3 -1
View File
@@ -3,7 +3,9 @@ package files
import (
"net/http"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
)
+3 -1
View File
@@ -9,7 +9,9 @@ import (
"strings"
"time"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
)
+5 -3
View File
@@ -3,8 +3,10 @@ package files
import (
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
)
func NewBackend(ctx *App, conn map[string]string) (IBackend, error) {
@@ -47,7 +49,7 @@ func NewBackend(ctx *App, conn map[string]string) (IBackend, error) {
}
if isAllowed() == false {
return Backend.Get(kernel.BACKEND_NIL), ErrNotAllowed
return Backend.Get(BACKEND_NIL), ErrNotAllowed
}
return Backend.Get(conn["type"]).Init(conn, ctx)
}
+4 -1
View File
@@ -10,7 +10,10 @@ import (
"strings"
"text/template"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/mickael-kerjean/filestash/server/pkg/extension"
)
+5 -1
View File
@@ -4,7 +4,11 @@ import (
"net/http"
"regexp"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/mime"
)
func PublicConfigHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
+4 -1
View File
@@ -8,7 +8,10 @@ import (
"slices"
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func HealthHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
+5 -1
View File
@@ -7,7 +7,11 @@ import (
"path/filepath"
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/mime"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/mickael-kerjean/filestash/server/pkg/extension"
"github.com/gorilla/mux"
+2 -1
View File
@@ -3,7 +3,8 @@ package frontend
import (
"net/http"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
)
func ReportHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
+6 -1
View File
@@ -20,7 +20,12 @@ import (
. "github.com/mickael-kerjean/filestash"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/mime"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/mickael-kerjean/filestash/server/pkg/compress"
"github.com/bluekeyes/go-gitdiff/gitdiff"
+3 -1
View File
@@ -3,7 +3,9 @@ package frontend
import (
"net/http"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
)
func WellKnownSecurityHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
+3 -1
View File
@@ -5,7 +5,9 @@ import (
"io"
"net/http"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func BodyParser(fn HandlerFunc) HandlerFunc {
+6 -1
View File
@@ -6,7 +6,12 @@ import (
"path/filepath"
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/mime"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"golang.org/x/time/rate"
)
+2 -1
View File
@@ -5,7 +5,8 @@ import (
"time"
_ "unsafe"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
)
func init() {
-190
View File
@@ -1,190 +0,0 @@
package middleware
import (
"bytes"
"encoding/base64"
"encoding/json"
"net/http"
"regexp"
"strings"
"time"
. "github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/filestash/server/model"
"github.com/mickael-kerjean/filestash/server/pkg/share"
"github.com/mickael-kerjean/filestash/server/pkg/token"
"github.com/mickael-kerjean/filestash/server/pkg/env"
"github.com/gorilla/mux"
)
func LoggedInOnly(fn HandlerFunc) HandlerFunc {
return HandlerFunc(func(ctx *App, res http.ResponseWriter, req *http.Request) {
if ctx.Backend == nil || ctx.Session == nil {
SendErrorResult(res, ErrPermissionDenied)
return
}
fn(ctx, res, req)
})
}
func SessionStart(fn HandlerFunc) HandlerFunc {
return HandlerFunc(func(ctx *App, res http.ResponseWriter, req *http.Request) {
var err error
if ctx.Share, err = _extractShare(req); err != nil {
SendErrorResult(res, err)
return
}
ctx.Authorization = token.Extract(req)
if ctx.Session, err = _extractSession(req, ctx); err != nil {
share.RecoverFromBadCookie(res)
SendErrorResult(res, err)
return
}
if ctx.Backend, err = _extractBackend(req, ctx); err != nil {
if len(ctx.Session) == 0 {
SendErrorResult(res, ErrNotAuthorized)
return
}
SendErrorResult(res, err)
return
}
ctx.Languages = _extractLanguages(req)
fn(ctx, res, req)
})
}
func SessionTry(fn HandlerFunc) HandlerFunc {
return HandlerFunc(func(ctx *App, res http.ResponseWriter, req *http.Request) {
ctx.Share, _ = _extractShare(req)
ctx.Authorization = token.Extract(req)
ctx.Session, _ = _extractSession(req, ctx)
ctx.Backend, _ = _extractBackend(req, ctx)
fn(ctx, res, req)
})
}
func _extractShareId(req *http.Request) string {
share := req.URL.Query().Get("share")
if share != "" {
return share
}
m := mux.Vars(req)["share"]
if m == "private" {
return ""
}
return m
}
func _extractShare(req *http.Request) (Share, error) {
var err error
share_id := _extractShareId(req)
if share_id == "" {
return Share{}, nil
}
if Config.Get("features.share.enable").Bool() == false {
Log.Debug("Share feature isn't enabled, contact your administrator")
return Share{}, NewError("Feature isn't enabled, contact your administrator", 405)
}
s, err := share.Get(share_id)
if err != nil {
return Share{}, nil
}
if err = share.IsValid(s); err != nil {
return Share{}, err
}
verifiedProof := share.Verified(req)
username, password := func(authHeader string) (string, string) {
decoded, err := base64.StdEncoding.DecodeString(
strings.TrimPrefix(authHeader, "Basic "),
)
if err != nil {
return "", ""
}
s := bytes.Split(decoded, []byte(":"))
if len(s) < 2 {
return "", ""
}
p := string(bytes.Join(s[1:], []byte(":")))
usr := regexp.MustCompile(`^(.*)\[([0-9a-zA-Z]+)\]$`).FindStringSubmatch(string(s[0]))
if len(usr) != 3 {
return "", p
}
if Hash(usr[1]+env.SECRET_KEY_DERIVATE_FOR_HASH, 10) != usr[2] {
return "", p
}
return usr[1], p
}(req.Header.Get("Authorization"))
if s.Users != nil && username != "" {
if v, ok := share.VerifyEmail(*s.Users, username); ok {
verifiedProof = append(verifiedProof, share.Proof{Key: "email", Value: v})
}
}
if s.Password != nil && password != "" {
if v, ok := share.VerifyPassword(*s.Password, password); ok {
verifiedProof = append(verifiedProof, share.Proof{Key: "password", Value: v})
}
}
if remainingProof := share.Remainings(share.Required(s), verifiedProof); len(remainingProof) != 0 {
return Share{}, NewError("Unauthorized Shared space", 400)
}
return s, nil
}
func _extractSession(req *http.Request, ctx *App) (map[string]string, error) {
var (
str string
err error
session map[string]string = make(map[string]string)
)
if ctx.Share.Id != "" {
str, err = DecryptString(env.SECRET_KEY_DERIVATE_FOR_USER, ctx.Share.Auth)
if err != nil {
// This typically happen when changing the secret key
return session, ErrNotAuthorized
}
err = json.Unmarshal([]byte(str), &session)
session["path"] = ctx.Share.Path
return session, err
}
if ctx.Authorization == "" {
return session, nil
}
str, err = DecryptString(env.SECRET_KEY_DERIVATE_FOR_USER, ctx.Authorization)
if err != nil {
// This typically happen when changing the secret key
Log.Debug("middleware::session decrypt error '%s'", err.Error())
return session, ErrNotAuthorized
}
if err = json.Unmarshal([]byte(str), &session); err != nil {
return session, err
}
t, err := time.Parse(time.RFC3339, session["timestamp"])
if err != nil {
Log.Warning("middleware::session 'cannot parse time - %s'", err.Error())
return session, ErrNotAuthorized
} else if t.Add(24 * 365 * time.Hour).Before(time.Now()) {
Log.Warning("middleware::session 'cookie too old - %s'", t.Format(time.RFC3339))
return session, ErrNotAuthorized
}
return session, err
}
func _extractBackend(req *http.Request, ctx *App) (IBackend, error) {
return model.NewBackend(ctx, ctx.Session)
}
func _extractLanguages(req *http.Request) []string {
var lng = []string{}
for _, lngs := range strings.Split(req.Header.Get("Accept-Language"), ",") {
chunks := strings.Split(lngs, ";")
if len(chunks) == 0 {
continue
}
lng = append(lng, chunks[0])
}
return lng
}
+4 -1
View File
@@ -7,7 +7,10 @@ import (
"strconv"
"sync"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
var (
+1 -1
View File
@@ -1,7 +1,7 @@
package permissions
import (
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
)
func CanRead(ctx *App) bool {
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"net/url"
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/mickael-kerjean/filestash/server/pkg/token"
"github.com/mickael-kerjean/filestash/server/pkg/tracer"
)
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"strconv"
"time"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func (this Filestash) Ls(path string) ([]os.FileInfo, error) {
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"net/http"
"net/url"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/mickael-kerjean/filestash/server/pkg/tracer"
)
+3 -1
View File
@@ -4,7 +4,9 @@ import (
"encoding/json"
"time"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func (this *Filestash) NewToken(storage string, path string, formData map[string]string) error {
+3 -1
View File
@@ -6,7 +6,9 @@ import (
"io"
"net/http"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/mickael-kerjean/filestash/server/pkg/extension"
"github.com/mickael-kerjean/filestash/server/pkg/tracer"
+2 -1
View File
@@ -5,7 +5,8 @@ import (
"time"
"encoding/json"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/mickael-kerjean/filestash/server/pkg/env"
)
+9 -6
View File
@@ -11,11 +11,14 @@ import (
"strings"
"time"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
"github.com/mickael-kerjean/filestash/server/pkg/cookie"
"github.com/mickael-kerjean/filestash/server/pkg/files"
"github.com/mickael-kerjean/filestash/server/pkg/env"
"github.com/mickael-kerjean/filestash/server/pkg/token"
"github.com/gorilla/mux"
@@ -96,7 +99,7 @@ func SessionAuthenticate(ctx *App, res http.ResponseWriter, req *http.Request) {
SendErrorResult(res, NewError(err.Error(), 500))
return
}
obfuscate, err := EncryptString(env.SECRET_KEY_DERIVATE_FOR_USER, string(s))
obfuscate, err := EncryptString(SECRET_KEY_DERIVATE_FOR_USER, string(s))
if err != nil {
Log.Debug("[auth] action=authenticate::encrypt err=%s", ferror(err))
SendErrorResult(res, NewError(err.Error(), 500))
@@ -343,9 +346,9 @@ func SessionAuthMiddleware(ctx *App, res http.ResponseWriter, req *http.Request)
}
}
if attributes = strings.TrimSpace(attributes); attributes != "" {
v, err := DecryptString(env.SECRET_KEY_DERIVATE_FOR_SIGNATURE, signature)
v, err := DecryptString(SECRET_KEY_DERIVATE_FOR_SIGNATURE, signature)
if err != nil || attributes != v {
v, _ = EncryptString(env.SECRET_KEY_DERIVATE_FOR_SIGNATURE, attributes)
v, _ = EncryptString(SECRET_KEY_DERIVATE_FOR_SIGNATURE, attributes)
Log.Debug("callback signature is required, signature=%s", v)
http.Redirect(
res, req,
@@ -427,7 +430,7 @@ func SessionAuthMiddleware(ctx *App, res http.ResponseWriter, req *http.Request)
SendErrorResult(res, ErrNotValid)
return
}
obfuscate, err := EncryptString(env.SECRET_KEY_DERIVATE_FOR_USER, string(s))
obfuscate, err := EncryptString(SECRET_KEY_DERIVATE_FOR_USER, string(s))
if err != nil {
Log.Debug("session::authMiddleware 'encryption error - %s", err.Error())
SendErrorResult(res, ErrNotValid)
+7 -5
View File
@@ -4,9 +4,11 @@ import (
"net/http"
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/files"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/mickael-kerjean/filestash/server/model"
"github.com/mickael-kerjean/filestash/server/pkg/share"
"github.com/mickael-kerjean/filestash/server/pkg/token"
)
@@ -28,7 +30,7 @@ func Start(fn HandlerFunc) HandlerFunc {
SendErrorResult(res, err)
return
}
ctx.Authorization = token.Extract(req)
ctx.Authorization = token.From(req)
if ctx.Session, err = FromRequest(req, ctx); err != nil {
share.RecoverFromBadCookie(res)
SendErrorResult(res, err)
@@ -51,7 +53,7 @@ func Start(fn HandlerFunc) HandlerFunc {
func Try(fn HandlerFunc) HandlerFunc {
return HandlerFunc(func(ctx *App, res http.ResponseWriter, req *http.Request) {
ctx.Share, _ = share.FromRequest(req)
ctx.Authorization = token.Extract(req)
ctx.Authorization = token.From(req)
ctx.Session, _ = FromRequest(req, ctx)
ctx.Backend, _ = _extractBackend(req, ctx)
@@ -60,7 +62,7 @@ func Try(fn HandlerFunc) HandlerFunc {
}
func _extractBackend(req *http.Request, ctx *App) (IBackend, error) {
return model.NewBackend(ctx, ctx.Session)
return NewBackend(ctx, ctx.Session)
}
func _extractLanguages(req *http.Request) []string {
+9 -7
View File
@@ -7,7 +7,9 @@ import (
"bytes"
"regexp"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/mickael-kerjean/filestash/server/pkg/env"
"github.com/gorilla/mux"
@@ -24,15 +26,15 @@ func FromRequest(req *http.Request) (Share, error) {
return Share{}, NewError("Feature isn't enabled, contact your administrator", 405)
}
s, err := Get(share_id)
s, err := ShareGet(share_id)
if err != nil {
return Share{}, nil
}
if err = IsValid(s); err != nil {
if err = ShareIsValid(s); err != nil {
return Share{}, err
}
verifiedProof := Verified(req)
verifiedProof := ShareVerified(req)
username, password := func(authHeader string) (string, string) {
decoded, err := base64.StdEncoding.DecodeString(
strings.TrimPrefix(authHeader, "Basic "),
@@ -55,16 +57,16 @@ func FromRequest(req *http.Request) (Share, error) {
return usr[1], p
}(req.Header.Get("Authorization"))
if s.Users != nil && username != "" {
if v, ok := VerifyEmail(*s.Users, username); ok {
if v, ok := ShareVerifyEmail(*s.Users, username); ok {
verifiedProof = append(verifiedProof, Proof{Key: "email", Value: v})
}
}
if s.Password != nil && password != "" {
if v, ok := VerifyPassword(*s.Password, password); ok {
if v, ok := ShareVerifyPassword(*s.Password, password); ok {
verifiedProof = append(verifiedProof, Proof{Key: "password", Value: v})
}
}
if remainingProof := Remainings(Required(s), verifiedProof); len(remainingProof) != 0 {
if remainingProof := ShareRemainings(ShareRequired(s), verifiedProof); len(remainingProof) != 0 {
return Share{}, NewError("Unauthorized Shared space", 400)
}
return s, nil
+17 -15
View File
@@ -6,9 +6,11 @@ import (
"net/http"
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/mickael-kerjean/filestash/server/pkg/token"
"github.com/mickael-kerjean/filestash/server/pkg/env"
"github.com/gorilla/mux"
)
@@ -19,7 +21,7 @@ func ShareListHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
SendErrorResult(res, err)
return
}
listOfSharedLinks, err := List(
listOfSharedLinks, err := ShareList(
GenerateID(ctx.Session),
path,
)
@@ -31,7 +33,7 @@ func ShareListHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
for i := 0; i < len(listOfSharedLinks); i++ {
listOfSharedLinks[i].Path = "/" + strings.TrimPrefix(listOfSharedLinks[i].Path, path)
listOfSharedLinks[i] = Redact(listOfSharedLinks[i])
listOfSharedLinks[i] = ShareRedact(listOfSharedLinks[i])
}
SendSuccessResults(res, listOfSharedLinks)
}
@@ -47,7 +49,7 @@ func ShareUpsertHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
Id: share_id,
Auth: func() string {
if ctx.Share.Id == "" {
return token.Extract(req)
return token.From(req)
}
return ctx.Share.Auth
}(),
@@ -79,7 +81,7 @@ func ShareUpsertHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
CanWrite: NewBoolFromInterface(ctx.Body["can_write"]),
CanUpload: NewBoolFromInterface(ctx.Body["can_upload"]),
}
if err := Upsert(&s); err != nil {
if err := ShareUpsert(&s); err != nil {
Log.Debug("share::upsert '%s'", err.Error())
SendErrorResult(res, err)
return
@@ -89,7 +91,7 @@ func ShareUpsertHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
func ShareDeleteHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
share_target := mux.Vars(req)["share"]
if err := Delete(share_target); err != nil {
if err := ShareDelete(share_target); err != nil {
Log.Debug("share::delete '%s'", err.Error())
SendErrorResult(res, err)
return
@@ -107,7 +109,7 @@ func ShareVerifyProofHandler(ctx *App, res http.ResponseWriter, req *http.Reques
// 1) initialise the current context
share_id := mux.Vars(req)["share"]
s, err = Get(share_id)
s, err = ShareGet(share_id)
if err != nil {
Log.Debug("share::verify::init '%s'", err.Error())
SendErrorResult(res, err)
@@ -117,13 +119,13 @@ func ShareVerifyProofHandler(ctx *App, res http.ResponseWriter, req *http.Reques
Key: fmt.Sprint(ctx.Body["type"]),
Value: fmt.Sprint(ctx.Body["value"]),
}
verifiedProof = Verified(req)
requiredProof = Required(s)
verifiedProof = ShareVerified(req)
requiredProof = ShareRequired(s)
// 2) validate the current context
if len(verifiedProof) > 20 || len(requiredProof) > 20 {
http.SetCookie(res, &http.Cookie{
Name: env.COOKIE_NAME_PROOF,
Name: COOKIE_NAME_PROOF,
Value: "",
MaxAge: -1,
Path: COOKIE_PATH,
@@ -132,14 +134,14 @@ func ShareVerifyProofHandler(ctx *App, res http.ResponseWriter, req *http.Reques
SendErrorResult(res, ErrNotValid)
return
}
if err := IsValid(s); err != nil {
if err := ShareIsValid(s); err != nil {
Log.Debug("share::verify::validate '%s'", err.Error())
SendErrorResult(res, err)
return
}
// 3) process the proof sent by the user
submittedProof, err = Verify(s, submittedProof)
submittedProof, err = ShareVerify(s, submittedProof)
if err != nil {
Log.Debug("share::verify::process '%s'", err.Error())
submittedProof.Error = NewString(err.Error())
@@ -168,14 +170,14 @@ func ShareVerifyProofHandler(ctx *App, res http.ResponseWriter, req *http.Reques
}
// 4) Find remaining proofs: requiredProof - verifiedProof
remainingProof = Remainings(requiredProof, verifiedProof)
remainingProof = ShareRemainings(requiredProof, verifiedProof)
// 5) persist proofs in client cookie
cookie := http.Cookie{
Name: COOKIE_NAME_PROOF,
Value: func(p []Proof) string {
j, _ := json.Marshal(p)
str, _ := EncryptString(env.SECRET_KEY_DERIVATE_FOR_PROOF, string(j))
str, _ := EncryptString(SECRET_KEY_DERIVATE_FOR_PROOF, string(j))
return str
}(verifiedProof),
Path: COOKIE_PATH,
+6 -5
View File
@@ -3,8 +3,9 @@ package share
import (
"net/http"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/mickael-kerjean/filestash/server/pkg/token"
"github.com/gorilla/mux"
@@ -21,7 +22,7 @@ func CanManageShare(sessionStart Middleware, extractSession func(*http.Request,
}
// anyone can manage a share_id that's not been attributed yet
s, err := Get(share_id)
s, err := ShareGet(share_id)
if err != nil {
if err == ErrNotFound {
sessionStart(fn)(ctx, res, req)
@@ -36,7 +37,7 @@ func CanManageShare(sessionStart Middleware, extractSession func(*http.Request,
// the user that's currently logged in can manage the link. 2 scenarios here:
// 1) scenario 1: the user is the very same one that generated the shared link in the first place
ctx.Share = Share{}
ctx.Authorization = token.Extract(req)
ctx.Authorization = token.From(req)
if ctx.Session, err = extractSession(req, ctx); err != nil {
Log.Debug("share::middleware 'cannot extract session - %s'", err.Error())
SendErrorResult(res, err)
@@ -53,7 +54,7 @@ func CanManageShare(sessionStart Middleware, extractSession func(*http.Request,
SendErrorResult(res, err)
return
}
ctx.Authorization = token.Extract(req)
ctx.Authorization = token.From(req)
if ctx.Session, err = extractSession(req, ctx); err != nil {
Log.Debug("share::middleware 'cannot extract session 2 - %s'", err.Error())
SendErrorResult(res, err)
+19 -17
View File
@@ -12,7 +12,9 @@ import (
"strings"
"time"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/mickael-kerjean/filestash/server/pkg/sqlite"
"github.com/mickael-kerjean/filestash/server/pkg/env"
@@ -25,7 +27,7 @@ var tmplEmailVerification string
const PASSWORD_DUMMY = "{{PASSWORD}}"
func Redact(s Share) Share {
func ShareRedact(s Share) Share {
s.Auth = ""
if s.Password != nil {
dummy := PASSWORD_DUMMY
@@ -34,7 +36,7 @@ func Redact(s Share) Share {
return s
}
func IsValid(s Share) error {
func ShareIsValid(s Share) error {
if s.Expire != nil {
now := time.Now().UnixNano() / 1000000
if now > *s.Expire {
@@ -44,7 +46,7 @@ func IsValid(s Share) error {
return nil
}
func List(backend string, path string) ([]Share, error) {
func ShareList(backend string, path string) ([]Share, error) {
stmt, err := sqlite.DB.Prepare("SELECT id, related_path, params FROM Share WHERE related_backend = ? AND related_path LIKE ? || '%' ")
if err != nil {
return nil, err
@@ -65,7 +67,7 @@ func List(backend string, path string) ([]Share, error) {
return sharedFiles, nil
}
func All() ([]Share, error) {
func ShareAll() ([]Share, error) {
rows, err := sqlite.DB.Query("SELECT id, related_path, params FROM Share")
if err != nil {
return nil, err
@@ -82,7 +84,7 @@ func All() ([]Share, error) {
return sharedFiles, nil
}
func Get(id string) (Share, error) {
func ShareGet(id string) (Share, error) {
var p Share
stmt, err := sqlite.DB.Prepare("SELECT id, related_backend, related_path, auth, params FROM share WHERE id = ?")
if err != nil {
@@ -101,10 +103,10 @@ func Get(id string) (Share, error) {
return p, nil
}
func Upsert(p *Share) error {
func ShareUpsert(p *Share) error {
if p.Password != nil {
if *p.Password == PASSWORD_DUMMY {
if s, err := Get(p.Id); err == nil {
if s, err := ShareGet(p.Id); err == nil {
p.Password = s.Password
}
} else {
@@ -157,7 +159,7 @@ func Upsert(p *Share) error {
return err
}
func Delete(id string) error {
func ShareDelete(id string) error {
stmt, err := sqlite.DB.Prepare("DELETE FROM Share WHERE id = ?")
if err != nil {
return err
@@ -166,7 +168,7 @@ func Delete(id string) error {
return err
}
func Verify(s Share, proof Proof) (Proof, error) {
func ShareVerify(s Share, proof Proof) (Proof, error) {
p := proof
if proof.Key == "password" {
@@ -174,7 +176,7 @@ func Verify(s Share, proof Proof) (Proof, error) {
return p, NewError("No password required", 400)
}
v, ok := VerifyPassword(*s.Password, proof.Value)
v, ok := ShareVerifyPassword(*s.Password, proof.Value)
if ok == false {
time.Sleep(1000 * time.Millisecond)
return p, ErrInvalidPassword
@@ -187,7 +189,7 @@ func Verify(s Share, proof Proof) (Proof, error) {
if s.Users == nil {
return p, NewError("Authentication not required", 400)
}
v, ok := VerifyEmail(*s.Users, proof.Value)
v, ok := ShareVerifyEmail(*s.Users, proof.Value)
if ok == false {
time.Sleep(1000 * time.Millisecond)
return p, ErrNotAuthorized
@@ -282,14 +284,14 @@ func Verify(s Share, proof Proof) (Proof, error) {
return p, nil
}
func VerifyPassword(hashed string, given string) (string, bool) {
func ShareVerifyPassword(hashed string, given string) (string, bool) {
if err := bcrypt.CompareHashAndPassword([]byte(hashed), []byte(given)); err != nil {
return "", false
}
return hashed, true
}
func VerifyEmail(users string, wanted string) (string, bool) {
func ShareVerifyEmail(users string, wanted string) (string, bool) {
s := strings.Split(users, ",")
user := ""
for _, possibleUser := range s {
@@ -311,7 +313,7 @@ func VerifyEmail(users string, wanted string) (string, bool) {
return user, true
}
func Verified(req *http.Request) []Proof {
func ShareVerified(req *http.Request) []Proof {
var p []Proof
var cookieValue string
@@ -331,7 +333,7 @@ func Verified(req *http.Request) []Proof {
return p
}
func Required(s Share) []Proof {
func ShareRequired(s Share) []Proof {
var p []Proof
if s.Password != nil {
p = append(p, Proof{Key: "password", Value: *s.Password})
@@ -342,7 +344,7 @@ func Required(s Share) []Proof {
return p
}
func Remainings(ref []Proof, mem []Proof) []Proof {
func ShareRemainings(ref []Proof, mem []Proof) []Proof {
var remainingProof []Proof
for i := 0; i < len(ref); i++ {
+3 -1
View File
@@ -5,7 +5,9 @@ import (
"path/filepath"
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/mickael-kerjean/filestash/server/pkg/permissions"
"github.com/mickael-kerjean/net/webdav"
+3 -1
View File
@@ -17,7 +17,9 @@ import (
"strings"
"time"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/mickael-kerjean/net/webdav"
)
+3 -1
View File
@@ -4,7 +4,9 @@ import (
"database/sql"
"time"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
var DB *sql.DB
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"crypto/tls"
"crypto/x509"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func GenerateSelfSigned() (tls.Certificate, *x509.CertPool, error) {
+2 -1
View File
@@ -1,7 +1,8 @@
package ssl
import (
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
var (
+1 -1
View File
@@ -11,7 +11,7 @@ import (
"regexp"
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func Office(r io.ReadCloser) (io.ReadCloser, error) {
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"os"
"os/exec"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func PDF(r io.ReadCloser) (io.ReadCloser, error) {
+5 -4
View File
@@ -4,13 +4,14 @@ import (
"net/http"
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
"github.com/mickael-kerjean/filestash/server/pkg/cookie"
)
func Extract(req *http.Request) string {
func From(req *http.Request) string {
// strategy 1: split cookie
token := ExtractFromCookies(req.Cookies())
token := FromCookies(req.Cookies())
if token != "" {
return token
}
@@ -26,7 +27,7 @@ func Extract(req *http.Request) string {
return ""
}
func ExtractFromCookies(cookies []*http.Cookie) string {
func FromCookies(cookies []*http.Cookie) string {
var (
token strings.Builder
index int
+3 -1
View File
@@ -1,7 +1,9 @@
package workflow
import (
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
_ "github.com/mickael-kerjean/filestash/server/pkg/workflow/actions"
. "github.com/mickael-kerjean/filestash/server/pkg/workflow/model"
+3 -1
View File
@@ -3,7 +3,9 @@ package actions
import (
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
"gopkg.in/gomail.v2"
)
+3 -1
View File
@@ -9,7 +9,9 @@ import (
"strconv"
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func init() {
+3 -1
View File
@@ -1,7 +1,9 @@
package actions
import (
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func init() {
+1 -1
View File
@@ -1,7 +1,7 @@
package actions
import (
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
)
func Render(templateText string, variables map[string]string) string {
+3 -1
View File
@@ -1,7 +1,9 @@
package workflow
import (
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
)
func init() {
+3 -1
View File
@@ -4,7 +4,9 @@ import (
"encoding/json"
"net/http"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/workflow/model"
"github.com/gorilla/mux"
+3 -1
View File
@@ -3,7 +3,9 @@ package workflow
import (
"time"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/workflow/model"
)
+1 -1
View File
@@ -1,7 +1,7 @@
package model
import (
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
)
type StepDefinition struct {
+3 -2
View File
@@ -3,13 +3,14 @@ package model
import (
"database/sql"
"github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/filestash/server/pkg/env"
"github.com/mickael-kerjean/filestash/server/pkg/utils"
)
var db *sql.DB
func InitState() (err error) {
db, err = sql.Open("sqlite3", common.GetAbsolutePath(common.DB_PATH, "workflow.sql"))
db, err = sql.Open("sqlite3", utils.GetAbsolutePath(env.DB_PATH, "workflow.sql"))
if err != nil {
return err
}
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"database/sql"
"encoding/json"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
type Job struct {
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"database/sql"
"encoding/json"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
type Workflow struct {
+3 -1
View File
@@ -3,7 +3,9 @@ package trigger
import (
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/workflow/model"
)
+7 -5
View File
@@ -7,9 +7,11 @@ import (
"sync"
"time"
. "github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/filestash/server/model"
"github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/files"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/workflow/model"
)
@@ -109,14 +111,14 @@ func filewatchCallback(workflow Workflow) (map[string]string, bool) {
func createBackend(token string) (IBackend, map[string]string, error) {
session := map[string]string{}
str, err := DecryptString(env.SECRET_KEY_DERIVATE_FOR_USER, token)
str, err := DecryptString(SECRET_KEY_DERIVATE_FOR_USER, token)
if err != nil {
return nil, session, err
}
if err = json.Unmarshal([]byte(str), &session); err != nil {
return nil, session, err
}
backend, err := model.NewBackend(
backend, err := NewBackend(
&App{Context: context.Background()},
session,
)
+2 -1
View File
@@ -4,7 +4,8 @@ import (
"encoding/json"
"net/http"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/workflow/model"
)
+3 -1
View File
@@ -5,7 +5,9 @@ import (
"strings"
"time"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/pkg/workflow/model"
)
+3 -1
View File
@@ -6,7 +6,9 @@ import (
"net/http"
"strings"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/workflow/model"
"github.com/gorilla/mux"
+7 -6
View File
@@ -7,9 +7,10 @@ import (
"net/http"
"time"
. "github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/filestash/server/pkg/env"
"github.com/mickael-kerjean/filestash/server/model"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/pkg/files"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/plugin/plg_handler_mcp/impl"
. "github.com/mickael-kerjean/filestash/server/plugin/plg_handler_mcp/types"
. "github.com/mickael-kerjean/filestash/server/plugin/plg_handler_mcp/utils"
@@ -56,7 +57,7 @@ func (this *Server) sseHandler(_ *App, w http.ResponseWriter, r *http.Request) {
userSession := this.GetSession(uuid.New().String())
userSession.Token = token
if b, err := getBackend(userSession.Token); err == nil {
userSession.HomeDir, _ = model.GetHome(b, "/")
userSession.HomeDir, _ = GetHome(b, "/")
userSession.CurrDir = ToString(userSession.HomeDir, "/")
}
@@ -226,7 +227,7 @@ func (this *Server) sseHandler(_ *App, w http.ResponseWriter, r *http.Request) {
}
func getBackend(token string) (IBackend, error) {
str, err := DecryptString(env.SECRET_KEY_DERIVATE_FOR_USER, token)
str, err := DecryptString(SECRET_KEY_DERIVATE_FOR_USER, token)
if err != nil {
return nil, ErrNotAuthorized
}
@@ -234,7 +235,7 @@ func getBackend(token string) (IBackend, error) {
if err = json.Unmarshal([]byte(str), &session); err != nil {
return nil, err
}
return model.NewBackend(&App{
return NewBackend(&App{
Context: context.Background(),
}, session)
}
+1 -2
View File
@@ -8,7 +8,6 @@ import (
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/middleware"
"github.com/mickael-kerjean/filestash/server/model"
"github.com/mickael-kerjean/filestash/server/pkg/permissions"
"github.com/gorilla/mux"
@@ -83,7 +82,7 @@ func SiteHandler(app *App, w http.ResponseWriter, r *http.Request) {
}
func SharesListHandler(app *App, w http.ResponseWriter, r *http.Request) {
shares, err := model.ShareAll()
shares, err := ShareAll()
if err != nil {
SendErrorResult(w, err)
return