Compare commits
5 commits
v0.7.0-bet
...
main
Author | SHA1 | Date | |
---|---|---|---|
asonix | 9ab99f162a | ||
asonix | 298843c31c | ||
asonix | 1c88a70021 | ||
asonix | 5f38d493c6 | ||
asonix | 0d3fd3b19e |
55
.forgejo/workflows/check.yaml
Normal file
55
.forgejo/workflows/check.yaml
Normal file
|
@ -0,0 +1,55 @@
|
|||
on:
|
||||
push:
|
||||
branches:
|
||||
- '*'
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
clippy:
|
||||
runs-on: base-image
|
||||
steps:
|
||||
-
|
||||
name: Checkout actix-form-data
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
-
|
||||
name: Cargo Cache
|
||||
uses: https://git.asonix.dog/asonix/actions/cache-rust-dependencies@main
|
||||
-
|
||||
name: Clippy
|
||||
run: |
|
||||
cargo clippy --no-default-features -- -D warnings
|
||||
|
||||
tests:
|
||||
runs-on: base-image
|
||||
steps:
|
||||
-
|
||||
name: Checkout actix-form-data
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
-
|
||||
name: Cargo Cache
|
||||
uses: https://git.asonix.dog/asonix/actions/cache-rust-dependencies@main
|
||||
-
|
||||
name: Test
|
||||
run: cargo test
|
||||
|
||||
check:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
target:
|
||||
- x86_64-unknown-linux-musl
|
||||
- armv7-unknown-linux-musleabihf
|
||||
- aarch64-unknown-linux-musl
|
||||
runs-on: base-image
|
||||
steps:
|
||||
-
|
||||
name: Checkout actix-form-data
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
-
|
||||
name: Cargo Cache
|
||||
uses: https://git.asonix.dog/asonix/actions/cache-rust-dependencies@main
|
||||
-
|
||||
name: Debug builds
|
||||
run: cargo zigbuild --target ${{ matrix.target }}
|
78
.forgejo/workflows/publish.yaml
Normal file
78
.forgejo/workflows/publish.yaml
Normal file
|
@ -0,0 +1,78 @@
|
|||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*.*.*'
|
||||
|
||||
jobs:
|
||||
clippy:
|
||||
runs-on: base-image
|
||||
steps:
|
||||
-
|
||||
name: Checkout actix-form-data
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
-
|
||||
name: Cargo Cache
|
||||
uses: https://git.asonix.dog/asonix/actions/cache-rust-dependencies@main
|
||||
-
|
||||
name: Clippy
|
||||
run: |
|
||||
cargo clippy --no-default-features -- -D warnings
|
||||
|
||||
tests:
|
||||
runs-on: base-image
|
||||
steps:
|
||||
-
|
||||
name: Checkout actix-form-data
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
-
|
||||
name: Cargo Cache
|
||||
uses: https://git.asonix.dog/asonix/actions/cache-rust-dependencies@main
|
||||
-
|
||||
name: Test
|
||||
run: cargo test
|
||||
|
||||
build:
|
||||
needs:
|
||||
- clippy
|
||||
- tests
|
||||
runs-on: base-image
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
target:
|
||||
- x86_64-unknown-linux-musl
|
||||
- armv7-unknown-linux-musleabihf
|
||||
- aarch64-unknown-linux-musl
|
||||
steps:
|
||||
-
|
||||
name: Checkout actix-form-data
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
-
|
||||
name: Cargo Cache
|
||||
uses: https://git.asonix.dog/asonix/actions/cache-rust-dependencies@main
|
||||
-
|
||||
name: Compile actix-form-data
|
||||
run: cargo zigbuild --target ${{ matrix.target }}
|
||||
|
||||
publish-forgejo:
|
||||
needs: [build]
|
||||
runs-on: base-image
|
||||
steps:
|
||||
- uses: actions/forgejo-release@v1
|
||||
with:
|
||||
direction: upload
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
publish-crate:
|
||||
needs: [build]
|
||||
runs-on: base-image
|
||||
steps:
|
||||
-
|
||||
name: Checkout actix-form-data
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
-
|
||||
name: Cargo Cache
|
||||
uses: https://git.asonix.dog/asonix/actions/cache-rust-dependencies@main
|
||||
-
|
||||
name: Publish Crate
|
||||
run: cargo publish --token ${{ secrets.CRATES_IO_TOKEN }}
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "actix-form-data"
|
||||
description = "Multipart Form Data for Actix Web"
|
||||
version = "0.7.0-beta.5"
|
||||
version = "0.7.0-beta.7"
|
||||
license = "GPL-3.0"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
repository = "https://git.asonix.dog/asonix/actix-form-data.git"
|
||||
|
|
|
@ -11,8 +11,8 @@ impl FormData for UploadedContent {
|
|||
type Item = ();
|
||||
type Error = Error;
|
||||
|
||||
fn form(_: &HttpRequest) -> Form<Self::Item, Self::Error> {
|
||||
Form::new()
|
||||
fn form(_: &HttpRequest) -> Result<Form<Self::Item, Self::Error>, Self::Error> {
|
||||
Ok(Form::new()
|
||||
.field("Hey", Field::text())
|
||||
.field(
|
||||
"Hi",
|
||||
|
@ -29,7 +29,7 @@ impl FormData for UploadedContent {
|
|||
}
|
||||
Ok(()) as Result<(), Error>
|
||||
})),
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
fn extract(value: Value<Self::Item>) -> Result<Self, Self::Error>
|
||||
|
|
|
@ -61,11 +61,11 @@ impl FormData for UploadedContent {
|
|||
type Item = PathBuf;
|
||||
type Error = Errors;
|
||||
|
||||
fn form(req: &HttpRequest) -> Form<Self::Item, Self::Error> {
|
||||
fn form(req: &HttpRequest) -> Result<Form<Self::Item, Self::Error>, Self::Error> {
|
||||
let file_count = req.app_data::<Arc<AtomicUsize>>().expect("Set config");
|
||||
let file_count = Arc::clone(file_count);
|
||||
|
||||
Form::new()
|
||||
Ok(Form::new()
|
||||
.field("Hey", Field::text())
|
||||
.field(
|
||||
"Hi",
|
||||
|
@ -85,7 +85,7 @@ impl FormData for UploadedContent {
|
|||
.map_err(Errors::from)
|
||||
}
|
||||
})),
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
fn extract(value: Value<Self::Item>) -> Result<Self, Self::Error>
|
||||
|
|
|
@ -9,7 +9,7 @@ pub trait FormData {
|
|||
type Item: 'static;
|
||||
type Error: ResponseError + 'static;
|
||||
|
||||
fn form(req: &HttpRequest) -> Form<Self::Item, Self::Error>;
|
||||
fn form(req: &HttpRequest) -> Result<Form<Self::Item, Self::Error>, Self::Error>;
|
||||
|
||||
fn extract(value: Value<Self::Item>) -> Result<Self, Self::Error>
|
||||
where
|
||||
|
@ -27,9 +27,11 @@ where
|
|||
|
||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
||||
let multipart = actix_multipart::Multipart::new(req.headers(), payload.take());
|
||||
let form = Rc::new(T::form(req));
|
||||
let res = T::form(req);
|
||||
|
||||
Box::pin(async move {
|
||||
let form = Rc::new(res?);
|
||||
|
||||
let uploaded = match handle_multipart(multipart, Rc::clone(&form)).await {
|
||||
Ok(Ok(uploaded)) => uploaded,
|
||||
Ok(Err(e)) => return Err(e.into()),
|
||||
|
|
|
@ -38,8 +38,8 @@
|
|||
//! type Item = ();
|
||||
//! type Error = Error;
|
||||
//!
|
||||
//! fn form(_: &HttpRequest) -> Form<Self::Item, Self::Error> {
|
||||
//! Form::new()
|
||||
//! fn form(_: &HttpRequest) -> Result<Form<Self::Item, Self::Error>, Self::Error> {
|
||||
//! Ok(Form::new()
|
||||
//! .field("Hey", Field::text())
|
||||
//! .field(
|
||||
//! "Hi",
|
||||
|
@ -56,7 +56,7 @@
|
|||
//! }
|
||||
//! Ok(()) as Result<(), Error>
|
||||
//! })),
|
||||
//! )
|
||||
//! ))
|
||||
//! }
|
||||
//!
|
||||
//! fn extract(value: Value<Self::Item>) -> Result<Self, Self::Error>
|
||||
|
|
|
@ -28,6 +28,7 @@ use actix_web::web::BytesMut;
|
|||
use std::{collections::HashMap, path::Path, rc::Rc};
|
||||
use streem::IntoStreamer;
|
||||
use tokio::task::JoinSet;
|
||||
use tracing::Instrument;
|
||||
|
||||
fn consolidate<T>(mf: MultipartForm<T>) -> Value<T> {
|
||||
mf.into_iter().fold(
|
||||
|
@ -280,6 +281,8 @@ where
|
|||
|
||||
if !stream_error {
|
||||
while let Some(res) = m.next().await {
|
||||
tracing::trace!("draining multipart field");
|
||||
|
||||
if let Ok(field) = res {
|
||||
let mut stream = field.into_streamer();
|
||||
while stream.next().await.is_some() {
|
||||
|
@ -306,7 +309,7 @@ where
|
|||
if let Some(res) = opt {
|
||||
match res {
|
||||
Ok(field) => {
|
||||
set.spawn_local(handle_stream_field(field, Rc::clone(&form)));
|
||||
set.spawn_local(handle_stream_field(field, Rc::clone(&form)).instrument(tracing::trace_span!("multipart-field")));
|
||||
},
|
||||
Err(e) => {
|
||||
is_closed = true;
|
||||
|
|
Loading…
Reference in a new issue