mirror of https://github.com/Xhofe/alist
fix(chaoxing): JSON parsing error in `content` field (#5877)
* fix(chaoxing):fix JSON parsing error in `content` field * fix(chaoxing): optimizing `UnmarshalJSON` implementation * fix(chaoxing): use `objectID` when is emptypull/5891/head
parent
86b35ae5cf
commit
f0e8c0e886
|
@ -1,7 +1,9 @@
|
||||||
package chaoxing
|
package chaoxing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/internal/model"
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
|
@ -88,44 +90,59 @@ type UserAuth struct {
|
||||||
} `json:"operationAuth"`
|
} `json:"operationAuth"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 手机端学习通上传的文件的json内容(content字段)与网页端上传的有所不同
|
||||||
|
// 网页端json `"puid": 54321, "size": 12345`
|
||||||
|
// 手机端json `"puid": "54321". "size": "12345"`
|
||||||
|
type int_str int
|
||||||
|
|
||||||
|
// json 字符串数字和纯数字解析
|
||||||
|
func (ios *int_str) UnmarshalJSON(data []byte) error {
|
||||||
|
intValue, err := strconv.Atoi(string(bytes.Trim(data, "\"")))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*ios = int_str(intValue)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
Cataid int `json:"cataid"`
|
Cataid int `json:"cataid"`
|
||||||
Cfid int `json:"cfid"`
|
Cfid int `json:"cfid"`
|
||||||
Content struct {
|
Content struct {
|
||||||
Cfid int `json:"cfid"`
|
Cfid int `json:"cfid"`
|
||||||
Pid int `json:"pid"`
|
Pid int `json:"pid"`
|
||||||
FolderName string `json:"folderName"`
|
FolderName string `json:"folderName"`
|
||||||
ShareType int `json:"shareType"`
|
ShareType int `json:"shareType"`
|
||||||
Preview string `json:"preview"`
|
Preview string `json:"preview"`
|
||||||
Filetype string `json:"filetype"`
|
Filetype string `json:"filetype"`
|
||||||
PreviewURL string `json:"previewUrl"`
|
PreviewURL string `json:"previewUrl"`
|
||||||
IsImg bool `json:"isImg"`
|
IsImg bool `json:"isImg"`
|
||||||
ParentPath string `json:"parentPath"`
|
ParentPath string `json:"parentPath"`
|
||||||
Icon string `json:"icon"`
|
Icon string `json:"icon"`
|
||||||
Suffix string `json:"suffix"`
|
Suffix string `json:"suffix"`
|
||||||
Duration int `json:"duration"`
|
Duration int `json:"duration"`
|
||||||
Pantype string `json:"pantype"`
|
Pantype string `json:"pantype"`
|
||||||
Puid int `json:"puid"`
|
Puid int_str `json:"puid"`
|
||||||
Filepath string `json:"filepath"`
|
Filepath string `json:"filepath"`
|
||||||
Crc string `json:"crc"`
|
Crc string `json:"crc"`
|
||||||
Isfile bool `json:"isfile"`
|
Isfile bool `json:"isfile"`
|
||||||
Residstr string `json:"residstr"`
|
Residstr string `json:"residstr"`
|
||||||
ObjectID string `json:"objectId"`
|
ObjectID string `json:"objectId"`
|
||||||
Extinfo string `json:"extinfo"`
|
Extinfo string `json:"extinfo"`
|
||||||
Thumbnail string `json:"thumbnail"`
|
Thumbnail string `json:"thumbnail"`
|
||||||
Creator int `json:"creator"`
|
Creator int `json:"creator"`
|
||||||
ResTypeValue int `json:"resTypeValue"`
|
ResTypeValue int `json:"resTypeValue"`
|
||||||
UploadDateFormat string `json:"uploadDateFormat"`
|
UploadDateFormat string `json:"uploadDateFormat"`
|
||||||
DisableOpt bool `json:"disableOpt"`
|
DisableOpt bool `json:"disableOpt"`
|
||||||
DownPath string `json:"downPath"`
|
DownPath string `json:"downPath"`
|
||||||
Sort int `json:"sort"`
|
Sort int `json:"sort"`
|
||||||
Topsort int `json:"topsort"`
|
Topsort int `json:"topsort"`
|
||||||
Restype string `json:"restype"`
|
Restype string `json:"restype"`
|
||||||
Size int `json:"size"`
|
Size int_str `json:"size"`
|
||||||
UploadDate string `json:"uploadDate"`
|
UploadDate string `json:"uploadDate"`
|
||||||
FileSize string `json:"fileSize"`
|
FileSize string `json:"fileSize"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
FileID string `json:"fileId"`
|
FileID string `json:"fileId"`
|
||||||
} `json:"content"`
|
} `json:"content"`
|
||||||
CreatorID int `json:"creatorId"`
|
CreatorID int `json:"creatorId"`
|
||||||
DesID string `json:"des_id"`
|
DesID string `json:"des_id"`
|
||||||
|
@ -204,7 +221,6 @@ type UploadFileDataRsp struct {
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type UploadDoneParam struct {
|
type UploadDoneParam struct {
|
||||||
Cataid string `json:"cataid"`
|
Cataid string `json:"cataid"`
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
|
|
|
@ -79,7 +79,7 @@ func (d *ChaoXing) GetFiles(parent string) ([]File, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if resp.Result != 1 {
|
if resp.Result != 1 {
|
||||||
msg:=fmt.Sprintf("error code is:%d", resp.Result)
|
msg := fmt.Sprintf("error code is:%d", resp.Result)
|
||||||
return nil, errors.New(msg)
|
return nil, errors.New(msg)
|
||||||
}
|
}
|
||||||
if len(resp.List) > 0 {
|
if len(resp.List) > 0 {
|
||||||
|
@ -97,8 +97,12 @@ func (d *ChaoXing) GetFiles(parent string) ([]File, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(resps.List) > 0 {
|
for _, file := range resps.List {
|
||||||
files = append(files, resps.List...)
|
// 手机端超星上传的文件没有fileID字段,但ObjectID与fileID相同,可代替
|
||||||
|
if file.Content.FileID == "" {
|
||||||
|
file.Content.FileID = file.Content.ObjectID
|
||||||
|
}
|
||||||
|
files = append(files, file)
|
||||||
}
|
}
|
||||||
return files, nil
|
return files, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue