fix(telegram): resolve send_attachment paths in the user's workspace
Nightly Build / build (push) Successful in 8m6s
Nightly Build / build (push) Successful in 8m6s
`send_attachment` handed its `file_path` argument straight to `InputFile::file`, which resolves against the **server process's** working directory. Every path the model can actually have — relative to the user's home, or absolute inside their container — failed the `path.exists()` check, and the one class that didn't (a name that happens to exist next to the binary) would have sent the wrong file. The routing already exists for the fs-tools, so expose it rather than repeat it: `UserFilesApi` (core-api) reads a path in the agent's own vocabulary and is obtained from `UserChannelHandle::files()`, so it is scoped to one user by construction. skald-core implements it over `resolve_view_target` — host mount read directly, container-only path through `docker exec` — holding the `SharedFs` cell rather than a snapshot, so a remount lands without a login. The size cap is checked before the read (a new `exec_fs::size` for the container branch): the point of a cap is to keep an oversized file out of RAM, so checking it afterwards would protect nothing. A photo above `sendPhoto`'s narrower 10 MB ceiling goes out as a document instead of as an API error.
This commit is contained in:
@@ -93,6 +93,20 @@ pub async fn write(container: &str, path: &Path, bytes: &[u8]) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Byte size of a file inside the container — for the callers that must decide
|
||||
/// whether to read it *before* pulling it through the pipe. `wc -c` rather than
|
||||
/// `stat`, so the answer is the same on any of the image's shells.
|
||||
pub async fn size(container: &str, path: &Path) -> Result<u64> {
|
||||
let p = path.to_string_lossy();
|
||||
let raw = sh(container, r#"wc -c < "$1""#, &[&p])
|
||||
.await
|
||||
.with_context(|| format!("Cannot stat file: {p}"))?;
|
||||
String::from_utf8_lossy(&raw)
|
||||
.trim()
|
||||
.parse()
|
||||
.with_context(|| format!("Cannot stat file: {p}"))
|
||||
}
|
||||
|
||||
pub async fn exists(container: &str, path: &Path) -> bool {
|
||||
sh_ok(container, r#"test -e "$1""#, &[&path.to_string_lossy()]).await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user