fix(astrbot): try the current file API before the legacy one
一些检测仍在等待运行
ci / Portable quality checks (push) Waiting to run
ci / Windows Tauri build (push) Waiting to run

The server was upgraded and now routes /api/v1/files: an unknown
/api/v1 path answers 404 "Not Found" where it previously answered 401,
and both /api/v1/files/content and /api/v1/files/{id}/content answer 401
"Missing API key", which is a route that exists rather than a catch-all.

Order the candidates accordingly. By name first, since that is what a
media frame carries; by id second, because markers already written to
local history hold the id from attachment_saved and can now resolve. The
/api/chat pair moves last, where it still serves a server that has not
been upgraded.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
这个提交存在于:
YokiiroBW 2026-07-27 03:43:12 +08:00
父节点 4063215b0a
当前提交 809f530486

查看文件

@ -492,10 +492,16 @@ impl AstrBotClient {
}
let encoded = urlencoding_username(attachment_id);
let mut last_note = String::new();
// Current AstrBot serves both forms under `/api/v1/files`. By name
// first, because that is what a media frame carries; by id second,
// because markers already stored in history hold the id from
// `attachment_saved`. The `/api/chat/*` pair is what older builds
// exposed, kept last so an un-upgraded server still works.
for path in [
format!("/api/v1/files/content?filename={encoded}"),
format!("/api/v1/files/{encoded}/content"),
format!("/api/chat/get_file?filename={encoded}"),
format!("/api/chat/get_attachment?attachment_id={encoded}"),
format!("/api/v1/files/content?filename={encoded}"),
] {
match self.try_attachment(&path).await? {
Ok(found) => return Ok(found),