From 6c6ee7706722f182624dc004654e22e58bf0386c Mon Sep 17 00:00:00 2001 From: krau <71133316+krau@users.noreply.github.com> Date: Sat, 1 Feb 2025 14:36:08 +0800 Subject: [PATCH] fix: alist error resp --- cmd/run.go | 2 +- storage/alist/alist.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cmd/run.go b/cmd/run.go index 97f70ae..87c3fd2 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -18,5 +18,5 @@ func Run(_ *cobra.Command, _ []string) { quit := make(chan os.Signal, 1) signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) sig := <-quit - logger.L.Info(sig, "exit") + logger.L.Info(sig, ", exit") } diff --git a/storage/alist/alist.go b/storage/alist/alist.go index 41ea7af..fa590e3 100644 --- a/storage/alist/alist.go +++ b/storage/alist/alist.go @@ -86,6 +86,21 @@ func (a *Alist) Init() { go refreshToken(reqClient) } +type putResponse struct { + Code int `json:"code"` + Message string `json:"message"` + Data struct { + Task struct { + ID string `json:"id"` + Name string `json:"name"` + State int `json:"state"` + Status string `json:"status"` + Progress int `json:"progress"` + Error string `json:"error"` + } `json:"task"` + } `json:"data"` +} + func (a *Alist) Save(ctx context.Context, filePath, storagePath string) error { storagePath = path.Join(basePath, storagePath) file, err := os.Open(filePath) @@ -105,5 +120,12 @@ func (a *Alist) Save(ctx context.Context, filePath, storagePath string) error { if resp.StatusCode != http.StatusOK { return fmt.Errorf("failed to save file to Alist: %s", resp.Status) } + var putResp putResponse + if err := json.Unmarshal(resp.Bytes(), &putResp); err != nil { + return fmt.Errorf("failed to unmarshal put response: %v", err) + } + if putResp.Code != http.StatusOK { + return fmt.Errorf("failed to save file to Alist: %d, %s", putResp.Code, putResp.Message) + } return nil }