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: response type for naifu #253

Merged
merged 3 commits into from
Jun 9, 2024
Merged

Conversation

MieMieMieeeee
Copy link
Contributor

@MieMieMieeeee MieMieMieeeee commented Jun 7, 2024

修复一个关于naifu的bug

  • 将naifu的回复类型设定为text类型
    • 在使用naifu时,response是text/event-stream类型,但是目前的代码会期待一个json的返回类型从而造成以下错误
    • @_`36NI9EFAB(K81)JDI$)S

Copy link
Member

@shigma shigma left a comment

Choose a reason for hiding this comment

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

我没有 naifu 环境,如果可以的话需要你自己测试一下。确认无误后可以合并。

@MieMieMieeeee
Copy link
Contributor Author

我没有 naifu 环境,如果可以的话需要你自己测试一下。确认无误后可以合并。

用naifu测试过了

  • ※以下的测试环境里在修改处前后加了几句logger.debug
    • image
    • image

@MieMieMieeeee
Copy link
Contributor Author

MieMieMieeeee commented Jun 7, 2024

但是似乎仍然存在一个bug,在sandbox和adapter-red下测试没问题,
可是在adapter-discord的环境下,由于图片的filename里不包含扩展名,导致在discord下无法正常显示

@MieMieMieeeee
Copy link
Contributor Author

MieMieMieeeee commented Jun 7, 2024

添加了一个修改

  • 从naifu的response获取图片data的时候移除最后的一些换行符
    • 理由:用text获取naifu返回的response的时候,字符串最后会有一些换行符
      这些换行符导致像@satorijs/adapter-discord这样的adapter通过@cordisjs/plugin-http的file函数获取图片时,无法正确匹配Data URI。
      从而导致@cordisjs/plugin-http的file函数试图从Data URI获取filename,最终获得一个没有扩展名的filename。
      所以当discord上传一个没有图片扩展名的文件时不会正确显示

src/index.ts Outdated
Comment on lines 470 to 472
if (config.type === 'naifu') {
return forceDataPrefix(res.data?.trimEnd().slice(27))
}
Copy link
Member

Choose a reason for hiding this comment

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

俺感觉这个逻辑可以合并到下面一行,直接统一 trimEnd 就行。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

@shigma shigma merged commit 39cdf4f into koishijs:main Jun 9, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants