fix release attachments
This commit is contained in:
parent
79fb779030
commit
a2ff083f71
26
Cargo.lock
generated
26
Cargo.lock
generated
|
@ -413,6 +413,16 @@ version = "0.3.17"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
||||
|
||||
[[package]]
|
||||
name = "mime_guess"
|
||||
version = "2.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
|
||||
dependencies = [
|
||||
"mime",
|
||||
"unicase",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.7.1"
|
||||
|
@ -587,6 +597,7 @@ dependencies = [
|
|||
"js-sys",
|
||||
"log",
|
||||
"mime",
|
||||
"mime_guess",
|
||||
"native-tls",
|
||||
"once_cell",
|
||||
"percent-encoding",
|
||||
|
@ -931,6 +942,15 @@ version = "0.2.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89"
|
||||
dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.13"
|
||||
|
@ -970,6 +990,12 @@ version = "0.2.15"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "want"
|
||||
version = "0.3.1"
|
||||
|
|
|
@ -6,7 +6,7 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
reqwest = { version = "0.11.18", features = ["json"] }
|
||||
reqwest = { version = "0.11.18", features = ["json", "multipart"] }
|
||||
soft_assert = "0.1.1"
|
||||
thiserror = "1.0.43"
|
||||
tokio = { version = "1.29.1", features = ["net"] }
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ async fn repo(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
|
|||
let release_latest = api.latest_release("TestingAdmin", "test").await.wrap_err("failed to find latest release")?;
|
||||
ensure!(release_by_tag == release_latest, "releases not equal");
|
||||
|
||||
let attachment = api.create_release_attachment("TestingAdmin", "test", release.id, "test.txt", b"This is a file!").await.wrap_err("failed to create release attachment")?;
|
||||
let attachment = api.create_release_attachment("TestingAdmin", "test", release.id, "test.txt", b"This is a file!".to_vec()).await.wrap_err("failed to create release attachment")?;
|
||||
api.delete_release_attachment("TestingAdmin", "test", release.id, attachment.id).await.wrap_err("failed to deleted attachment")?;
|
||||
|
||||
api.delete_release("TestingAdmin", "test", release.id).await.wrap_err("failed to delete release")?;
|
||||
|
|
Loading…
Reference in a new issue