Skip to content

Commit 37e369a

Browse files
committed
feat(alist_v3): add IntSlice type for JSON unmarshalling
- Add `IntSlice` type to handle both single int and array in JSON. - Modify `MeResp` struct to use `IntSlice` for `Role` field. - Import `encoding/json` for JSON operations.
1 parent 46de9e9 commit 37e369a

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

drivers/alist_v3/types.go

Lines changed: 24 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/alist-org/alist/v3/internal/model"
@@ -72,15 +73,15 @@ 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"`
8485
}
8586

8687
type ArchiveMetaReq struct {
@@ -168,3 +169,17 @@ type DecompressReq struct {
168169
PutIntoNewDir bool `json:"put_into_new_dir"`
169170
SrcDir string `json:"src_dir"`
170171
}
172+
173+
type IntSlice []int
174+
175+
func (s *IntSlice) UnmarshalJSON(data []byte) error {
176+
if len(data) > 0 && data[0] == '[' {
177+
return json.Unmarshal(data, (*[]int)(s))
178+
}
179+
var single int
180+
if err := json.Unmarshal(data, &single); err != nil {
181+
return err
182+
}
183+
*s = []int{single}
184+
return nil
185+
}

0 commit comments

Comments
 (0)