feat(#1315): hive-forge attachment-get verb - download attachments by uuid or url

This commit is contained in:
damocles 2026-06-04 21:35:21 +02:00 committed by mara
commit 98f96e5435
6 changed files with 118 additions and 3 deletions

View file

@ -197,6 +197,26 @@ impl Client {
Ok(())
}
/// Build the full URL for a Forgejo attachment by UUID.
/// Attachments live at `<base>/attachments/<uuid>`, NOT under
/// `/api/v1/`, so this uses `self.base` directly.
#[must_use]
pub fn attachment_url(&self, uuid: &str) -> String {
format!("{}/attachments/{uuid}", self.base)
}
/// GET a raw (non-API) URL and return the response body as bytes.
/// The client's auth headers are still sent — Forgejo requires them
/// for private attachment downloads. Uses the full URL as-is; the
/// caller is responsible for constructing it (see `attachment_url`).
pub fn get_bytes_raw(&self, url: &str) -> Result<Vec<u8>> {
let resp = self.http.get(url).send().context("GET")?;
let resp = check_status(resp, &format!("GET {url}"))?;
resp.bytes()
.map(|b| b.to_vec())
.with_context(|| format!("read bytes for GET {url}"))
}
/// POST a multipart file upload, returning the parsed response.
/// Used by `attach-issue` / `attach-comment`.
pub fn post_multipart_file(&self, path: &str, file: &std::path::Path) -> Result<Value> {