models

package
v0.0.0-...-cbbc4cb Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BackupCompleteEvent          = "backupComplete"
	BackupFailedEvent            = "backupFailed"
	BackupProgressEvent          = "backupProgress"
	CopyFileCompleteEvent        = "copyFileComplete"
	CopyFileFailedEvent          = "copyFileFailed"
	CopyFileStartedEvent         = "copyFileStarted"
	ErrorEvent                   = "error"
	FileCreatedEvent             = "fileCreated"
	FileDeletedEvent             = "fileDeleted"
	FileMovedEvent               = "fileMoved"
	FileScanCompleteEvent        = "fileScanComplete"
	FileUpdatedEvent             = "fileUpdated"
	FilesDeletedEvent            = "filesDeleted"
	FilesMovedEvent              = "filesMoved"
	FilesUpdatedEvent            = "filesUpdated"
	FolderScanCompleteEvent      = "folderScanComplete"
	PoolCancelledEvent           = "poolCancelled"
	PoolCompleteEvent            = "poolComplete"
	PoolCreatedEvent             = "poolCreated"
	RemoteConnectionChangedEvent = "remoteConnectionChanged"
	RestoreCompleteEvent         = "restoreComplete"
	RestoreFailedEvent           = "restoreFailed"
	RestoreProgressEvent         = "restoreProgress"
	RestoreStartedEvent          = "restoreStarted"
	ScanDirectoryProgressEvent   = "scanDirectoryProgress"
	ServerGoingDownEvent         = "goingDown"
	ShareUpdatedEvent            = "shareUpdated"
	StartupProgressEvent         = "startupProgress"
	TaskCanceledEvent            = "taskCanceled"
	TaskCompleteEvent            = "taskComplete"
	TaskCreatedEvent             = "taskCreated"
	TaskFailedEvent              = "taskFailure"
	WeblensLoadedEvent           = "weblensLoaded"
	ZipCompleteEvent             = "zipComplete"
	ZipProgressEvent             = "createZipProgress"
)
View Source
const (
	ScanDirectoryTask    = "scan_directory"
	ScanFileTask         = "scan_file"
	MoveFileTask         = "move_file"
	UploadFilesTask      = "write_file"
	CreateZipTask        = "create_zip"
	GatherFsStatsTask    = "gather_filesystem_stats"
	BackupTask           = "do_backup"
	HashFileTask         = "hash_file"
	CopyFileFromCoreTask = "copy_file_from_core"
	RestoreCoreTask      = "restore_core"
)
View Source
const ThumbnailHeight float32 = 500

Variables

This section is empty.

Functions

func MakeOwner

func MakeOwner(u *User)

Types

type AccessService

type AccessService interface {
	GenerateJwtToken(user *User) (token string, expires time.Time, err error)
	GetApiKey(key WeblensApiKey) (ApiKey, error)
	AddApiKey(key ApiKey) error
	GetUserFromToken(token string) (*User, error)
	DeleteApiKey(key WeblensApiKey) error
	GenerateApiKey(creator *User, local *Instance) (ApiKey, error)
	CanUserAccessFile(user *User, file *fileTree.WeblensFileImpl, share *FileShare) bool
	CanUserModifyShare(user *User, share Share) bool
	CanUserAccessAlbum(user *User, album *Album, share *AlbumShare) bool

	GetAllKeys(accessor *User) ([]ApiKey, error)
	GetAllKeysByServer(accessor *User, serverId InstanceId) ([]ApiKey, error)
	SetKeyUsedBy(key WeblensApiKey, server *Instance) error
}

type Album

type Album struct {
	Id             AlbumId     `bson:"_id"`
	Name           string      `bson:"name"`
	Owner          Username    `bson:"owner"`
	Medias         []ContentId `bson:"medias"`
	Cover          ContentId   `bson:"cover"`
	PrimaryColor   string      `bson:"primaryColor"`
	SecondaryColor string      `bson:"secondaryColor"`
	ShowOnTimeline bool        `bson:"showOnTimeline"`
}

func NewAlbum

func NewAlbum(albumName string, owner *User) *Album

func (*Album) GetCover

func (a *Album) GetCover() ContentId

func (*Album) GetMedias

func (a *Album) GetMedias() []ContentId

func (*Album) GetName

func (a *Album) GetName() string

func (*Album) GetOwner

func (a *Album) GetOwner() Username

func (*Album) GetPrimaryColor

func (a *Album) GetPrimaryColor() string

func (*Album) ID

func (a *Album) ID() AlbumId

func (*Album) RemoveMedia

func (a *Album) RemoveMedia(toRemoveIds ...ContentId)

func (*Album) SetCover

func (a *Album) SetCover(cover ContentId, color1, color2 string)

type AlbumId

type AlbumId = string

type AlbumService

type AlbumService interface {
	Init() error
	Size() int
	Get(id AlbumId) *Album
	Add(album *Album) error
	Del(id AlbumId) error
	GetAllByUser(u *User) ([]*Album, error)

	GetAlbumMedias(album *Album) iter.Seq[*Media]

	RenameAlbum(album *Album, newName string) error
	SetAlbumCover(albumId AlbumId, cover *Media) error
	AddMediaToAlbum(album *Album, media ...*Media) error
	RemoveMediaFromAlbum(album *Album, mediaIds ...ContentId) error

	RemoveMediaFromAny(ContentId) error
}

type AlbumShare

type AlbumShare struct {
	ShareId   ShareId    `bson:"_id" json:"shareId"`
	AlbumId   AlbumId    `bson:"albumId" json:"albumId"`
	Owner     Username   `bson:"owner"`
	Accessors []Username `bson:"accessors"`
	Public    bool       `bson:"public"`
	Enabled   bool       `bson:"enabled"`
	Expires   time.Time  `bson:"expires"`
	Updated   time.Time  `bson:"updated"`
	ShareType ShareType  `bson:"shareType"`

} // @name AlbumShare

