core

package
v0.0.0-...-80595d0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2025 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResourceBindConflictResolutionError     = ResourceBindConflictResolution(0) // Error if exists
	ResourceBindConflictResolutionEnsure    = ResourceBindConflictResolution(1) // Error if type mismatch
	ResourceBindConflictResolutionRename    = ResourceBindConflictResolution(2) // Auto rename new resource
	ResourceBindConflictResolutionOverwrite = ResourceBindConflictResolution(3) // Delete existing resource only if type mismatch (preserves props)
	ResourceBindConflictResolutionDelete    = ResourceBindConflictResolution(4) // Delete existing resource before creating
)
View Source
const (
	PermissionNone  = Permission(0)
	PermissionRead  = Permission(4)
	PermissionWrite = Permission(32)
	PermissionShare = Permission(128)
	PermissionSU    = Permission(-1)
)
View Source
const (
	PermissionUsersInvite = UserPermissions(0x10)
	PermissionUsersGrant  = UserPermissions(0x20)
	PermissionFilesAll    = UserPermissions(0x100)
)

Variables

View Source
var (
	ErrIDConflict                     = NewError(http.StatusConflict, "id_conflict", "ID conflict detected. A previous attempt may have succeeded")
	ErrInsufficientPermissions        = NewError(http.StatusForbidden, "insufficient_permissions", "Insufficient permissions")
	ErrInsufficientScope              = NewError(http.StatusForbidden, "insufficient_scope", "Insufficient scope")
	ErrPreviewNotFound                = NewError(http.StatusNotFound, "preview_not_found", "Unable to locate preview")
	ErrResourceNotFound               = NewError(http.StatusNotFound, "resource_not_found", "No such file or directory")
	ErrResourceNotCollection          = NewError(http.StatusMethodNotAllowed, "resource_not_collection", "Cannot add a member to a non-collection resource")
	ErrResourceCollection             = NewError(http.StatusMethodNotAllowed, "resource_collection", "Cannot write contents to a collection resource")
	ErrResourcePathInvalid            = NewError(http.StatusBadRequest, "resource_path_invalid", "Resource path is invalid")
	ErrResourceNameInvalid            = NewError(http.StatusBadRequest, "resource_name_invalid", "Resource name is invalid")
	ErrResourceNameConflict           = NewError(http.StatusPreconditionFailed, "resource_name_conflict", "Another resource with this name already exists")
	ErrResourceMoveTargetSubdirectory = NewError(http.StatusConflict, "move_target_subdirectory", "Cannot move a resource to its own subdirectory")
	ErrResourceCopyTargetSelf         = NewError(http.StatusConflict, "copy_target_self", "Cannot overwrite a resource with itself")
	ErrResourceDeleted                = NewError(http.StatusPreconditionFailed, "resource_deleted", "Resource is deleted")
	ErrParentNotFound                 = NewError(http.StatusConflict, "parent_not_found", "Parent not found")
	ErrParentDeleted                  = NewError(http.StatusConflict, "parent_deleted", "Parent deleted")
	ErrPublinkNameConflict            = NewError(http.StatusPreconditionFailed, "publink_name_conflict", "Another public share with this name already exists")
	ErrVersionNotFound                = NewError(http.StatusNotFound, "version_not_found", "Version Not Foud")
	ErrResourceVersionLatest          = NewError(http.StatusPreconditionFailed, "resource_version_latest", "Cannot delete most recent version of a resource")
)
View Source
var ErrUserNotFound = NewError(http.StatusNotFound, "user_not_found", "no such user")

Functions

func CheckResourceNameInvalid

func CheckResourceNameInvalid(s string) bool

func GrantUserPermissions

func GrantUserPermissions(db db.TxHandler, userID int32, permissions UserPermissions) error

func Initialize

func Initialize(db db.Handler, cfg Config) error

func Is

func Is(err, target error) bool

func NewError

func NewError(httpStatus int, code, msg string) error

func NewServerError

func NewServerError(msg string) error

func RemoveBookmark

func RemoveBookmark(db db.TxHandler, userID int32, id uuid.UUID) error

func RevokeUserPermissions

func RevokeUserPermissions(db db.TxHandler, userID int32, permissions UserPermissions) error

func TrashCompact

func TrashCompact(ctx context.Context, logger *zerolog.Logger, duration time.Duration)

func UserEmailByID

func UserEmailByID(db db.Handler, id int) (string, error)

func UserHome

func UserHome(db db.Handler, email string) (pgtype.UUID, error)

Types

type Bookmark

type Bookmark struct {
	ResourceID uuid.UUID
	Name       string
	Dir        bool
	Created    time.Time
}

