|
1 | 1 | package alist |
2 | 2 |
|
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | +) |
| 6 | + |
3 | 7 | type AlistResponse[T any] struct { |
4 | 8 | Code int64 `json:"code"` // 状态码 |
5 | 9 | Data T `json:"data"` // data |
@@ -29,13 +33,33 @@ type FsGetData struct { |
29 | 33 | } |
30 | 34 |
|
31 | 35 | type UserInfoData struct { |
32 | | - BasePath string `json:"base_path"` // 根目录 |
33 | | - Disabled bool `json:"disabled"` // 是否禁用 |
34 | | - ID int64 `json:"id"` // id |
35 | | - Otp bool `json:"otp"` // 是否开启二步验证 |
36 | | - Password string `json:"password"` // 密码 |
37 | | - Permission int64 `json:"permission"` // 权限 |
38 | | - Role int64 `json:"role"` // 角色 |
39 | | - SsoID string `json:"sso_id"` // sso id |
40 | | - Username string `json:"username"` // 用户名 |
| 36 | + BasePath string `json:"base_path"` // 根目录 |
| 37 | + Disabled bool `json:"disabled"` // 是否禁用 |
| 38 | + ID int64 `json:"id"` // id |
| 39 | + Otp bool `json:"otp"` // 是否开启二步验证 |
| 40 | + Password string `json:"password"` // 密码 |
| 41 | + Permission int64 `json:"permission"` // 权限 |
| 42 | + Role Int64Slice `json:"role"` // 角色 |
| 43 | + SsoID string `json:"sso_id"` // sso id |
| 44 | + Username string `json:"username"` // 用户名 |
| 45 | +} |
| 46 | + |
| 47 | +type Int64Slice []int64 |
| 48 | + |
| 49 | +func (s *Int64Slice) UnmarshalJSON(data []byte) error { |
| 50 | + if len(data) == 0 || string(data) == "null" { |
| 51 | + *s = []int64{} |
| 52 | + return nil |
| 53 | + } |
| 54 | + var single int64 |
| 55 | + if err := json.Unmarshal(data, &single); err == nil { |
| 56 | + *s = []int64{single} |
| 57 | + return nil |
| 58 | + } |
| 59 | + var arr []int64 |
| 60 | + if err := json.Unmarshal(data, &arr); err != nil { |
| 61 | + return err |
| 62 | + } |
| 63 | + *s = arr |
| 64 | + return nil |
41 | 65 | } |
0 commit comments