func NewAlbumShare

func NewAlbumShare(
	a *Album, owner *User, accessors []*User, public bool,
) *AlbumShare

func (*AlbumShare) AddUsers

func (s *AlbumShare) AddUsers(usernames []Username)

func (*AlbumShare) GetAccessors

func (s *AlbumShare) GetAccessors() []Username

func (*AlbumShare) GetItemId

func (s *AlbumShare) GetItemId() string

func (*AlbumShare) GetOwner

func (s *AlbumShare) GetOwner() Username

func (*AlbumShare) GetShareType

func (s *AlbumShare) GetShareType() ShareType

func (*AlbumShare) ID

func (s *AlbumShare) ID() ShareId

func (*AlbumShare) IsEnabled

func (s *AlbumShare) IsEnabled() bool

func (*AlbumShare) IsPublic

func (s *AlbumShare) IsPublic() bool

func (*AlbumShare) LastUpdated

func (s *AlbumShare) LastUpdated() time.Time

func (*AlbumShare) MarshalBSON

func (s *AlbumShare) MarshalBSON() ([]byte, error)

func (*AlbumShare) RemoveUsers

func (s *AlbumShare) RemoveUsers(usernames []Username)

func (*AlbumShare) SetAccessors

func (s *AlbumShare) SetAccessors(usernames []Username)

func (*AlbumShare) SetEnabled

func (s *AlbumShare) SetEnabled(enable bool)

func (*AlbumShare) SetItemId

func (s *AlbumShare) SetItemId(albumId string)

func (*AlbumShare) SetPublic

func (s *AlbumShare) SetPublic(pub bool)

func (*AlbumShare) UnmarshalBSON

func (s *AlbumShare) UnmarshalBSON(bs []byte) error

func (*AlbumShare) UpdatedNow

func (s *AlbumShare) UpdatedNow()

type ApiKey

type ApiKey struct {
	Id          primitive.ObjectID `bson:"_id"`
	Key         WeblensApiKey      `bson:"key"`
	Owner       Username           `bson:"owner"`
	CreatedTime time.Time          `bson:"createdTime"`
	RemoteUsing InstanceId         `bson:"remoteUsing"`
	CreatedBy   InstanceId         `bson:"createdBy"`
}

type BackupCoreFileMeta

type BackupCoreFileMeta struct {
	ProxyFileService FileService
	FileService      FileService
	File             *fileTree.WeblensFileImpl
	Caster           Broadcaster
	Core             *Instance
	Filename         string
}

func (BackupCoreFileMeta) FormatToResult

func (m BackupCoreFileMeta) FormatToResult() task.TaskResult

func (BackupCoreFileMeta) JobName

func (m BackupCoreFileMeta) JobName() string

func (BackupCoreFileMeta) MetaString

func (m BackupCoreFileMeta) MetaString() string

func (BackupCoreFileMeta) Verify

func (m BackupCoreFileMeta) Verify() error

type BackupMeta

type BackupMeta struct {
	Core             *Instance
	FileService      FileService
	UserService      UserService
	WebsocketService ClientManager
	InstanceService  InstanceService
	TaskService      task.TaskService
	AccessService    AccessService
	Caster           Broadcaster
}

func (BackupMeta) FormatToResult

func (m BackupMeta) FormatToResult() task.TaskResult

func (BackupMeta) JobName

func (m BackupMeta) JobName() string

func (BackupMeta) MetaString

func (m BackupMeta) MetaString() string

func (BackupMeta) Verify

func (m BackupMeta) Verify() error

type BasicCaster

type BasicCaster interface {
	PushWeblensEvent(eventTag string, content ...WsC)

	PushFileUpdate(updatedFile *fileTree.WeblensFileImpl, media *Media)
	PushTaskUpdate(task *task.Task, event string, result task.TaskResult)
	PushPoolUpdate(pool task.Pool, event string, result task.TaskResult)
}

type Broadcaster

type Broadcaster interface {
	BasicCaster
	PushFileCreate(newFile *fileTree.WeblensFileImpl)
	PushFileMove(preMoveFile *fileTree.WeblensFileImpl, postMoveFile *fileTree.WeblensFileImpl)
	PushFilesMove(preMoveParentId, postMoveParentId fileTree.FileId, files []*fileTree.WeblensFileImpl)
	PushFileDelete(deletedFile *fileTree.WeblensFileImpl)
	PushFilesDelete(deletedFiles []*fileTree.WeblensFileImpl)
	PushFilesUpdate(files []*fileTree.WeblensFileImpl, medias []*Media)
	PushShareUpdate(username Username, newShareInfo Share)
	Enable()
	Disable()
	IsEnabled() bool
	IsBuffered() bool

	FolderSubToTask(folder fileTree.FileId, taskId task.Id)
	// UnsubTask(task *task.Task)
	DisableAutoFlush()
	AutoFlushEnable()
	Flush()

	Relay(msg WsResponseInfo)

	// Close flush, release the auto-flusher, and disable the caster
	Close()
}

type Client

type Client interface {
	BasicCaster

	IsOpen() bool

	ReadOne() (int, []byte, error)

	GetSubscriptions() iter.Seq[Subscription]
	GetClientId() ClientId
	GetShortId() ClientId

	SubLock()
	SubUnlock()

	AddSubscription(sub Subscription)

	GetUser() *User
	GetRemote() *Instance

	Error(error)
}

type ClientId

type ClientId = string