func AddBookmark

func AddBookmark(db db.TxHandler, userID int32, resource Resource, name string) (Bookmark, error)

func ListBookmarks

func ListBookmarks(db db.Handler, userID int32, since int64) ([]Bookmark, error)

type Config

type Config struct {
	User     UserConfig     `koanf:"users"`
	Publinks PublinksConfig `koanf:"publinks"`
	Img      img.Config     `koanf:"img"`
}

type DiskUsageInfo

type DiskUsageInfo struct {
	TotalSize int64
	Entities  int64
	Files     int64
	Dirs      int64
}

type Error

type Error struct {
	Status  int    `json:"status"`
	Code    string `json:"code"`
	Message string `json:"msg"`
}

func (Error) Error

func (e Error) Error() string

type FileSystem

type FileSystem struct {
	// contains filtered or unexported fields
}

func OpenFileSystem

func OpenFileSystem(db db.Handler, pathRoot pgtype.UUID, userID int32, userPermissions UserPermissions, scopes []string) *FileSystem

func OpenSUFileSystem

func OpenSUFileSystem(db db.Handler) *FileSystem

func (*FileSystem) Copy

func (f *FileSystem) Copy(r Resource, target string, id uuid.UUID, recursive bool, conflictResolution ResourceBindConflictResolution) (Resource, bool, error)

func (*FileSystem) CreateFileByPath

func (f *FileSystem) CreateFileByPath(path string, requestedID, versionID uuid.UUID, conflictResolution ResourceBindConflictResolution) (io.WriteCloser, error)

func (*FileSystem) CreateFileVersion

func (f *FileSystem) CreateFileVersion(r Resource, versionID uuid.UUID) (io.WriteCloser, error)

func (FileSystem) CreateMount

func (f FileSystem) CreateMount(path string, backend storage.Backend) error
func (f *FileSystem) CreatePublink(r Resource, id, password string, expires pgtype.Timestamp, accessLimit int) error

func (*FileSystem) CreateResourceByPath

func (f *FileSystem) CreateResourceByPath(path string, requestedID uuid.UUID, dir, createParents bool, conflictResolution ResourceBindConflictResolution) (Resource, error)

func (*FileSystem) Delete

func (f *FileSystem) Delete(r Resource) (Resource, error)

func (*FileSystem) DeleteForever

func (f *FileSystem) DeleteForever(r Resource) error

func (*FileSystem) DeleteResourceVersion

func (f *FileSystem) DeleteResourceVersion(res Resource, versionID uuid.UUID) (Resource, error)

func (*FileSystem) DiskUsage

func (f *FileSystem) DiskUsage(r Resource) (DiskUsageInfo, error)

func (*FileSystem) GetAllVersions

func (f *FileSystem) GetAllVersions(r Resource) ([]Version, error)

func (*FileSystem) GetAncestors

func (f *FileSystem) GetAncestors(r Resource) ([]ResourceAncestor, error)

func (*FileSystem) GetImg

func (f *FileSystem) GetImg(r Resource, versionIDStr string, resolution img.Res) (io.ReadCloser, error)

func (*FileSystem) GetPath

func (f *FileSystem) GetPath(r Resource) (string, error)

func (*FileSystem) GetVersion

func (f *FileSystem) GetVersion(r Resource, versionIDStr string) (Version, error)
func (f *FileSystem) ListPublinks(r Resource) ([]Publink, error)

func (*FileSystem) Move

func (f *FileSystem) Move(r Resource, target string, conflictResolution ResourceBindConflictResolution) (Resource, bool, error)

func (*FileSystem) ReadDir

func (f *FileSystem) ReadDir(r Resource, recursive bool) ([]Resource, error)

func (*FileSystem) ReadDirExtended

func (f *FileSystem) ReadDirExtended(r Resource, recursive, includeDeleted, orderByDepth bool) ([]Resource, error)

func (*FileSystem) ResourceByID

func (f *FileSystem) ResourceByID(id uuid.UUID) (Resource, error)

func (*FileSystem) ResourceByPath

func (f *FileSystem) ResourceByPath(path string) (Resource, error)

ResourceByPath locates the resource at path.

An empty path or "/" will return the root resource.

A permission check will be performed to ensure that the FileSystem's User has read permissions on the resource. If not, then ErrResourceNotFound will be returned.

func (*FileSystem) ResourceByPathWithRoot

func (f *FileSystem) ResourceByPathWithRoot(path string) (Resource, error)

ResourceByPathWithRoot locates the resource at path. path may begin with a "<uuid>:" prefix, which will traverse the path relative to that root instead of this FileSystem's default [PathRoot].

An empty path or "/" will return the root resource.

A permission check will be performed to ensure that the FileSystem's User has read permissions on the resource. If not, then ErrResourceNotFound will be returned.

func (*FileSystem) RestoreDeleted

func (f *FileSystem) RestoreDeleted(r Resource, parentPathOrUUID string, name string, autoRename bool) (res Resource, err error)

func (*FileSystem) Search

func (f *FileSystem) Search(query string, includeDeleted bool) ([]Resource, error)

func (*FileSystem) TrashEmpty

func (f *FileSystem) TrashEmpty() error

func (*FileSystem) TrashList

func (f *FileSystem) TrashList(cursor string, n uint) ([]Resource, string, error)

func (*FileSystem) TrashSummary

func (f *FileSystem) TrashSummary() (int, int, error)

func (*FileSystem) UpdatePermissions

func (f *FileSystem) UpdatePermissions(r Resource, user User, permission Permission) (res Resource, err error)

func (*FileSystem) Walk

func (f *FileSystem) Walk(r Resource, depth int, fn func(Resource, string) error) error

type Permission

type Permission = int32
type Publink struct {
	ID           string
	Created      time.Time
	Root         uuid.UUID
	Accessed     int32
	AccessLimit  int32
	PasswordHash string
	Expires      int64
}

type PublinksConfig

type PublinksConfig struct {
	Password crypt.Config `koanf:"password"`
}

type ReadFileSystem

type ReadFileSystem interface {
	ResourceByPath(string) (Resource, error)
	ReadDir(Resource, bool) ([]Resource, error)
	GetVersion(Resource, string) (Version, error)
	Walk(Resource, int, func(Resource, string) error) error
}

filesystem_readonly.go

func OpenFileSystemFromPublink(ctx context.Context, id string, password string) (ReadFileSystem, error)

type Resource

type Resource struct {
	// contains filtered or unexported fields
}

func SharedResources

func SharedResources(db db.Handler, userID int32) ([]Resource, error)

func (Resource) Created

func (r Resource) Created() time.Time

func (Resource) Deleted

func (r Resource) Deleted() pgtype.Timestamp

func (Resource) Dir

func (r Resource) Dir() bool

func (Resource) Grants

func (r Resource) Grants() []byte

func (Resource) ID

func (r Resource) ID() uuid.UUID

func (Resource) InheritedPermissions

func (r Resource) InheritedPermissions() []byte

func (Resource) LatestVersion

func (r Resource) LatestVersion() VersionInfo
func (r Resource) Links() []byte

func (Resource) Modified

func (r Resource) Modified() time.Time

func (Resource) Name

func (r Resource) Name() string

func (Resource) Versions

func (r Resource) Versions() []byte

func (Resource) VisibleParentID

func (r Resource) VisibleParentID() pgtype.UUID

type ResourceAncestor

type ResourceAncestor struct {
	ID             uuid.UUID
	Name           string
	UserPermission Permission
}

type ResourceBindConflictResolution

type ResourceBindConflictResolution int32

type User

type User struct {
	ID          int32
	Email       string
	Name        string
	Home        pgtype.UUID
	Permissions UserPermissions
}

func CreateUser

func CreateUser(db db.TxHandler, email, name string, noCreateHome bool) (User, error)

func ListUsers

func ListUsers(db db.Handler, since int64) ([]User, error)

func UpdateUserHome

func UpdateUserHome(db db.TxHandler, userID int32, home pgtype.UUID) (User, error)

func UpdateUserName

func UpdateUserName(db db.TxHandler, userID int32, name string) (User, error)

func UserByEmail

func UserByEmail(db db.Handler, email string) (User, error)

func UserByID

func UserByID(db db.Handler, userID int32) (User, error)

type UserConfig

type UserConfig struct {
	BaseDir    string          `koanf:"basedir"`
	Permisison UserPermissions `koanf:"permission"`
}

type UserPermissions

type UserPermissions = int32

type Version

type Version struct {
	VersionInfo
	Storage string
}

func (Version) OpenRead

func (v Version) OpenRead(start, length int) (io.ReadCloser, error)

type VersionInfo

type VersionInfo struct {
	ID       uuid.UUID `json:"id"`
	Created  int       `json:"created"`
	Deleted  int       `json:"deleted,omitempty"`
	Size     int64     `json:"size"`
	MimeType string    `json:"mime_type"`
	SHA256   string    `json:"sha256"`
	ImgRes   uint8     `json:"imgres"`
}

VersionInfo represents a single version of a resource json tags are needed for unmarshalling the json object in sql queries

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL