add mobile putaway web server with camera/upload capture

This commit is contained in:
Ian Gulliver
2026-05-31 14:51:18 -07:00
parent e22d512be7
commit e70dce275c
3 changed files with 227 additions and 10 deletions
+22 -10
View File
@@ -52,15 +52,12 @@ const spoolURLPrefix = "https://spooldb.com/s/"
func main() {
verbose := flag.Bool("v", false, "verbose: log each event's start/end with timings to stderr")
dryRun := flag.Bool("n", false, "dry run: read and report, but do not write weight changes back to the site")
serveAddr := flag.String("serve", "", "run the mobile putaway web server at this address (e.g. :8080)")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [-v] [-n] <image>...\n", os.Args[0])
fmt.Fprintf(os.Stderr, "usage: %s [-v] [-n] [-serve addr] <image>...\n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() < 1 {
flag.Usage()
os.Exit(2)
}
level := slog.LevelInfo
if *verbose {
@@ -77,6 +74,17 @@ func main() {
sp := &spoolSync{}
defer sp.close()
if *serveAddr != "" {
if err := serve(*serveAddr, auth, sp, *dryRun); err != nil {
fail("serve: %v", err)
}
return
}
if flag.NArg() < 1 {
flag.Usage()
os.Exit(2)
}
results := make([]result, 0, flag.NArg())
for _, path := range flag.Args() {
results = append(results, processImage(path, auth, sp, *dryRun))
@@ -163,14 +171,18 @@ func (s *spoolSync) close() {
// processImage reads one photo, capturing any failure in the result's Error
// field so a single bad image doesn't abort the whole batch.
func processImage(path string, auth claude.Auth, sp *spoolSync, dryRun bool) result {
defer trace("image " + path)()
r := result{Image: path}
img, err := loadImage(path)
if err != nil {
r.Error = fmt.Sprintf("load image: %v", err)
return r
return result{Image: path, Error: fmt.Sprintf("load image: %v", err)}
}
return processImg(img, path, auth, sp, dryRun)
}
// processImg runs the QR + weight + spooldb logic on a decoded image. name is
// just a label for the output (a file path or upload filename).
func processImg(img image.Image, name string, auth claude.Auth, sp *spoolSync, dryRun bool) result {
defer trace("image " + name)()
r := result{Image: name}
url, err := decodeQR(img)
if err != nil {