type ClientManager

type ClientManager interface {
	ClientConnect(conn *websocket.Conn, user *User) *WsClient
	ClientDisconnect(c *WsClient)
	RemoteConnect(conn *websocket.Conn, remote *Instance) *WsClient

	Send(msg WsResponseInfo)

	GetSubscribers(st WsAction, key SubId) (clients []*WsClient)
	GetClientByUsername(username Username) *WsClient
	GetClientByServerId(id InstanceId) *WsClient
	GetAllClients() []*WsClient
	GetConnectedAdmins() []*WsClient

	// FolderSubToPool(folderId fileTree.FileId, poolId task.Id)
	// TaskSubToPool(taskId task.Id, poolId task.Id)
	FolderSubToTask(folderId fileTree.FileId, taskId task.Id)
	UnsubTask(taskId task.Id)

	Subscribe(c *WsClient, key SubId, action WsAction, subTime time.Time, share Share) (
		complete bool, results map[task.TaskResultKey]any, err error,
	)
	Unsubscribe(c *WsClient, key SubId, unSubTime time.Time) error
}

type ClientType

type ClientType string
const (
	WebClient    ClientType = "webClient"
	RemoteClient ClientType = "remoteClient"
)

type ContentId

type ContentId = string

type FileCaster

type FileCaster interface {
	PushFileUpdate(updatedFile *fileTree.WeblensFileImpl, media *Media)
	PushFilesUpdate(updatedFiles []*fileTree.WeblensFileImpl, medias []*Media)

	PushTaskUpdate(task *task.Task, event string, result task.TaskResult)
	PushPoolUpdate(pool task.Pool, event string, result task.TaskResult)
	PushFileCreate(newFile *fileTree.WeblensFileImpl)

	PushFileMove(preMoveFile *fileTree.WeblensFileImpl, postMoveFile *fileTree.WeblensFileImpl)
	PushFilesMove(preMoveParentId, postMoveParentId fileTree.FileId, files []*fileTree.WeblensFileImpl)

	PushFileDelete(deletedFile *fileTree.WeblensFileImpl)
	PushFilesDelete(deletedFiles []*fileTree.WeblensFileImpl)
	Close()
	Flush()
}

type FileChunk

type FileChunk struct {
	FileId       fileTree.FileId
	Chunk        []byte
	ContentRange string

	NewFile *fileTree.WeblensFileImpl
}

type FileService

type FileService interface {
	Size(treeAlias string) int64

	AddTree(tree fileTree.FileTree)
	GetFileTreeByName(treeName string) fileTree.FileTree

	GetFileByTree(id fileTree.FileId, treeAlias string) (*fileTree.WeblensFileImpl, error)
	GetFileByContentId(contentId ContentId) (*fileTree.WeblensFileImpl, error)
	GetFiles(ids []fileTree.FileId) ([]*fileTree.WeblensFileImpl, []fileTree.FileId, error)
	GetFileSafe(id fileTree.FileId, accessor *User, share *FileShare) (*fileTree.WeblensFileImpl, error)

	PathToFile(searchPath string) (*fileTree.WeblensFileImpl, error)
	UserPathToFile(searchPath string, user *User) (*fileTree.WeblensFileImpl, error)

	CreateFile(parent *fileTree.WeblensFileImpl, filename string, event *fileTree.FileEvent, caster FileCaster) (*fileTree.WeblensFileImpl, error)
	CreateFolder(parent *fileTree.WeblensFileImpl, folderName string, event *fileTree.FileEvent, caster FileCaster) (*fileTree.WeblensFileImpl, error)
	CreateUserHome(user *User) error

	NewBackupFile(lt *fileTree.Lifetime) (*fileTree.WeblensFileImpl, error)

	GetFileOwner(file *fileTree.WeblensFileImpl) *User
	IsFileInTrash(file *fileTree.WeblensFileImpl) bool

	MoveFiles(files []*fileTree.WeblensFileImpl, destFolder *fileTree.WeblensFileImpl, treeName string, caster FileCaster) error
	RenameFile(file *fileTree.WeblensFileImpl, newName string, caster FileCaster) error
	MoveFilesToTrash(file []*fileTree.WeblensFileImpl, mover *User, share *FileShare, caster FileCaster) error
	ReturnFilesFromTrash(files []*fileTree.WeblensFileImpl, caster FileCaster) error
	DeleteFiles(files []*fileTree.WeblensFileImpl, treeName string, caster FileCaster) error
	RestoreFiles(ids []fileTree.FileId, newParent *fileTree.WeblensFileImpl, restoreTime time.Time, caster FileCaster) error
	RestoreHistory(lifetimes []*fileTree.Lifetime) error

	ReadFile(f *fileTree.WeblensFileImpl) (io.ReadCloser, error)

	GetMediaCacheByFilename(filename string) (*fileTree.WeblensFileImpl, error)
	NewCacheFile(media *Media, quality MediaQuality, pageNum int) (*fileTree.WeblensFileImpl, error)
	DeleteCacheFile(file fileTree.WeblensFile) error

	GetFolderCover(folder *fileTree.WeblensFileImpl) (ContentId, error)
	SetFolderCover(folderId fileTree.FileId, coverId ContentId) error

	AddTask(f *fileTree.WeblensFileImpl, t *task.Task) error
	RemoveTask(f *fileTree.WeblensFileImpl, t *task.Task) error
	GetTasks(f *fileTree.WeblensFileImpl) []*task.Task

	GetJournalByTree(treeName string) fileTree.Journal

	ResizeDown(file *fileTree.WeblensFileImpl, caster FileCaster) error
	ResizeUp(file *fileTree.WeblensFileImpl, caster FileCaster) error
	NewZip(zipName string, owner *User) (*fileTree.WeblensFileImpl, error)
	GetZip(id fileTree.FileId) (*fileTree.WeblensFileImpl, error)
}

