Remove config from FormData trait
This commit is contained in:
parent
c5265d286e
commit
3525bcd09c
|
@ -1,18 +1,17 @@
|
|||
use actix_form_data::{Error, Field, Form, FormData, Multipart, Value};
|
||||
use actix_web::{
|
||||
web::{post, resource},
|
||||
App, HttpResponse, HttpServer,
|
||||
App, HttpRequest, HttpResponse, HttpServer,
|
||||
};
|
||||
use futures_util::stream::StreamExt;
|
||||
|
||||
struct UploadedContent(Value<()>);
|
||||
|
||||
impl FormData for UploadedContent {
|
||||
type Config = ();
|
||||
type Item = ();
|
||||
type Error = Error;
|
||||
|
||||
fn form(_: Option<&Self::Config>) -> Form<Self::Item, Self::Error> {
|
||||
fn form(_: &HttpRequest) -> Form<Self::Item, Self::Error> {
|
||||
Form::new()
|
||||
.field("Hey", Field::text())
|
||||
.field(
|
||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::{
|
|||
http::StatusCode,
|
||||
middleware::Logger,
|
||||
web::{post, resource, Bytes},
|
||||
App, HttpResponse, HttpServer, ResponseError,
|
||||
App, HttpRequest, HttpResponse, HttpServer, ResponseError,
|
||||
};
|
||||
use futures_util::stream::{Stream, StreamExt, TryStreamExt};
|
||||
use std::{
|
||||
|
@ -58,12 +58,12 @@ impl ResponseError for Errors {
|
|||
struct UploadedContent(Value<PathBuf>);
|
||||
|
||||
impl FormData for UploadedContent {
|
||||
type Config = Arc<AtomicUsize>;
|
||||
type Item = PathBuf;
|
||||
type Error = Errors;
|
||||
|
||||
fn form(file_count: Option<&Self::Config>) -> Form<Self::Item, Self::Error> {
|
||||
let file_count = Arc::clone(file_count.expect("Set config"));
|
||||
fn form(req: &HttpRequest) -> Form<Self::Item, Self::Error> {
|
||||
let file_count = req.app_data::<Arc<AtomicUsize>>().expect("Set config");
|
||||
let file_count = Arc::clone(file_count);
|
||||
|
||||
Form::new()
|
||||
.field("Hey", Field::text())
|
||||
|
|
|
@ -6,11 +6,10 @@ use actix_web::{dev::Payload, FromRequest, HttpRequest, ResponseError};
|
|||
use std::{future::Future, pin::Pin};
|
||||
|
||||
pub trait FormData {
|
||||
type Config: 'static;
|
||||
type Item: 'static;
|
||||
type Error: ResponseError + 'static;
|
||||
|
||||
fn form(config: Option<&Self::Config>) -> Form<Self::Item, Self::Error>;
|
||||
fn form(req: &HttpRequest) -> Form<Self::Item, Self::Error>;
|
||||
|
||||
fn extract(value: Value<Self::Item>) -> Result<Self, Self::Error>
|
||||
where
|
||||
|
@ -28,8 +27,7 @@ where
|
|||
|
||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
||||
let multipart = actix_multipart::Multipart::new(req.headers(), payload.take());
|
||||
let config = req.app_data::<T::Config>();
|
||||
let form = T::form(config);
|
||||
let form = T::form(req);
|
||||
|
||||
Box::pin(async move {
|
||||
let uploaded = match handle_multipart(multipart, &form).await {
|
||||
|
|
Loading…
Reference in a new issue