Skip to content

Commit

Permalink
fix: alist error resp
Browse files Browse the repository at this point in the history
  • Loading branch information
krau committed Feb 1, 2025
1 parent f00aa18 commit 6c6ee77
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
22 changes: 22 additions & 0 deletions storage/alist/alist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

0 comments on commit 6c6ee77

Please sign in to comment.