type FileShare

type FileShare struct {
	ShareId   ShareId         `bson:"_id"`
	FileId    fileTree.FileId `bson:"fileId"`
	ShareName string          `bson:"shareName"`
	Owner     Username        `bson:"owner"`
	Accessors []Username      `bson:"accessors"`
	Public    bool            `bson:"public"`
	Wormhole  bool            `bson:"wormhole"`
	Enabled   bool            `bson:"enabled"`
	Expires   time.Time       `bson:"expires"`
	Updated   time.Time       `bson:"updated"`
	ShareType ShareType       `bson:"shareType"`
}

func NewFileShare

func NewFileShare(
	f *fileTree.WeblensFileImpl, owner *User, accessors []*User, public bool, wormhole bool,
) *FileShare

func (*FileShare) AddUsers

func (s *FileShare) AddUsers(usernames []Username)

func (*FileShare) GetAccessors

func (s *FileShare) GetAccessors() []Username

func (*FileShare) GetItemId

func (s *FileShare) GetItemId() string

func (*FileShare) GetOwner

func (s *FileShare) GetOwner() Username

func (*FileShare) GetShareType

func (s *FileShare) GetShareType() ShareType

func (*FileShare) ID

func (s *FileShare) ID() ShareId

func (*FileShare) IsEnabled

func (s *FileShare) IsEnabled() bool

func (*FileShare) IsPublic

func (s *FileShare) IsPublic() bool

func (*FileShare) IsWormhole

func (s *FileShare) IsWormhole() bool

func (*FileShare) LastUpdated

func (s *FileShare) LastUpdated() time.Time

func (*FileShare) RemoveUsers

func (s *FileShare) RemoveUsers(usernames []Username)

func (*FileShare) SetAccessors

func (s *FileShare) SetAccessors(usernames []Username)

func (*FileShare) SetEnabled

func (s *FileShare) SetEnabled(enable bool)

func (*FileShare) SetItemId

func (s *FileShare) SetItemId(fileId string)

func (*FileShare) SetPublic

func (s *FileShare) SetPublic(pub bool)

func (*FileShare) UpdatedNow

func (s *FileShare) UpdatedNow()

type FileUploadProgress

type FileUploadProgress struct {
	File          *fileTree.WeblensFileImpl
	BytesWritten  int64
	FileSizeTotal int64
	Hash          hash.Hash
}

type FsStatMeta

type FsStatMeta struct {
	RootDir *fileTree.WeblensFileImpl
}

func (FsStatMeta) FormatToResult

func (m FsStatMeta) FormatToResult() task.TaskResult

func (FsStatMeta) JobName

func (m FsStatMeta) JobName() string

func (FsStatMeta) MetaString

func (m FsStatMeta) MetaString() string

func (FsStatMeta) Verify

func (m FsStatMeta) Verify() error

type HashFileMeta

type HashFileMeta struct {
	File   *fileTree.WeblensFileImpl
	Caster Broadcaster
}

func (HashFileMeta) FormatToResult

func (m HashFileMeta) FormatToResult() task.TaskResult

func (HashFileMeta) JobName

func (m HashFileMeta) JobName() string

func (HashFileMeta) MetaString

func (m HashFileMeta) MetaString() string

func (HashFileMeta) Verify

func (m HashFileMeta) Verify() error

type Hasher

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

func NewHasher

func NewHasher(service task.TaskService, caster Broadcaster) *Hasher

func (*Hasher) Hash

func (h *Hasher) Hash(file *fileTree.WeblensFileImpl) error

func (*Hasher) Wait

func (h *Hasher) Wait()

type Instance

type Instance struct {
	// The ID of the server in the local database
	DbId primitive.ObjectID `json:"-" bson:"_id"`

	// The ID of the server that is shared between all servers
	Id   InstanceId `json:"id" bson:"instanceId"`
	Name string     `json:"name" bson:"name"`

	// Only applies to "core" server entries. This is the apiKey that remote server is using to connect to local,
	// if local is core. If local is backup, then this is the key being used to connect to remote core
	UsingKey WeblensApiKey `json:"-" bson:"usingKey"`

	// Core or BackupServer
	Role ServerRole `json:"role" bson:"serverRole"`

	// If this server info represents this local server
	IsThisServer bool `json:"-" bson:"isThisServer"`

	// Address of the remote server, only if the instance is a core.
	// Not set for any remotes/backups on core server, as it IS the core
	Address string `json:"coreAddress" bson:"coreAddress"`

	// The ID of the server in which this remote instance is in reference from
	CreatedBy InstanceId `json:"createdBy" bson:"createdBy"`

	// The time of the latest backup, in milliseconds since epoch
	LastBackup int64 `json:"lastBackup" bson:"lastBackup"`
	// contains filtered or unexported fields
}

An "Instance" is a single Weblens server. For clarity: Core vs Backup are absolute server roles, and each server will fit into one of these categories once initialized. Local vs Remote are RELATIVE terms, meaning one core servers "remote" is the backup servers "local".

func NewInstance

func NewInstance(
	id InstanceId, name string, key WeblensApiKey, role ServerRole, isThisServer bool,
	address string, createdBy InstanceId,
) *Instance

func (*Instance) GetAddress

func (wi *Instance) GetAddress() (string, error)

func (*Instance) GetName

func (wi *Instance) GetName() string

func (*Instance) GetReportedRole

func (wi *Instance) GetReportedRole() ServerRole

func (*Instance) GetRole

