mirror of https://github.com/Xhofe/alist
feat(alist_v3): add IntSlice type for JSON unmarshalling (#9247)
- 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.pull/9249/head v3.48.0
parent
52da07e8a7
commit
85fe4e5bb3
|
@ -1,6 +1,7 @@
|
||||||
package alist_v3
|
package alist_v3
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/internal/model"
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
|
@ -72,15 +73,15 @@ type LoginResp struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type MeResp struct {
|
type MeResp struct {
|
||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
BasePath string `json:"base_path"`
|
BasePath string `json:"base_path"`
|
||||||
Role []int `json:"role"`
|
Role IntSlice `json:"role"`
|
||||||
Disabled bool `json:"disabled"`
|
Disabled bool `json:"disabled"`
|
||||||
Permission int `json:"permission"`
|
Permission int `json:"permission"`
|
||||||
SsoId string `json:"sso_id"`
|
SsoId string `json:"sso_id"`
|
||||||
Otp bool `json:"otp"`
|
Otp bool `json:"otp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArchiveMetaReq struct {
|
type ArchiveMetaReq struct {
|
||||||
|
@ -168,3 +169,17 @@ type DecompressReq struct {
|
||||||
PutIntoNewDir bool `json:"put_into_new_dir"`
|
PutIntoNewDir bool `json:"put_into_new_dir"`
|
||||||
SrcDir string `json:"src_dir"`
|
SrcDir string `json:"src_dir"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type IntSlice []int
|
||||||
|
|
||||||
|
func (s *IntSlice) UnmarshalJSON(data []byte) error {
|
||||||
|
if len(data) > 0 && data[0] == '[' {
|
||||||
|
return json.Unmarshal(data, (*[]int)(s))
|
||||||
|
}
|
||||||
|
var single int
|
||||||
|
if err := json.Unmarshal(data, &single); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*s = []int{single}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue