Documentation
¶
Overview ¶
Package space implements the Space domain — the user's personal file workspace.
A UserFile is an owner-first entity: each file or folder is owned by exactly one authenticated user. Core capabilities are upload, preview, share, and remote-fetch.
Domain boundary: this package must not import backend/infra or backend/platform. PocketBase core is treated as a shared foundation layer.
Index ¶
- Constants
- func IsReservedRootFolderName(name string, extraDisallowed []string) bool
- func NormalizeExt(v string) string
- func NormalizeExts(values []string) []string
- func ValidateExt(quota Quota, ext string) error
- func ValidateItemCount(current, max int) error
- type Quota
- type UserFile
- func (f *UserFile) ApplyShare(s sharedshare.Token)
- func (f *UserFile) EffectiveDisplayName() string
- func (f *UserFile) EffectiveMimeType() string
- func (f *UserFile) ID() string
- func (f *UserFile) IsDeleted() bool
- func (f *UserFile) IsFolder() bool
- func (f *UserFile) IsOwnedBy(auth *core.Record) bool
- func (f *UserFile) IsOwnedByID(userID string) bool
- func (f *UserFile) IsPreviewable() bool
- func (f *UserFile) MimeType() string
- func (f *UserFile) Name() string
- func (f *UserFile) Owner() string
- func (f *UserFile) Parent() string
- func (f *UserFile) RevokeShare()
- func (f *UserFile) Save(app core.App) error
- func (f *UserFile) ShareExpiresAt() (time.Time, error)
- func (f *UserFile) ShareIsActive() (bool, string)
- func (f *UserFile) ShareToken() string
- func (f *UserFile) Size() int
- func (f *UserFile) StoredFilename() string
- func (f *UserFile) ValidateShareActive() error
Constants ¶
const ( SettingsModule = "space" SettingsKey = "quota" )
const ( // ReservedFolderNames are root-level folder names reserved by the system. ReservedFolderNames = "deploy,artifact" // PreviewMimeTypes is the whitelist of MIME types allowed for inline preview. // SVG is included — the frontend renders it via <img> which blocks JS execution. PreviewMimeTypes = "image/png,image/jpeg,image/gif,image/webp,image/svg+xml," + "image/bmp,image/x-icon,application/pdf," + "audio/mpeg,audio/wav,audio/ogg,audio/aac,audio/flac,audio/webm," + "video/mp4,video/webm,video/ogg" // AllowedUploadFormats lists every extension that may be uploaded. AllowedUploadFormats = "txt,md,yaml,yml,json,sh,bash,zsh,fish,env,js,ts,jsx,tsx,mjs,cjs,vue,svelte," + "py,rb,go,rs,java,c,cpp,h,hpp,cc,cs,php,swift,kt,scala,groovy,lua,r,m,pl,pm," + "ex,exs,erl,hrl,clj,cljs,fs,fsx,ml,mli," + "css,scss,sass,less,html,htm,xml,svg,sql,graphql," + "toml,ini,cfg,conf,properties,gitignore,dockerignore,makefile,cmake," + "editorconfig,log,diff,patch,lock," + "pdf,doc,docx,xls,xlsx,ppt,pptx,odt,ods,odp" // EditableFormats is the subset of AllowedUploadFormats that supports online editing. EditableFormats = "txt,md,yaml,yml,json,sh,bash,zsh,fish,env,js,ts,jsx,tsx,mjs,cjs,vue,svelte," + "py,rb,go,rs,java,c,cpp,h,hpp,cc,cs,php,swift,kt,scala,groovy,lua,r,m,pl,pm," + "ex,exs,erl,hrl,clj,cljs,fs,fsx,ml,mli," + "css,scss,sass,less,html,htm,xml,svg,sql,graphql," + "toml,ini,cfg,conf,properties,gitignore,dockerignore,makefile,cmake," + "editorconfig,log,diff,patch" )
const Collection = "user_files"
Variables ¶
This section is empty.
Functions ¶
func IsReservedRootFolderName ¶
IsReservedRootFolderName reports whether name is a system-reserved or dynamically disallowed root folder name.
func NormalizeExt ¶
NormalizeExt normalises a file extension token to lowercase without leading dot. Handles the "python" alias for "py".
func NormalizeExts ¶
NormalizeExts normalises a slice of extensions, deduplicating and dropping empties.
func ValidateExt ¶
ValidateExt checks whether ext is permitted by the quota allowlist/denylist. Returns a non-nil error with a user-facing message when the extension is blocked.
func ValidateItemCount ¶
ValidateItemCount returns an error when current >= max (and max > 0).
Types ¶
type Quota ¶
type Quota struct {
MaxSizeMB int
MaxPerUser int
MaxUploadFiles int
UploadAllowExts []string
UploadDenyExts []string
DisallowedFolderNames []string
}
Quota holds all effective quota values for the space domain.
type UserFile ¶
type UserFile struct {
// contains filtered or unexported fields
}
UserFile is the aggregate root for the Space domain. It wraps a PocketBase record and exposes typed domain accessors and invariants.
func (*UserFile) ApplyShare ¶
func (f *UserFile) ApplyShare(s sharedshare.Token)
ApplyShare writes the share token and expiry from s onto the underlying record.
func (*UserFile) EffectiveDisplayName ¶
EffectiveDisplayName returns name, falling back to the stored filename.
func (*UserFile) EffectiveMimeType ¶
EffectiveMimeType returns mime_type, falling back to "application/octet-stream".
func (*UserFile) IsOwnedByID ¶
IsOwnedByID reports ownership by raw user ID string.
func (*UserFile) IsPreviewable ¶
IsPreviewable reports whether this file's MIME type is in the preview whitelist.
func (*UserFile) RevokeShare ¶
func (f *UserFile) RevokeShare()
RevokeShare clears the share token and expiry from the underlying record.
func (*UserFile) ShareExpiresAt ¶
ShareExpiresAt parses and returns the share expiry time.
func (*UserFile) ShareIsActive ¶
ShareIsActive preserves the previous boolean API while delegating to typed errors.
func (*UserFile) ShareToken ¶
func (*UserFile) StoredFilename ¶
func (*UserFile) ValidateShareActive ¶
ValidateShareActive reports whether this file has an active (non-expired, non-revoked) share token. It returns a typed domain error when inactive.