func (wi *Instance) GetRole() ServerRole

func (*Instance) GetUsingKey

func (wi *Instance) GetUsingKey() WeblensApiKey

func (*Instance) IsCore

func (wi *Instance) IsCore() bool

func (*Instance) IsLocal

func (wi *Instance) IsLocal() bool

func (*Instance) ServerId

func (wi *Instance) ServerId() InstanceId

func (*Instance) SetAddress

func (wi *Instance) SetAddress(address string) error

func (*Instance) SetReportedRole

func (wi *Instance) SetReportedRole(role ServerRole)

func (*Instance) SetRole

func (wi *Instance) SetRole(role ServerRole)

func (*Instance) SetServerId

func (wi *Instance) SetServerId(id InstanceId)

func (*Instance) SetUsingKey

func (wi *Instance) SetUsingKey(key WeblensApiKey)

func (*Instance) SocketType

func (wi *Instance) SocketType() string

type InstanceId

type InstanceId = string

type InstanceService

type InstanceService interface {
	Size() int

	Get(dbId string) *Instance
	GetAllByOriginServer(serverId InstanceId) []*Instance
	GetByInstanceId(serverId InstanceId) *Instance
	Add(instance *Instance) error
	Del(dbId primitive.ObjectID) error
	GetLocal() *Instance
	GetCores() []*Instance
	GetRemotes() []*Instance
	InitCore(serverName string) error
	InitBackup(name, coreAddr string, key WeblensApiKey) error
	SetLastBackup(id InstanceId, time time.Time) error
	AttachRemoteCore(coreAddr string, key string) (*Instance, error)
	ResetAll() error
}

type Media

type Media struct {
	MediaId primitive.ObjectID `bson:"_id" example:"5f9b3b3b7b4f3b0001b3b3b7"`

	// Hash of the file content, to ensure that the same files don't get duplicated
	ContentId ContentId `bson:"contentId"`

	// Slices of files whos content hash to the contentId
	FileIds []fileTree.FileId `bson:"fileIds"`

	CreateDate time.Time `bson:"createDate"`

	// User who owns the file that resulted in this media being created
	Owner Username `bson:"owner"`

	// Full-res image dimensions
	Width  int `bson:"width"`
	Height int `bson:"height"`

	// Number of pages (typically 1, 0 in not a valid page count)
	PageCount int `bson:"pageCount"`

	// Total time, in milliseconds, of a video
	Duration int `bson:"duration"`

	// Mime-type key of the media
	MimeType string `bson:"mimeType"`

	// Tags from the ML image scan so searching for particular objects in the images can be done
	RecognitionTags []string `bson:"recognitionTags"`

	// If the media is hidden from the timeline
	// TODO - make this per user
	Hidden bool `bson:"hidden"`

	// If the media disabled. This can happen when the backing file(s) are deleted,
	// but the media stays behind because it can be re-used if needed.
	Enabled bool `bson:"enabled"`

	LikedBy []Username `bson:"likedBy"`

	// The rotation of the image from its original. Found from the exif data
	Rotate string
	// contains filtered or unexported fields
}

func NewMedia

func NewMedia(contentId ContentId) *Media

func (*Media) AddFile

func (m *Media) AddFile(f *fileTree.WeblensFileImpl)

func (*Media) FmtCacheFileName

func (m *Media) FmtCacheFileName(quality MediaQuality, pageNum int) string

func (*Media) GetCreateDate

func (m *Media) GetCreateDate() time.Time

func (*Media) GetFiles

func (m *Media) GetFiles() []fileTree.FileId

func (*Media) GetHighresCacheFiles

func (m *Media) GetHighresCacheFiles(pageNum int) *fileTree.WeblensFileImpl

func (*Media) GetLowresCacheFile

func (m *Media) GetLowresCacheFile() *fileTree.WeblensFileImpl

func (*Media) GetOwner

func (m *Media) GetOwner() Username

func (*Media) GetPageCount

func (m *Media) GetPageCount() int

func (*Media) GetVideoLength

func (m *Media) GetVideoLength() int

GetVideoLength returns the length of the media video, if it is a video. Duration is counted in milliseconds

func (*Media) ID

func (m *Media) ID() ContentId

func (*Media) IsEnabled

func (m *Media) IsEnabled() bool

func (*Media) IsHidden

func (m *Media) IsHidden() bool

func (*Media) IsImported

func (m *Media) IsImported() bool

func (*Media) MarshalJSON

func (m *Media) MarshalJSON() ([]byte, error)

func (*Media) SetContentId

func (m *Media) SetContentId(id ContentId)

func (*Media) SetCreateDate

func (m *Media) SetCreateDate(t time.Time)

func (*Media) SetEnabled

func (m *Media) SetEnabled(e bool)

func (*Media) SetHighresCacheFiles

func (m *Media) SetHighresCacheFiles(highresFile *fileTree.WeblensFileImpl, pageNum int)

func (*Media) SetImported

func (m *Media) SetImported(i bool)

func (*Media) SetLowresCacheFile

func (m *Media) SetLowresCacheFile(thumb *fileTree.WeblensFileImpl)

func (*Media) SetOwner

func (m *Media) SetOwner(owner Username)

func (*Media) UnmarshalBSON

func (m *Media) UnmarshalBSON(bs []byte) error

func (*Media) UnmarshalJSON

func (m *Media) UnmarshalJSON(bs []byte) error

type MediaQuality

type MediaQuality string
const (
	LowRes  MediaQuality = "thumbnail"
	HighRes MediaQuality = "fullres"
	Video   MediaQuality = "video"
)

type MediaService

