1
0
Fork 0

fix release attachments

This commit is contained in:
Cyborus 2023-12-11 14:31:52 -05:00
parent 79fb779030
commit a2ff083f71
No known key found for this signature in database
5 changed files with 36 additions and 9 deletions

View file

@ -104,13 +104,13 @@ impl Forgejo {
self.execute(request).await
}
async fn post_form<T: Serialize, U: DeserializeOwned>(
async fn post_multipart<T: DeserializeOwned>(
&self,
path: &str,
body: &T,
) -> Result<U, ForgejoError> {
body: reqwest::multipart::Form,
) -> Result<T, ForgejoError> {
let url = self.url.join("api/v1/").unwrap().join(path).unwrap();
let request = self.client.post(url).form(body).build()?;
let request = self.client.post(url).multipart(body).build()?;
self.execute(request).await
}

View file

@ -140,11 +140,12 @@ impl Forgejo {
repo: &str,
id: u64,
name: &str,
file: &[u8],
file: Vec<u8>,
) -> Result<Attachment, ForgejoError> {
self.post_form(
self.post_multipart(
&format!("repos/{owner}/{repo}/releases/{id}/assets?name={name}"),
&file,
reqwest::multipart::Form::new()
.part("attachment", reqwest::multipart::Part::bytes(file).file_name("file").mime_str("*/*").unwrap()),
)
.await
}