summaryrefslogtreecommitdiff
path: root/internal/model
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-03 21:06:08 +0300
committerPaul Buetow <paul@buetow.org>2026-05-03 21:06:08 +0300
commitd7a25aaf44641efb7d57975b13413112bf9c9977 (patch)
treeac15d39e78ced46dbe9a702ee82e91103e01fe44 /internal/model
parentc4de92da38bb12154aa9b2e8847dcce79a2cfae6 (diff)
Backfill godoc for task 1
Diffstat (limited to 'internal/model')
-rw-r--r--internal/model/media.go19
-rw-r--r--internal/model/scan.go23
2 files changed, 27 insertions, 15 deletions
diff --git a/internal/model/media.go b/internal/model/media.go
index 74492c1..f242746 100644
--- a/internal/model/media.go
+++ b/internal/model/media.go
@@ -7,8 +7,11 @@ import "time"
type MediaType string
const (
+ // MediaTypeVideo identifies video files.
MediaTypeVideo MediaType = "video"
+ // MediaTypeAudio identifies audio files.
MediaTypeAudio MediaType = "audio"
+ // MediaTypeImage identifies image files.
MediaTypeImage MediaType = "image"
)
@@ -16,7 +19,9 @@ const (
type Role string
const (
- RoleOwner Role = "owner"
+ // RoleOwner allows browsing, uploading, deleting and thumbnail updates.
+ RoleOwner Role = "owner"
+ // RoleViewer allows browsing and playback.
RoleViewer Role = "viewer"
)
@@ -31,12 +36,12 @@ type User struct {
// Set represents a top-level media collection (a directory under MEDIA_ROOT).
type Set struct {
- ID int64 `json:"id"`
- Name string `json:"name"`
- RootPath string `json:"root_path"`
- CoverThumbnailPath string `json:"cover_thumbnail_path"`
- Permissions []SetPermission `json:"permissions"`
- CreatedAt time.Time `json:"created_at"`
+ ID int64 `json:"id"`
+ Name string `json:"name"`
+ RootPath string `json:"root_path"`
+ CoverThumbnailPath string `json:"cover_thumbnail_path"`
+ Permissions []SetPermission `json:"permissions"`
+ CreatedAt time.Time `json:"created_at"`
}
// SetPermission grants a user access to a set.
diff --git a/internal/model/scan.go b/internal/model/scan.go
index 675b5dd..7fb4e8d 100644
--- a/internal/model/scan.go
+++ b/internal/model/scan.go
@@ -4,16 +4,17 @@ import "sync"
// ScanProgress tracks the state of an in-progress or recently completed scan.
type ScanProgress struct {
- mu sync.RWMutex
- Running bool `json:"running"`
- CurrentSet string `json:"current_set,omitempty"`
- SetsTotal int `json:"sets_total"`
- SetsDone int `json:"sets_done"`
- FilesTotal int `json:"files_total"`
- FilesDone int `json:"files_done"`
- LastError string `json:"last_error,omitempty"`
+ mu sync.RWMutex
+ Running bool `json:"running"`
+ CurrentSet string `json:"current_set,omitempty"`
+ SetsTotal int `json:"sets_total"`
+ SetsDone int `json:"sets_done"`
+ FilesTotal int `json:"files_total"`
+ FilesDone int `json:"files_done"`
+ LastError string `json:"last_error,omitempty"`
}
+// Start marks a scan running and resets counters for the given set count.
func (p *ScanProgress) Start(setsTotal int) {
p.mu.Lock()
defer p.mu.Unlock()
@@ -25,30 +26,35 @@ func (p *ScanProgress) Start(setsTotal int) {
p.LastError = ""
}
+// SetCurrentSet records the set currently being scanned.
func (p *ScanProgress) SetCurrentSet(name string) {
p.mu.Lock()
defer p.mu.Unlock()
p.CurrentSet = name
}
+// IncrementFile increments the completed file count.
func (p *ScanProgress) IncrementFile() {
p.mu.Lock()
defer p.mu.Unlock()
p.FilesDone++
}
+// SetFilesTotal records the number of files to scan.
func (p *ScanProgress) SetFilesTotal(total int) {
p.mu.Lock()
defer p.mu.Unlock()
p.FilesTotal = total
}
+// IncrementSet increments the completed set count.
func (p *ScanProgress) IncrementSet() {
p.mu.Lock()
defer p.mu.Unlock()
p.SetsDone++
}
+// Done marks the scan complete and records an error message when provided.
func (p *ScanProgress) Done(err error) {
p.mu.Lock()
defer p.mu.Unlock()
@@ -59,6 +65,7 @@ func (p *ScanProgress) Done(err error) {
}
}
+// Copy returns a race-safe snapshot of the scan progress.
func (p *ScanProgress) Copy() ScanProgress {
p.mu.RLock()
defer p.mu.RUnlock()