type MediaService interface {
	Size() int
	Add(media *Media) error

	Get(id ContentId) *Media
	GetAll() []*Media

	Del(id ContentId) error
	HideMedia(m *Media, hidden bool) error
	AdjustMediaDates(anchor *Media, newTime time.Time, extraMedias []*Media) error

	LoadMediaFromFile(m *Media, file *fileTree.WeblensFileImpl) error
	RemoveFileFromMedia(media *Media, fileId fileTree.FileId) error
	Cleanup() error
	AddFileToMedia(media *Media, file *fileTree.WeblensFileImpl) error

	GetMediaType(m *Media) MediaType
	GetMediaTypes() MediaTypeService
	IsFileDisplayable(file *fileTree.WeblensFileImpl) bool
	IsCached(m *Media) bool
	GetProminentColors(media *Media) (prom []string, err error)

	FetchCacheImg(m *Media, quality MediaQuality, pageNum int) ([]byte, error)
	StreamVideo(m *Media, u *User, share *FileShare) (*VideoStreamer, error)
	StreamCacheVideo(m *Media, startByte, endByte int) ([]byte, error)
	NukeCache() error

	GetFilteredMedia(
		requester *User, sort string, sortDirection int, excludeIds []ContentId, raw bool, hidden bool,
	) ([]*Media, error)
	RecursiveGetMedia(folders ...*fileTree.WeblensFileImpl) []*Media

	SetMediaLiked(mediaId ContentId, liked bool, username Username) error
}

type MediaType

type MediaType struct {
	Mime            string   `json:"mime"`
	Name            string   `json:"FriendlyName"`
	Extensions      []string `json:"FileExtension"`
	Displayable     bool     `json:"IsDisplayable"`
	Raw             bool     `json:"IsRaw"`
	Video           bool     `json:"IsVideo"`
	ImgRecog        bool     `json:"SupportsImgRecog"`
	MultiPage       bool     `json:"MultiPage"`
	RawThumbExifKey string   `json:"RawThumbExifKey"`

} // @name MediaType

func (MediaType) FriendlyName

func (mt MediaType) FriendlyName() string

func (MediaType) GetMime

func (mt MediaType) GetMime() string

func (MediaType) GetThumbExifKey

func (mt MediaType) GetThumbExifKey() string

func (MediaType) IsDisplayable

func (mt MediaType) IsDisplayable() bool

func (MediaType) IsMime

func (mt MediaType) IsMime(mime string) bool

func (MediaType) IsMultiPage

func (mt MediaType) IsMultiPage() bool

func (MediaType) IsRaw

func (mt MediaType) IsRaw() bool

func (MediaType) IsSupported

func (mt MediaType) IsSupported() bool

func (MediaType) IsVideo

func (mt MediaType) IsVideo() bool

func (MediaType) SupportsImgRecog

func (mt MediaType) SupportsImgRecog() bool

type MediaTypeService

type MediaTypeService interface {
	GetMaps() (map[string]MediaType, map[string]MediaType)
	ParseExtension(ext string) MediaType
	ParseMime(mime string) MediaType
	Generic() MediaType
	Size() int
}

func NewTypeService

func NewTypeService(marshMap map[string]MediaType) MediaTypeService

type MoveMeta

type MoveMeta struct {
	FileIds             []fileTree.FileId
	DestinationFolderId fileTree.FileId
	NewFilename         string
	FileEvent           *fileTree.FileEvent
	Caster              FileCaster

	User        *User
	FileService FileService
}

func (MoveMeta) FormatToResult

func (m MoveMeta) FormatToResult() task.TaskResult

func (MoveMeta) JobName

func (m MoveMeta) JobName() string

func (MoveMeta) MetaString

func (m MoveMeta) MetaString() string

func (MoveMeta) Verify

func (m MoveMeta) Verify() error

type RestoreCoreMeta

type RestoreCoreMeta struct {
	Core  *Instance
	Local *Instance
	Pack  *ServicePack
}

func (RestoreCoreMeta) FormatToResult

func (m RestoreCoreMeta) FormatToResult() task.TaskResult

func (RestoreCoreMeta) JobName

func (m RestoreCoreMeta) JobName() string

func (RestoreCoreMeta) MetaString

func (m RestoreCoreMeta) MetaString() string

func (RestoreCoreMeta) Verify

func (m RestoreCoreMeta) Verify() error

type ScanMeta

type ScanMeta struct {
	File         *fileTree.WeblensFileImpl
	FileBytes    []byte
	PartialMedia *Media

	FileService  FileService
	MediaService MediaService
	TaskService  TaskDispatcher
	TaskSubber   TaskSubscriber
	Caster       FileCaster
}

func (ScanMeta) FormatToResult

func (m ScanMeta) FormatToResult() task.TaskResult

func (ScanMeta) JobName

func (m ScanMeta) JobName() string

func (ScanMeta) MetaString

func (m ScanMeta) MetaString() string

MetaString overrides marshal function for scanMetadata

func (ScanMeta) Verify

func (m ScanMeta) Verify() error

type Server

type Server interface {
	Start()
	UseApi() *chi.Mux
	Restart(wait bool)
	Stop()
}

type ServerRole

type ServerRole = string
const (
	InitServerRole    ServerRole = "init"
	CoreServerRole    ServerRole = "core"
	BackupServerRole  ServerRole = "backup"
	RestoreServerRole ServerRole = "restore"
)

type ServicePack

type ServicePack struct {
	FileService     FileService
	MediaService    MediaService
	AccessService   AccessService
	UserService     UserService
	ShareService    ShareService
	InstanceService InstanceService
	AlbumService    AlbumService
	TaskService     task.TaskService
	ClientService   ClientManager
	Caster          Broadcaster

	Server      Server
	Loaded      atomic.Bool
	StartupChan chan bool

	Db *mongo.Database
	// contains filtered or unexported fields
}

