Add standalone desktop workflow

This commit is contained in:
2026-04-24 11:54:33 +03:00
parent 75c6b928ae
commit 50246ada85
20 changed files with 1068 additions and 306 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"context"
"encoding/json"
"errors"
"flag"
"log"
"net/http"
@@ -33,6 +34,9 @@ func main() {
if err != nil {
log.Fatalf("load config: %v", err)
}
if cfg.MediaPath == "" {
cfg.MediaPath = config.NormalizeMediaPath(*mediaPath)
}
taskStore := task.NewStore()
cp := copier.New(taskStore)
@@ -123,7 +127,7 @@ func main() {
case disk.DiskKnown:
openDiskDB(ev.Info)
if watcherReady && ev.Prev.State != disk.DiskKnown && cfg.AutoCopy {
triggerAutoCopy(cp, cfg, ev.Info, *mediaPath)
triggerAutoCopy(cp, cfg, ev.Info)
}
case disk.DiskForeign:
closeDiskDB(ev.Prev)
@@ -134,6 +138,21 @@ func main() {
w.ProbeNow()
watcherReady = true
probeDisk := func(mountPath string) (disk.DiskInfo, error) {
mountPath = config.NormalizeMediaPath(mountPath)
if mountPath == "" {
return disk.DiskInfo{}, errors.New("mount_path is required")
}
info, err := disk.Probe(mountPath)
if err != nil {
return info, err
}
if info.State == disk.DiskKnown {
openDiskDB(info)
}
return info, nil
}
srv, err := api.New(api.Deps{
Config: cfg,
ConfigPath: *configPath,
@@ -141,8 +160,7 @@ func main() {
Watcher: w,
Copier: cp,
Tasks: taskStore,
MediaPath: *mediaPath,
MountPath: *mountPath,
ProbeDisk: probeDisk,
OnDiskInit: func(mountPath, diskID string) {
openDiskDB(disk.DiskInfo{
State: disk.DiskKnown,
@@ -178,7 +196,7 @@ func main() {
}
}
func triggerAutoCopy(cp *copier.Copier, cfg *config.Config, info disk.DiskInfo, mediaPath string) {
func triggerAutoCopy(cp *copier.Copier, cfg *config.Config, info disk.DiskInfo) {
hasEnabledSources := false
for _, s := range cfg.Sources {
if s.Enabled {
@@ -193,7 +211,7 @@ func triggerAutoCopy(cp *copier.Copier, cfg *config.Config, info disk.DiskInfo,
_, err := cp.Start(context.Background(), copier.Options{
DiskID: info.DiskID,
MountPath: info.MountPath,
MediaPath: mediaPath,
MediaPath: cfg.MediaPath,
DestFolder: cfg.DestFolder,
SourceRules: cfg.Sources,
ReserveFreeGB: cfg.ReserveFreeGB,