mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-09-05 23:56:50 +08:00
fix: alist error resp
This commit is contained in:
+1
-1
@@ -18,5 +18,5 @@ func Run(_ *cobra.Command, _ []string) {
|
|||||||
quit := make(chan os.Signal, 1)
|
quit := make(chan os.Signal, 1)
|
||||||
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
||||||
sig := <-quit
|
sig := <-quit
|
||||||
logger.L.Info(sig, "exit")
|
logger.L.Info(sig, ", exit")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,21 @@ func (a *Alist) Init() {
|
|||||||
go refreshToken(reqClient)
|
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 {
|
func (a *Alist) Save(ctx context.Context, filePath, storagePath string) error {
|
||||||
storagePath = path.Join(basePath, storagePath)
|
storagePath = path.Join(basePath, storagePath)
|
||||||
file, err := os.Open(filePath)
|
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 {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return fmt.Errorf("failed to save file to Alist: %s", resp.Status)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user