func (*ServicePack) AddStartupTask

func (pack *ServicePack) AddStartupTask(taskName, description string)

func (*ServicePack) GetStartupTasks

func (pack *ServicePack) GetStartupTasks() []StartupTask

func (*ServicePack) RemoveStartupTask

func (pack *ServicePack) RemoveStartupTask(taskName string)

type Share

type Share interface {
	ID() ShareId
	GetShareType() ShareType
	GetItemId() string
	IsPublic() bool
	IsEnabled() bool
	GetAccessors() []Username
	GetOwner() Username
	AddUsers(usernames []Username)
	RemoveUsers(usernames []Username)
	SetAccessors(usernames []Username)

	SetItemId(string)
	SetPublic(bool)
	SetEnabled(bool)

	UpdatedNow()
	LastUpdated() time.Time
}

type ShareId

type ShareId = string

type ShareService

type ShareService interface {
	Size() int

	Get(id ShareId) Share
	Add(share Share) error
	Del(id ShareId) error
	AddUsers(share Share, newUsers []*User) error
	RemoveUsers(share Share, newUsers []*User) error

	GetFileShare(fId fileTree.FileId) (*FileShare, error)
	GetAlbumShare(aId AlbumId) (*AlbumShare, error)

	GetFileSharesWithUser(u *User) ([]*FileShare, error)
	GetAlbumSharesWithUser(u *User) ([]*AlbumShare, error)

	GetAllShares() []Share

	EnableShare(share Share, enabled bool) error
	SetSharePublic(share Share, public bool) error
}

type ShareType

type ShareType = string
const (
	SharedFile  ShareType = "file"
	SharedAlbum ShareType = "album"
)

type SocketUser

type SocketUser interface {
	SocketType() string
}

type StartupTask

type StartupTask struct {
	Name        string
	Description string
	StartedAt   time.Time
}

type SubId

type SubId = string

type Subscription

type Subscription struct {
	Type WsAction
	Key  SubId
	When time.Time
}

type TaskDispatcher

type TaskDispatcher interface {
	DispatchJob(jobName string, meta task.TaskMetadata, pool *task.TaskPool) (*task.Task, error)
}

type TaskStage

type TaskStage struct {
	Key      string `json:"key"`
	Name     string `json:"name"`
	Started  int64  `json:"started"`
	Finished int64  `json:"finished"`
	// contains filtered or unexported fields
}

type TaskStages

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

func NewBackupTaskStages

func NewBackupTaskStages() *TaskStages

func (*TaskStages) FinishStage

func (ts *TaskStages) FinishStage(key string)

func (*TaskStages) MarshalJSON

func (ts *TaskStages) MarshalJSON() ([]byte, error)

func (*TaskStages) StartStage

func (ts *TaskStages) StartStage(key string)

type TaskSubscriber

type TaskSubscriber interface {
	FolderSubToTask(folderId fileTree.FileId, taskId task.Id)
	UnsubTask(taskId task.Id)
}

type Token

type Token struct {
	Token    string   `json:"token"`
	Username Username `json:"username"`
}

type UploadFilesMeta

type UploadFilesMeta struct {
	ChunkStream  chan FileChunk
	RootFolderId fileTree.FileId
	ChunkSize    int64
	TotalSize    int64

	UploadEvent *fileTree.FileEvent

	FileService  FileService
	MediaService MediaService
	TaskService  task.TaskService
	TaskSubber   TaskSubscriber
	User         *User
	Share        *FileShare
	Caster       FileCaster
}

func (UploadFilesMeta) FormatToResult

func (m UploadFilesMeta) FormatToResult() task.TaskResult

func (UploadFilesMeta) JobName

func (m UploadFilesMeta) JobName() string

func (UploadFilesMeta) MetaString

func (m UploadFilesMeta) MetaString() string

func (UploadFilesMeta) Verify

func (m UploadFilesMeta) Verify() error

type User

type User struct {
	Id            primitive.ObjectID `bson:"_id"`
	Username      Username           `bson:"username"`
	Password      string             `bson:"password"`
	Admin         bool               `bson:"admin"`
	Activated     bool               `bson:"activated"`
	IsServerOwner bool               `bson:"owner"`
	HomeId        fileTree.FileId    `bson:"homeId"`
	TrashId       fileTree.FileId    `bson:"trashId"`

	// The id of the server instance that created this user
	CreatedBy InstanceId `bson:"createdBy"`

	SystemUser bool
	// contains filtered or unexported fields
}

func NewUser

func NewUser(username Username, password string, isAdmin, autoActivate bool) (*User, error)

func (*User) CheckLogin

func (u *User) CheckLogin(password string) bool

func (*User) GetUsername

func (u *User) GetUsername() Username

func (*User) IsActive

func (u *User) IsActive() bool

func (*User) IsAdmin

func (u *User) IsAdmin() bool

func (*User) IsOwner

func (u *User) IsOwner() bool

func (*User) IsPublic

func (u *User) IsPublic() bool

func (*User) IsSystemUser

func (u *User) IsSystemUser() bool

func (*User) SetHomeFolder

func (u *User) SetHomeFolder(f *fileTree.WeblensFileImpl)

func (*User) SetTrashFolder

func (u *User) SetTrashFolder(f *fileTree.WeblensFileImpl)

func (*User) SocketType

func (u *User) SocketType() string

func (*User) UnmarshalJSON

func (u *User) UnmarshalJSON(data []byte) error

type UserService

