Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chaoxing):fix JSON parsing error in content field #5877

Merged
merged 3 commits into from
Jan 14, 2024

Conversation

SoY0ung
Copy link
Contributor

@SoY0ung SoY0ung commented Jan 12, 2024

手机端超星上传小组云盘和网页端上传的文件在获取文件信息(pc/resource/getResourceList&recType=2)时返回的 json 格式不同,sizepuid 字段可能是 string 也可能是 int。

用自定义数据类型 int_strunmarshaler 接口来解决此问题。

Copy link

welcome bot commented Jan 12, 2024

Thanks for opening this pull request! Please check out our contributing guidelines.

@SoY0ung
Copy link
Contributor Author

SoY0ung commented Jan 12, 2024

网页端返回的 json:

{
  "cataid": 123,
  "cfid": 123,
  "content": {
    "...": "...",
    "size": "31415",
    "puid": "12345678",
    "....": "...."
  }
}

手机端返回的 json:

{
  "cataid": 123,
  "cfid": 123,
  "content": {
    "...": "...",    
    "size": 31415,
    "puid": 12345678,
    "....": "...."
  }
}

错误截图:

alistErr

手机端超星上传:

cxmobile

Comment on lines 99 to 116
func (ios *int_str) UnmarshalJSON(data []byte) error {
// 解析为int
var intValue int
if err := json.Unmarshal(data, &intValue); err == nil {
*ios = int_str(intValue)
return nil
}
// 解析string再转int
var strValue string
if err := json.Unmarshal(data, &strValue); err == nil {
intValue, err := strconv.Atoi(strValue)
if err != nil {
return fmt.Errorf("json: cannot unmarshal data into Go struct field .list.content._ of type int_string")
}
*ios = int_str(intValue)
}
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没必要这样转,json字符串和数字就双引号的区别,删除双引号就是数字

intValue, err := strconv.Atoi(string(bytes.Trim(data , "\"")))
if err != nil {
		return err
}
*ios = int_str(intValue)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

谢谢您的指正,已经改进

@SoY0ung
Copy link
Contributor Author

SoY0ung commented Jan 13, 2024

另外,手机端上传的文件没有 fileID 字段,导致无法获取下载链接。

missFileID

由于文件 objectID 字段与 fileID 相同,当 fileID 为空时用 objectID 代替

@xhofe xhofe merged commit f0e8c0e into AlistGo:main Jan 14, 2024
3 checks passed
Copy link

welcome bot commented Jan 14, 2024

Congrats on merging your first pull request! We here at behavior bot are proud of you!

@ChinaStark
Copy link

哥们还是不要叫计算机菜鸟了! formidable opponent!

@SoY0ung SoY0ung deleted the feat_chaoxing_json branch March 3, 2024 04:31
EtherealAO pushed a commit to EtherealAO/alist that referenced this pull request Apr 12, 2024
* fix(chaoxing):fix JSON parsing error in `content` field

* fix(chaoxing): optimizing `UnmarshalJSON` implementation

* fix(chaoxing): use `objectID` when  is empty
EtherealAO pushed a commit to EtherealAO/alist that referenced this pull request Apr 12, 2024
* fix(chaoxing):fix JSON parsing error in `content` field

* fix(chaoxing): optimizing `UnmarshalJSON` implementation

* fix(chaoxing): use `objectID` when  is empty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants