feat: add AM search and organized NAS library paths

This commit is contained in:
OpenClaw Agent
2026-09-16 01:57:36 +08:00
parent 356c3273b0
commit b7756756c5
2 changed files with 28 additions and 1 deletions
+25 -1
View File
@@ -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)