type UserService interface {
	Size() int
	Get(id Username) *User
	Add(user *User) error
	Del(id Username) error
	GetAll() (iter.Seq[*User], error)
	CreateOwner(username, password string) (*User, error)
	GetPublicUser() *User
	SearchByUsername(searchString string) (iter.Seq[*User], error)
	SetUserAdmin(*User, bool) error
	ActivateUser(*User, bool) error
	GetRootUser() *User
	UpdateUserHome(u *User) error

	UpdateUserPassword(username Username, oldPassword, newPassword string, allowEmptyOld bool) error
}

type Username

type Username = string

type VideoStreamer

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

func NewVideoStreamer

func NewVideoStreamer(file *fileTree.WeblensFileImpl) *VideoStreamer

func (*VideoStreamer) Encode

func (*VideoStreamer) Err

func (vs *VideoStreamer) Err() error

func (*VideoStreamer) GetChunk

func (vs *VideoStreamer) GetChunk(chunkName string) (*os.File, error)

func (*VideoStreamer) GetEncodeDir

func (vs *VideoStreamer) GetEncodeDir() string

func (*VideoStreamer) GetListFile

func (vs *VideoStreamer) GetListFile() ([]byte, error)

func (*VideoStreamer) IsTranscoding

func (vs *VideoStreamer) IsTranscoding() bool

type WeblensApiKey

type WeblensApiKey = string

type WsAction

type WsAction string

WsAction is an action sent by the client to the server

const (
	// UserSubscribe does not actually get "subscribed" to, it is automatically tracked for every websocket
	// connection made, and only sends updates to that specific user when needed
	UserSubscribe WsAction = "userSubscribe"

	FolderSubscribe   WsAction = "folderSubscribe"
	TaskSubscribe     WsAction = "taskSubscribe"
	TaskTypeSubscribe WsAction = "taskTypeSubscribe"
	Unsubscribe       WsAction = "unsubscribe"
	ScanDirectory     WsAction = "scanDirectory"
	CancelTask        WsAction = "cancelTask"
	ReportError       WsAction = "showWebError"
)

type WsC

type WsC map[string]any

WsC is the generic WebSocket Content container

type WsClient

type WsClient struct {
	Active atomic.Bool
	// contains filtered or unexported fields
}

func NewClient

func NewClient(conn *websocket.Conn, socketUser SocketUser) *WsClient

func (*WsClient) AddSubscription

func (wsc *WsClient) AddSubscription(sub Subscription)

func (*WsClient) ClientType

func (wsc *WsClient) ClientType() ClientType

func (*WsClient) Disconnect

func (wsc *WsClient) Disconnect()

func (*WsClient) Error

func (wsc *WsClient) Error(err error)

func (*WsClient) GetClientId

func (wsc *WsClient) GetClientId() ClientId

func (*WsClient) GetRemote

func (wsc *WsClient) GetRemote() *Instance

func (*WsClient) GetShortId

func (wsc *WsClient) GetShortId() ClientId

func (*WsClient) GetSubscriptions

func (wsc *WsClient) GetSubscriptions() iter.Seq[Subscription]

func (*WsClient) GetUser

func (wsc *WsClient) GetUser() *User

func (*WsClient) IsOpen

func (wsc *WsClient) IsOpen() bool

func (*WsClient) PushFileUpdate

func (wsc *WsClient) PushFileUpdate(updatedFile *fileTree.WeblensFileImpl, media *Media)

func (*WsClient) PushPoolUpdate

func (wsc *WsClient) PushPoolUpdate(pool task.Pool, event string, result task.TaskResult)

func (*WsClient) PushTaskUpdate

func (wsc *WsClient) PushTaskUpdate(task *task.Task, event string, result task.TaskResult)

func (*WsClient) PushWeblensEvent

func (wsc *WsClient) PushWeblensEvent(eventTag string, content ...WsC)

func (*WsClient) Raw

func (wsc *WsClient) Raw(msg any) error

func (*WsClient) ReadOne

func (wsc *WsClient) ReadOne() (int, []byte, error)

func (*WsClient) RemoveSubscription

func (wsc *WsClient) RemoveSubscription(key SubId)

func (*WsClient) Send

func (wsc *WsClient) Send(msg WsResponseInfo) error

func (*WsClient) SubLock

func (wsc *WsClient) SubLock()

func (*WsClient) SubUnlock

func (wsc *WsClient) SubUnlock()

type WsR

type WsR interface {
	GetKey() SubId
	Action() WsAction
}

WsR WebSocket Request interface

type WsRequestInfo

type WsRequestInfo struct {
	Action  WsAction `json:"action"`
	SentAt  int64    `json:"sentAt"`
	Content string   `json:"content"`
}

type WsResponseInfo

type WsResponseInfo struct {
	EventTag      string     `json:"eventTag"`
	SubscribeKey  SubId      `json:"subscribeKey"`
	TaskType      string     `json:"taskType,omitempty"`
	Content       WsC        `json:"content"`
	Error         string     `json:"error,omitempty"`
	BroadcastType WsAction   `json:"broadcastType,omitempty"`
	RelaySource   InstanceId `json:"relaySource,omitempty"`
	SentTime      int64      `json:"sentTime,omitempty"`
}

type ZipMeta

type ZipMeta struct {
	Files     []*fileTree.WeblensFileImpl
	Share     *FileShare
	Requester *User

	FileService FileService
	Caster      FileCaster
}

func (ZipMeta) FormatToResult

func (m ZipMeta) FormatToResult() task.TaskResult

func (ZipMeta) JobName

func (m ZipMeta) JobName() string

func (ZipMeta) MetaString

func (m ZipMeta) MetaString() string

func (ZipMeta) Verify

func (m ZipMeta) Verify() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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