space

package
v0.0.0-...-d25dbbd Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

View Source
const (
	SettingsModule = "space"
	SettingsKey    = "quota"
)
View Source
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"
)
View Source
const Collection = "user_files"

Variables

This section is empty.

Functions

func IsReservedRootFolderName

func IsReservedRootFolderName(name string, extraDisallowed []string) bool

IsReservedRootFolderName reports whether name is a system-reserved or dynamically disallowed root folder name.

func NormalizeExt

func NormalizeExt(v string) string

NormalizeExt normalises a file extension token to lowercase without leading dot. Handles the "python" alias for "py".

func NormalizeExts

func NormalizeExts(values []string) []string

NormalizeExts normalises a slice of extensions, deduplicating and dropping empties.

func ValidateExt

func ValidateExt(quota Quota, ext string) error

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

func ValidateItemCount(current, max int) error

ValidateItemCount returns an error when current >= max (and max > 0).

Types

type Quota

type Quota struct {
	MaxSizeMB             int
	MaxPerUser            int
	MaxUploadFiles        int
	ShareMaxMinutes       int
	ShareDefaultMinutes   int
	UploadAllowExts       []string
	UploadDenyExts        []string
	DisallowedFolderNames []string
}

Quota holds all effective quota values for the space domain.

func GetQuota

func GetQuota(app core.App) Quota

GetQuota loads the effective space quota configuration from sysconfig. Falls back to catalog defaults when the DB row is absent.

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 From

func From(rec *core.Record) *UserFile

From wraps a PocketBase record as a UserFile aggregate root.

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

func (f *UserFile) EffectiveDisplayName() string

EffectiveDisplayName returns name, falling back to the stored filename.

func (*UserFile) EffectiveMimeType

func (f *UserFile) EffectiveMimeType() string

EffectiveMimeType returns mime_type, falling back to "application/octet-stream".

func (*UserFile) ID

func (f *UserFile) ID() string

func (*UserFile) IsDeleted

func (f *UserFile) IsDeleted() bool

func (*UserFile) IsFolder

func (f *UserFile) IsFolder() bool

func (*UserFile) IsOwnedBy

func (f *UserFile) IsOwnedBy(auth *core.Record) bool

IsOwnedBy reports whether auth is the owner of this file.

func (*UserFile) IsOwnedByID

func (f *UserFile) IsOwnedByID(userID string) bool

IsOwnedByID reports ownership by raw user ID string.

func (*UserFile) IsPreviewable

func (f *UserFile) IsPreviewable() bool

IsPreviewable reports whether this file's MIME type is in the preview whitelist.

func (*UserFile) MimeType

func (f *UserFile) MimeType() string

func (*UserFile) Name

func (f *UserFile) Name() string

func (*UserFile) Owner

func (f *UserFile) Owner() string

func (*UserFile) Parent

func (f *UserFile) Parent() string

func (*UserFile) RevokeShare

func (f *UserFile) RevokeShare()

RevokeShare clears the share token and expiry from the underlying record.

func (*UserFile) Save

func (f *UserFile) Save(app core.App) error

Save persists the current aggregate state.

func (*UserFile) ShareExpiresAt

func (f *UserFile) ShareExpiresAt() (time.Time, error)

ShareExpiresAt parses and returns the share expiry time.

func (*UserFile) ShareIsActive

func (f *UserFile) ShareIsActive() (bool, string)

ShareIsActive preserves the previous boolean API while delegating to typed errors.

func (*UserFile) ShareToken

func (f *UserFile) ShareToken() string

func (*UserFile) Size

func (f *UserFile) Size() int

func (*UserFile) StoredFilename

func (f *UserFile) StoredFilename() string

func (*UserFile) ValidateShareActive

func (f *UserFile) ValidateShareActive() error

ValidateShareActive reports whether this file has an active (non-expired, non-revoked) share token. It returns a typed domain error when inactive.

Jump to

Keyboard shortcuts

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