fix: alist error resp

This commit is contained in:
krau
2025-02-01 14:36:08 +08:00
parent f00aa189e3
commit 6c6ee77067
2 changed files with 23 additions and 1 deletions

View File

@@ -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")
}

View File

@@ -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
}