From b7756756c564fd8307e6e0756ccce3f982264230 Mon Sep 17 00:00:00 2001 From: OpenClaw Agent Date: Wed, 16 Sep 2026 01:57:36 +0800 Subject: [PATCH] feat: add AM search and organized NAS library paths --- .gitignore | 3 +++ main.go | 26 +++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6c7abbb --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +data/ +downloads/ +*.db diff --git a/main.go b/main.go index 53eb589..69412e3 100644 --- a/main.go +++ b/main.go @@ -153,6 +153,30 @@ func (a *App) addTask(c *gin.Context) { a.queue <- t.ID c.JSON(202, t) } +func (a *App) search(c *gin.Context) { + keyword := strings.TrimSpace(c.Query("keyword")) + source := c.DefaultQuery("source", "kw") + if keyword == "" { + c.JSON(400, gin.H{"error": "keyword required"}) + return + } + u, _ := url.Parse(strings.TrimRight(a.cfg.AMAPI, "/") + "/search") + q := u.Query() + q.Set("keyword", keyword) + q.Set("source", source) + q.Set("page", c.DefaultQuery("page", "1")) + q.Set("limit", c.DefaultQuery("limit", "20")) + u.RawQuery = q.Encode() + resp, err := a.httpClient.Get(u.String()) + if err != nil { + c.JSON(502, gin.H{"error": err.Error()}) + return + } + defer resp.Body.Close() + c.Status(resp.StatusCode) + _, _ = io.Copy(c.Writer, resp.Body) +} + func (a *App) listTasks(c *gin.Context) { var ts []Task a.db.Order("id desc").Limit(100).Find(&ts) @@ -267,7 +291,7 @@ func (a *App) upload(t *Task) { return } a.db.Model(t).Updates(map[string]any{"status": "uploading"}) - remote := strings.TrimRight(a.cfg.WebDAVPath, "/") + "/" + safe(t.Artist) + " - " + safe(t.Title) + "." + safe(t.Format) + remote := strings.TrimRight(a.cfg.WebDAVPath, "/") + "/" + safe(t.Artist) + "/" + safe(t.Album) + "/" + safe(t.Title) + "." + safe(t.Format) t.RemotePath = remote client := gowebdav.NewClient(a.cfg.WebDAVURL, a.cfg.WebDAVUser, a.cfg.WebDAVPass) client.SetTimeout(10 * time.Minute)