chore (refactoring): cleanup pkg imports

This commit is contained in:
MickaelK
2026-08-21 12:06:30 +10:00
committed by mickael-kerjean
parent 5b290772fb
commit c3da0bcea9
26 changed files with 50 additions and 112 deletions
+1
View File
@@ -137,6 +137,7 @@ var (
SendSuccessResult = kernel.SendSuccessResult
SendSuccessResults = kernel.SendSuccessResults
SendSuccessResultWithEtagAndGzip = kernel.SendSuccessResultWithEtagAndGzip
SendSuccessResultsWithMetadata = kernel.SendSuccessResultsWithMetadata
SendErrorResult = kernel.SendErrorResult
Page = kernel.Page
RedirectPage = kernel.RedirectPage
+1 -3
View File
@@ -1,9 +1,7 @@
package files
import (
. "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/common"
)
func init() {
+1 -3
View File
@@ -4,10 +4,8 @@ import (
"net/http"
"strings"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func FileAccess(ctx *App, res http.ResponseWriter, req *http.Request) {
+1 -6
View File
@@ -10,13 +10,8 @@ import (
"strconv"
"strings"
. "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/common"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
var file_cache AppCache
+1 -3
View File
@@ -11,10 +11,8 @@ import (
"strings"
"time"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func FileExtract(ctx *App, res http.ResponseWriter, req *http.Request) {
+1 -3
View File
@@ -10,10 +10,8 @@ import (
"strconv"
"time"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
type FileInfo struct {
+1 -3
View File
@@ -5,9 +5,7 @@ import (
"fmt"
"net/http"
. "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/common"
)
func MetaGet(ctx *App, w http.ResponseWriter, r *http.Request) {
+1 -3
View File
@@ -3,10 +3,8 @@ package files
import (
"net/http"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func FileMkdir(ctx *App, res http.ResponseWriter, req *http.Request) {
+1 -3
View File
@@ -3,10 +3,8 @@ package files
import (
"net/http"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func FileMv(ctx *App, res http.ResponseWriter, req *http.Request) {
+1 -3
View File
@@ -3,10 +3,8 @@ package files
import (
"net/http"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func FileRm(ctx *App, res http.ResponseWriter, req *http.Request) {
+1 -3
View File
@@ -16,10 +16,8 @@ import (
"strings"
"sync"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
var chunkedUploadCache AppCache
+1 -3
View File
@@ -4,10 +4,8 @@ import (
"net/http"
"strings"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func FileSearch(ctx *App, res http.ResponseWriter, req *http.Request) {
+1 -3
View File
@@ -3,10 +3,8 @@ package files
import (
"net/http"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func FileTouch(ctx *App, res http.ResponseWriter, req *http.Request) {
+1 -3
View File
@@ -9,10 +9,8 @@ import (
"strings"
"time"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/pkg/permissions"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func FileDownloader(ctx *App, res http.ResponseWriter, req *http.Request) {
+3 -5
View File
@@ -3,10 +3,8 @@ package files
import (
"strings"
. "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/common"
"github.com/mickael-kerjean/filestash/server/pkg/kernel"
)
func NewBackend(ctx *App, conn map[string]string) (IBackend, error) {
@@ -49,7 +47,7 @@ func NewBackend(ctx *App, conn map[string]string) (IBackend, error) {
}
if isAllowed() == false {
return Backend.Get(BACKEND_NIL), ErrNotAllowed
return Backend.Get(kernel.BACKEND_NIL), ErrNotAllowed
}
return Backend.Get(conn["type"]).Init(conn, ctx)
}
+1 -4
View File
@@ -8,11 +8,8 @@ import (
"strings"
"text/template"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/filestash/server/pkg/extension"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
)
func AboutHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
+1 -5
View File
@@ -7,12 +7,8 @@ import (
"path/filepath"
"strings"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/env"
. "github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/filestash/server/pkg/extension"
. "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/gorilla/mux"
)
+1 -5
View File
@@ -8,11 +8,7 @@ import (
"slices"
"strings"
. "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/utils"
. "github.com/mickael-kerjean/filestash/server/common"
)
func ReportHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
+1 -6
View File
@@ -20,13 +20,8 @@ import (
. "github.com/mickael-kerjean/filestash"
. "github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/filestash/server/pkg/compress"
. "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/bluekeyes/go-gitdiff/gitdiff"
)
+1 -5
View File
@@ -9,15 +9,11 @@ import (
"strings"
"time"
. "github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/filestash/server/model"
"github.com/mickael-kerjean/filestash/server/pkg/admin"
. "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/share"
"github.com/mickael-kerjean/filestash/server/pkg/token"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/gorilla/mux"
)
+10 -13
View File
@@ -11,15 +11,12 @@ import (
"strings"
"time"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/common"
. "github.com/mickael-kerjean/filestash/server/middleware"
"github.com/mickael-kerjean/filestash/server/pkg/cookie"
. "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/middleware"
"github.com/mickael-kerjean/filestash/server/pkg/files"
"github.com/mickael-kerjean/filestash/server/pkg/token"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/gorilla/mux"
)
@@ -39,7 +36,7 @@ func SessionGet(ctx *App, res http.ResponseWriter, req *http.Request) {
SendSuccessResult(res, r)
return
}
home, err := GetHome(ctx.Backend, ctx.Session["path"])
home, err := files.GetHome(ctx.Backend, ctx.Session["path"])
if err != nil {
SendSuccessResult(res, r)
return
@@ -60,7 +57,7 @@ func SessionAuthenticate(ctx *App, res http.ResponseWriter, req *http.Request) {
session := MapStringInterfaceToMapStringString(ctx.Body)
session["path"] = EnforceDirectory(session["path"])
backend, err := NewBackend(ctx, session)
backend, err := files.NewBackend(ctx, session)
if err != nil {
Log.Debug("[auth] action=authenticate::newBackend err=%s", ferror(err))
Log.Stdout("AUDIT action[fail] backend[%s] user[%s] target[%s]", session["type"], backendID(session), ip(req))
@@ -77,7 +74,7 @@ func SessionAuthenticate(ctx *App, res http.ResponseWriter, req *http.Request) {
return
}
session = MapStringInterfaceToMapStringString(ctx.Body)
backend, err = NewBackend(ctx, session)
backend, err = files.NewBackend(ctx, session)
if err != nil {
Log.Debug("[auth] action=authenticate::oauth::newBackend err=%s", ferror(err))
Log.Stdout("AUDIT action[fail] backend[%s] user[%s] target[%s]", session["type"], username(session), ip(req))
@@ -86,7 +83,7 @@ func SessionAuthenticate(ctx *App, res http.ResponseWriter, req *http.Request) {
}
}
home, err := GetHome(backend, session["path"])
home, err := files.GetHome(backend, session["path"])
if err != nil {
Log.Debug("[auth] action=authenticate::getHome err=%s", ferror(err))
SendErrorResult(res, ErrAuthenticationFailed)
@@ -156,7 +153,7 @@ func SessionOAuthBackend(ctx *App, res http.ResponseWriter, req *http.Request) {
a := map[string]string{
"type": vars["service"],
}
b, err := NewBackend(ctx, a)
b, err := files.NewBackend(ctx, a)
if err != nil {
Log.Debug("session::oauth 'NewBackend' %+v", err)
SendErrorResult(res, err)
@@ -412,7 +409,7 @@ func SessionAuthMiddleware(ctx *App, res http.ResponseWriter, req *http.Request)
return
}
if _, err := NewBackend(ctx, session); err != nil {
if _, err := files.NewBackend(ctx, session); err != nil {
Log.Debug("session::authMiddleware 'backend connection failed %s'", err.Error())
Log.Info("[auth] status=failed user=%s backend=%s::%s ip=%s err=%s", username(session), session["type"], backendID(session), ip(req), ferror(err))
url := "/?error=" + ErrNotValid.Error() + "&trace=backend error - " + err.Error()
+1 -4
View File
@@ -6,11 +6,8 @@ import (
"net/http"
"strings"
. "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/common"
"github.com/mickael-kerjean/filestash/server/pkg/token"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/gorilla/mux"
)
+14 -16
View File
@@ -10,18 +10,16 @@ import (
"strings"
"time"
. "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/sqlite"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
. "github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/filestash/server/pkg/sqlite"
"github.com/mickael-kerjean/filestash/server/pkg/utils"
"golang.org/x/crypto/bcrypt"
"gopkg.in/gomail.v2"
)
func ShareList(backend string, path string) ([]Share, error) {
stmt, err := DB.Prepare("SELECT id, related_path, params FROM Share WHERE related_backend = ? AND related_path LIKE ? || '%' ")
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
}
@@ -42,7 +40,7 @@ func ShareList(backend string, path string) ([]Share, error) {
}
func ShareAll() ([]Share, error) {
rows, err := DB.Query("SELECT id, related_path, params FROM Share")
rows, err := sqlite.DB.Query("SELECT id, related_path, params FROM Share")
if err != nil {
return nil, err
}
@@ -60,7 +58,7 @@ func ShareAll() ([]Share, error) {
func ShareGet(id string) (Share, error) {
var p Share
stmt, err := DB.Prepare("SELECT id, related_backend, related_path, auth, params FROM share WHERE id = ?")
stmt, err := sqlite.DB.Prepare("SELECT id, related_backend, related_path, auth, params FROM share WHERE id = ?")
if err != nil {
return p, err
}
@@ -79,7 +77,7 @@ func ShareGet(id string) (Share, error) {
func ShareUpsert(p *Share) error {
if p.Password != nil {
if *p.Password == PASSWORD_DUMMY {
if *p.Password == utils.PASSWORD_DUMMY {
if s, err := ShareGet(p.Id); err != nil {
p.Password = s.Password
}
@@ -89,14 +87,14 @@ func ShareUpsert(p *Share) error {
}
}
stmt, err := DB.Prepare("INSERT INTO Location(backend, path) VALUES($1, $2)")
stmt, err := sqlite.DB.Prepare("INSERT INTO Location(backend, path) VALUES($1, $2)")
if err != nil {
return err
}
_, err = stmt.Exec(p.Backend, p.Path)
if err != nil {
throw := true
if IsConstraint(err) {
if sqlite.IsConstraint(err) {
throw = false
}
if throw == true {
@@ -104,7 +102,7 @@ func ShareUpsert(p *Share) error {
}
}
stmt, err = DB.Prepare("INSERT INTO Share(id, related_backend, related_path, params, auth) VALUES($1, $2, $3, $4, $5) ON CONFLICT(id) DO UPDATE SET related_backend = $2, related_path = $3, params = $4")
stmt, err = sqlite.DB.Prepare("INSERT INTO Share(id, related_backend, related_path, params, auth) VALUES($1, $2, $3, $4, $5) ON CONFLICT(id) DO UPDATE SET related_backend = $2, related_path = $3, params = $4")
if err != nil {
return err
}
@@ -134,7 +132,7 @@ func ShareUpsert(p *Share) error {
}
func ShareDelete(id string) error {
stmt, err := DB.Prepare("DELETE FROM Share WHERE id = ?")
stmt, err := sqlite.DB.Prepare("DELETE FROM Share WHERE id = ?")
if err != nil {
return err
}
@@ -171,7 +169,7 @@ func ShareProofVerifier(s Share, proof Proof) (Proof, error) {
user := v
// prepare the verification code
stmt, err := DB.Prepare("INSERT INTO Verification(key, code) VALUES(?, ?)")
stmt, err := sqlite.DB.Prepare("INSERT INTO Verification(key, code) VALUES(?, ?)")
if err != nil {
return p, err
}
@@ -225,7 +223,7 @@ func ShareProofVerifier(s Share, proof Proof) (Proof, error) {
if proof.Key == "code" {
// find key for given code
stmt, err := DB.Prepare("SELECT key FROM Verification WHERE code = ? AND expire > datetime('now')")
stmt, err := sqlite.DB.Prepare("SELECT key FROM Verification WHERE code = ? AND expire > datetime('now')")
if err != nil {
return p, NewError("Not found", 404)
}
@@ -244,7 +242,7 @@ func ShareProofVerifier(s Share, proof Proof) (Proof, error) {
stmt.Close()
// cleanup current attempt so that it isn't used for malicious purpose
if stmt, err = DB.Prepare("DELETE FROM Verification WHERE code = ?"); err == nil {
if stmt, err = sqlite.DB.Prepare("DELETE FROM Verification WHERE code = ?"); err == nil {
stmt.Exec(proof.Value)
stmt.Close()
}
+1 -3
View File
@@ -5,10 +5,8 @@ import (
"path/filepath"
"strings"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
. "github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/filestash/server/pkg/permissions"
. "github.com/mickael-kerjean/filestash/server/pkg/utils"
"github.com/mickael-kerjean/net/webdav"
)
+1 -4
View File
@@ -17,10 +17,7 @@ import (
"strings"
"time"
. "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/filestash/server/common"
"github.com/mickael-kerjean/net/webdav"
)
+1
View File
@@ -2,6 +2,7 @@ package workflow
import (
. "github.com/mickael-kerjean/filestash/server/common"
_ "github.com/mickael-kerjean/filestash/server/pkg/workflow/actions"
. "github.com/mickael-kerjean/filestash/server/pkg/workflow/model"
)