mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-05-12 15:18:38 -05:00
[server][core] Get rid of ResourceInfo.Path
This commit is contained in:
@@ -27,7 +27,6 @@ var ErrRangeNotSupported = errors.New("byte range not suppoered")
|
||||
|
||||
type ResourceInfo interface {
|
||||
Name() string
|
||||
Path() string
|
||||
Dir() bool
|
||||
Created() time.Time
|
||||
Modified() time.Time
|
||||
@@ -81,12 +80,12 @@ func serveCollection(w http.ResponseWriter, r *http.Request, file Resource) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
fmt.Fprintln(w, "<html>")
|
||||
fmt.Fprintln(w, "<head>")
|
||||
fmt.Fprintf(w, "<title>%s | Phylum</title>\n", file.Path())
|
||||
fmt.Fprintf(w, "<title>%s | Phylum</title>\n", file.Name())
|
||||
fmt.Fprintln(w, "<style>td, th {padding: 4px 12px;}</style>")
|
||||
fmt.Fprintln(w, "</head>")
|
||||
fmt.Fprintln(w, "<body>")
|
||||
fmt.Fprintln(w, "<pre>")
|
||||
fmt.Fprintf(w, "<h2>Index of %s</h2>", file.Path())
|
||||
fmt.Fprintf(w, "<h2>Index of %s</h2>", file.Name())
|
||||
fmt.Fprintln(w, "<table>")
|
||||
fmt.Fprintln(w, "<thead><tr><th>Name</th><th>Size</th><th>Content-Type</th><th>SHA-256</th></tr></thead>")
|
||||
fmt.Fprintln(w, "<tbody>")
|
||||
|
||||
@@ -3,8 +3,6 @@ package fs
|
||||
import (
|
||||
"archive/zip"
|
||||
"io"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
@@ -21,14 +19,13 @@ func handleDownloadRequest(c *gin.Context) {
|
||||
|
||||
f := auth.GetFileSystem(c)
|
||||
r, err := f.ResourceByID(resourceID)
|
||||
prefix := path.Dir(r.Path())
|
||||
|
||||
c.Writer.Header().Set("Content-Type", "application/zip")
|
||||
c.Writer.Header().Set("Content-Disposition", "attachment; filename=\""+r.Name()+".zip\"")
|
||||
|
||||
var zip = zip.NewWriter(c.Writer)
|
||||
close := c.Writer.CloseNotify()
|
||||
err = r.Walk(2, func(r serve.ResourceInfo) error {
|
||||
err = r.Walk(2, func(r serve.ResourceInfo, p string) error {
|
||||
if r.Dir() {
|
||||
return nil
|
||||
}
|
||||
@@ -39,11 +36,7 @@ func handleDownloadRequest(c *gin.Context) {
|
||||
default:
|
||||
}
|
||||
|
||||
path, found := strings.CutPrefix(r.Path(), prefix)
|
||||
if !found {
|
||||
return fs.ErrResourcePathInvalid
|
||||
}
|
||||
out, err := zip.Create(path)
|
||||
out, err := zip.Create(p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -449,7 +449,7 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) (status
|
||||
|
||||
mw := multistatusWriter{w: w}
|
||||
|
||||
writePropStat := func(r serve.ResourceInfo) error {
|
||||
writePropStat := func(r serve.ResourceInfo, p string) error {
|
||||
var pstats []Propstat
|
||||
if pf.Propname != nil {
|
||||
pnames, err := propnames(h.FileSystem, h.LockSystem, r)
|
||||
@@ -469,7 +469,7 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) (status
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
href := path.Join(h.Prefix, r.Path())
|
||||
href := path.Join(reqPath, p)
|
||||
if href != "/" && r.Dir() {
|
||||
href += "/"
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func setupLsCommand() *cobra.Command {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println(r.Path() + " " + fullPermissionsString(r))
|
||||
fmt.Println(r.Name() + " " + fullPermissionsString(r))
|
||||
fmt.Println(formatRow(r.ID().String(), formatSize(r.ContentLength()), r.ContentSHA256(), ".", permissionJsonString(r.Info.Permissions()), r.Info.Publinks()))
|
||||
|
||||
if r.Dir() {
|
||||
|
||||
@@ -183,11 +183,6 @@ func (r Resource) Copy(target string, id uuid.UUID, recursive bool, conflictReso
|
||||
}
|
||||
|
||||
info := ResourceInfoFromDBResource(root)
|
||||
if destParent.Path() == "/" {
|
||||
info.path = "/" + info.name
|
||||
} else {
|
||||
info.path = destParent.Path() + "/" + info.name
|
||||
}
|
||||
|
||||
ancestry := make([]ResourceInfo, len(destParent.Ancestors)+1)
|
||||
copy(ancestry, destParent.Ancestors)
|
||||
|
||||
@@ -85,11 +85,6 @@ func (r Resource) CreateMemberResource(name string, id uuid.UUID, dir bool, conf
|
||||
}
|
||||
|
||||
info := ResourceInfoFromDBResource(result)
|
||||
if r.Path() == "/" {
|
||||
info.path = "/" + info.name
|
||||
} else {
|
||||
info.path = r.Path() + "/" + info.name
|
||||
}
|
||||
ancestry := make([]ResourceInfo, len(r.Ancestors)+1)
|
||||
copy(ancestry, r.Ancestors)
|
||||
ancestry = append(ancestry, r.Info)
|
||||
|
||||
@@ -44,11 +44,6 @@ func (f filesystem) resourceFromResult(e []db.FullResource, err error) (Resource
|
||||
b.WriteString(e[i].Name)
|
||||
}
|
||||
info = resourceInfoFromDBPublinkedResource(e[i])
|
||||
if b.Len() == 0 {
|
||||
info.path = "/"
|
||||
} else {
|
||||
info.path = b.String()
|
||||
}
|
||||
if i != 0 {
|
||||
ancestry = append(ancestry, info)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"crypto/sha256"
|
||||
"io"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/shroff/phylum/server/internal/api/serve"
|
||||
"github.com/shroff/phylum/server/internal/core/db"
|
||||
)
|
||||
@@ -51,22 +50,19 @@ func (r Resource) ReadDir(recursive bool) ([]serve.ResourceInfo, error) {
|
||||
}
|
||||
|
||||
result := make([]serve.ResourceInfo, len(children))
|
||||
path := make(map[uuid.UUID]string)
|
||||
path[r.ID()] = r.Path()
|
||||
if r.Path() == "/" {
|
||||
path[r.ID()] = ""
|
||||
}
|
||||
for i, c := range children {
|
||||
info := resourceInfoFromDBPublinkedResource(c)
|
||||
info.path = path[*info.parentID] + "/" + info.name
|
||||
path[info.id] = info.path
|
||||
result[i] = info
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r Resource) Walk(depth int, fn func(serve.ResourceInfo) error) error {
|
||||
err := fn(r)
|
||||
func (r Resource) Walk(depth int, fn func(serve.ResourceInfo, string) error) error {
|
||||
suffix := ""
|
||||
if r.Dir() {
|
||||
suffix = "/"
|
||||
}
|
||||
err := fn(r, suffix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -80,7 +76,7 @@ func (r Resource) Walk(depth int, fn func(serve.ResourceInfo) error) error {
|
||||
}
|
||||
|
||||
for _, c := range children {
|
||||
if err := fn(c); err != nil {
|
||||
if err := fn(c, suffix+r.Name()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ type ResourceInfo struct {
|
||||
contentSHA256 string
|
||||
permissions []byte
|
||||
publinks []byte
|
||||
path string
|
||||
}
|
||||
|
||||
func (r Resource) ID() uuid.UUID { return r.Info.id }
|
||||
@@ -39,7 +38,6 @@ func (r Resource) Deleted() *time.Time { return r.Info.deleted }
|
||||
func (r Resource) ContentLength() int64 { return r.Info.contentLength }
|
||||
func (r Resource) ContentSHA256() string { return r.Info.contentSHA256 }
|
||||
func (r Resource) ContentType() string { return r.Info.contentType }
|
||||
func (r Resource) Path() string { return r.Info.path }
|
||||
|
||||
func (r Resource) hasPermission(p Permission) bool {
|
||||
return r.userPermission&p != 0
|
||||
@@ -57,4 +55,3 @@ func (r ResourceInfo) ContentSHA256() string { return r.contentSHA256 }
|
||||
func (r ResourceInfo) ContentType() string { return r.contentType }
|
||||
func (r ResourceInfo) Permissions() []byte { return r.permissions }
|
||||
func (r ResourceInfo) Publinks() []byte { return r.publinks }
|
||||
func (r ResourceInfo) Path() string { return r.path }
|
||||
|
||||
Reference in New Issue
Block a user