Skip to content

Commit e192149

Browse files
authored
fix(drivers/alist_v3): failed to unmarshal MeResp (#1931)
1 parent 0d99e16 commit e192149

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

drivers/alist_v3/types.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package alist_v3
22

33
import (
4+
"encoding/json"
45
"time"
56

67
"github.com/OpenListTeam/OpenList/v4/internal/model"
@@ -72,15 +73,26 @@ type LoginResp struct {
7273
}
7374

7475
type MeResp struct {
75-
Id int `json:"id"`
76-
Username string `json:"username"`
77-
Password string `json:"password"`
78-
BasePath string `json:"base_path"`
79-
Role []int `json:"role"`
80-
Disabled bool `json:"disabled"`
81-
Permission int `json:"permission"`
82-
SsoId string `json:"sso_id"`
83-
Otp bool `json:"otp"`
76+
Id int `json:"id"`
77+
Username string `json:"username"`
78+
Password string `json:"password"`
79+
BasePath string `json:"base_path"`
80+
Role IntSlice `json:"role"`
81+
Disabled bool `json:"disabled"`
82+
Permission int `json:"permission"`
83+
SsoId string `json:"sso_id"`
84+
Otp bool `json:"otp"`
85+
}
86+
87+
type IntSlice []int
88+
89+
func (s *IntSlice) UnmarshalJSON(b []byte) error {
90+
var i int
91+
if json.Unmarshal(b, &i) == nil {
92+
*s = []int{i}
93+
return nil
94+
}
95+
return json.Unmarshal(b, (*[]int)(s))
8496
}
8597

8698
type ArchiveMetaReq struct {

0 commit comments

Comments
 (0)