[server][core] Rename some more files

This commit is contained in:
Abhishek Shroff
2025-06-06 00:53:26 +05:30
parent 3fa962b5d0
commit 1a2532dcd7
8 changed files with 61 additions and 56 deletions
@@ -4,12 +4,11 @@ import (
"crypto/sha256"
"hash"
"io"
"strings"
"github.com/gabriel-vasile/mimetype"
)
type contentPropsComputer struct {
type contentProps struct {
dest io.WriteCloser
len int
sum hash.Hash
@@ -17,8 +16,8 @@ type contentPropsComputer struct {
successCallback func(int, hash.Hash, string) error
}
func computeProps(dest io.WriteCloser, successCallback func(int, hash.Hash, string) error) *contentPropsComputer {
return &contentPropsComputer{
func computeProps(dest io.WriteCloser, successCallback func(int, hash.Hash, string) error) io.WriteCloser {
return &contentProps{
dest: dest,
sum: sha256.New(),
contents: make([]byte, 0, 3072),
@@ -26,7 +25,7 @@ func computeProps(dest io.WriteCloser, successCallback func(int, hash.Hash, stri
}
}
func (c *contentPropsComputer) Write(p []byte) (n int, err error) {
func (c *contentProps) Write(p []byte) (n int, err error) {
n, err = c.dest.Write(p)
c.len += n
if c.sum != nil {
@@ -47,15 +46,9 @@ func min(a, b int) int {
}
func (c *contentPropsComputer) Close() error {
func (c *contentProps) Close() error {
if err := c.dest.Close(); err != nil {
return err
}
return c.successCallback(c.len, c.sum, mimetype.Detect(c.contents).String())
}
func CheckResourceNameInvalid(s string) bool {
return s == "" || s == "." || s == ".." || strings.ContainsFunc(s, func(r rune) bool {
return r == 0 || r == '/'
})
}
+2 -2
View File
@@ -49,10 +49,10 @@ type FileSystem interface {
Copy(r Resource, target string, id uuid.UUID, recursive bool, conflictResolution ResourceBindConflictResolution) (Resource, bool, error)
Move(r Resource, target string, conflictResolution ResourceBindConflictResolution) (Resource, bool, error)
// permissions.go
// resource_permissions.go
UpdatePermissions(r Resource, user User, permission Permission) (Resource, error)
//publink.go
// resource_publink.go
CreatePublink(r Resource, id, password string, expires pgtype.Timestamp, accessLimit int) error
ListPublinks(r Resource) ([]Publink, error)
-42
View File
@@ -1,13 +1,10 @@
package core
import (
"strings"
"time"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"github.com/shroff/phylum/server/internal/crypt"
)
type Publink struct {
@@ -39,42 +36,3 @@ func scanPublink(row pgx.CollectableRow) (Publink, error) {
}
return p, nil
}
func (f filesystem) CreatePublink(r Resource, id, password string, expires pgtype.Timestamp, accessLimit int) error {
if !r.hasPermission(PermissionShare | PermissionRead) {
return ErrInsufficientPermissions
}
if r.deleted.Valid {
return ErrResourceDeleted
}
passwordHash := ""
if password != "" {
hash, err := crypt.Generate(password)
if err != nil {
return err
}
passwordHash = hash
}
const q = `INSERT INTO publinks(id, root, password_hash, expires, access_limit) VALUES
($1::text, $2::uuid, $3::text, $4::timestamp, $5::int)`
_, err := f.db.Exec(q, id, r.ID(), passwordHash, expires, accessLimit)
if err != nil && strings.Contains(err.Error(), "publinks_pkey") {
return ErrPublinkNameConflict
}
return err
}
func (f filesystem) ListPublinks(r Resource) ([]Publink, error) {
const q = "SELECT * FROM publinks WHERE root = $1::UUID"
if rows, err := f.db.Query(q, r.id); err != nil {
return nil, err
} else if links, err := pgx.CollectRows(rows, scanPublink); err != nil {
return nil, err
} else {
return links, nil
}
}
+6
View File
@@ -22,6 +22,12 @@ const (
ResourceBindConflictResolutionDelete = ResourceBindConflictResolution(4) // Delete existing resource before creating
)
func CheckResourceNameInvalid(s string) bool {
return s == "" || s == "." || s == ".." || strings.ContainsFunc(s, func(r rune) bool {
return r == 0 || r == '/'
})
}
func (f filesystem) CreateResourceByPath(path string, id uuid.UUID, dir, createParents bool, conflictResolution ResourceBindConflictResolution) (Resource, error) {
if id == uuid.Nil {
id, _ = uuid.NewV7()
+48
View File
@@ -0,0 +1,48 @@
package core
import (
"strings"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"github.com/shroff/phylum/server/internal/crypt"
)
func (f filesystem) CreatePublink(r Resource, id, password string, expires pgtype.Timestamp, accessLimit int) error {
if !r.hasPermission(PermissionShare | PermissionRead) {
return ErrInsufficientPermissions
}
if r.deleted.Valid {
return ErrResourceDeleted
}
passwordHash := ""
if password != "" {
hash, err := crypt.Generate(password)
if err != nil {
return err
}
passwordHash = hash
}
const q = `INSERT INTO publinks(id, root, password_hash, expires, access_limit) VALUES
($1::text, $2::uuid, $3::text, $4::timestamp, $5::int)`
_, err := f.db.Exec(q, id, r.ID(), passwordHash, expires, accessLimit)
if err != nil && strings.Contains(err.Error(), "publinks_pkey") {
return ErrPublinkNameConflict
}
return err
}
func (f filesystem) ListPublinks(r Resource) ([]Publink, error) {
const q = "SELECT * FROM publinks WHERE root = $1::UUID"
if rows, err := f.db.Query(q, r.id); err != nil {
return nil, err
} else if links, err := pgx.CollectRows(rows, scanPublink); err != nil {
return nil, err
} else {
return links, nil
}
}