mirror of
https://github.com/actix/examples
synced 2024-11-23 14:31:07 +01:00
upgrade to alpha4
This commit is contained in:
parent
86e0f3e02c
commit
815e34f32d
@ -7,7 +7,7 @@ workspace = ".."
|
||||
|
||||
[dependencies]
|
||||
actix = "0.8.0-alpha.2"
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
actix-redis = { git="https://github.com/actix/actix-redis.git" }
|
||||
futures = "0.1.23"
|
||||
redis-async = "0.4.0"
|
||||
|
@ -6,9 +6,9 @@ workspace = ".."
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-files = "0.1.0-alpha.2"
|
||||
actix-session = "0.1.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
actix-files = "0.1.0-alpha.4"
|
||||
actix-session = "0.1.0-alpha.4"
|
||||
dotenv = "0.13.0"
|
||||
env_logger = "0.5.10"
|
||||
futures = "0.1.22"
|
||||
|
@ -7,7 +7,7 @@ workspace = ".."
|
||||
|
||||
[dependencies]
|
||||
actix-rt = "0.2"
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
|
||||
dotenv = "0.10"
|
||||
env_logger = "0.5"
|
||||
|
@ -7,7 +7,7 @@ workspace = ".."
|
||||
|
||||
[dependencies]
|
||||
actix-rt = "0.2"
|
||||
actix-web = { version="1.0.0-alpha.3", features=["ssl"] }
|
||||
actix-web = { version="1.0.0-alpha.4", features=["ssl"] }
|
||||
|
||||
futures = "0.1"
|
||||
serde = "1.0.43"
|
||||
|
@ -7,9 +7,9 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-rt = "0.2"
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-files = "0.1.0-alpha.2"
|
||||
actix-session = "0.1.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
actix-files = "0.1.0-alpha.4"
|
||||
actix-session = "0.1.0-alpha.4"
|
||||
|
||||
futures = "0.1.25"
|
||||
env_logger = "0.5"
|
||||
|
@ -6,5 +6,5 @@ edition = "2018"
|
||||
workspace = ".."
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
env_logger = "0.6"
|
||||
|
@ -6,8 +6,8 @@ workspace = ".."
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-session = "0.1.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
actix-session = "0.1.0-alpha.4"
|
||||
|
||||
futures = "0.1"
|
||||
time = "0.1"
|
||||
|
@ -6,7 +6,7 @@ workspace = ".."
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
|
||||
bytes = "0.4"
|
||||
env_logger = "0.6"
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
workspace = ".."
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
|
||||
derive_more = "0.14.0"
|
||||
futures = "0.1.23"
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
workspace = ".."
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
|
@ -6,5 +6,5 @@ workspace = ".."
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
env_logger = "0.6"
|
||||
|
@ -7,7 +7,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-rt = "0.2"
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
|
||||
clap = "2.32.0"
|
||||
futures = "0.1.25"
|
||||
|
@ -15,7 +15,7 @@ path = "src/server.rs"
|
||||
|
||||
[dependencies]
|
||||
actix-rt = "0.2"
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
|
||||
env_logger = "0.5"
|
||||
futures = "0.1"
|
||||
|
@ -6,7 +6,7 @@ workspace = ".."
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
|
||||
bytes = "0.4"
|
||||
futures = "0.1"
|
||||
|
@ -6,7 +6,7 @@ workspace = ".."
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
env_logger = "0.6"
|
||||
futures = "0.1"
|
||||
serde = "1.0"
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
workspace = ".."
|
||||
|
||||
[dependencies]
|
||||
actix-service = "0.3.3"
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-service = "0.3.6"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
futures = "0.1.25"
|
||||
env_logger = "0.6"
|
@ -10,7 +10,8 @@ name = "multipart"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
actix-multipart = { git="https://github.com/actix/actix-web.git" }
|
||||
|
||||
env_logger = "0.6"
|
||||
futures = "0.1.25"
|
||||
|
@ -1,16 +1,18 @@
|
||||
use std::cell::Cell;
|
||||
use std::fs;
|
||||
use std::fs::{self, File};
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
use actix_multipart::{Field, Item, Multipart, MultipartError};
|
||||
use actix_web::{error, middleware, web, App, Error, HttpResponse, HttpServer};
|
||||
use futures::future::{err, Either};
|
||||
use futures::future::{err, ok, Either};
|
||||
use futures::{Future, Stream};
|
||||
|
||||
pub struct AppState {
|
||||
pub counter: Cell<usize>,
|
||||
}
|
||||
|
||||
pub fn save_file(field: web::MultipartField) -> impl Future<Item = i64, Error = Error> {
|
||||
pub fn save_file(field: Field) -> impl Future<Item = i64, Error = Error> {
|
||||
let file_path_string = "upload.png";
|
||||
let mut file = match fs::File::create(file_path_string) {
|
||||
Ok(file) => file,
|
||||
@ -24,7 +26,7 @@ pub fn save_file(field: web::MultipartField) -> impl Future<Item = i64, Error =
|
||||
.map(|_| acc + bytes.len() as i64)
|
||||
.map_err(|e| {
|
||||
println!("file.write_all failed: {:?}", e);
|
||||
error::MultipartError::Payload(error::PayloadError::Io(e))
|
||||
MultipartError::Payload(error::PayloadError::Io(e))
|
||||
})
|
||||
})
|
||||
.map_err(|e| {
|
||||
@ -34,12 +36,10 @@ pub fn save_file(field: web::MultipartField) -> impl Future<Item = i64, Error =
|
||||
)
|
||||
}
|
||||
|
||||
pub fn handle_multipart_item(
|
||||
item: web::MultipartItem,
|
||||
) -> Box<Stream<Item = i64, Error = Error>> {
|
||||
pub fn handle_multipart_item(item: Item) -> Box<Stream<Item = i64, Error = Error>> {
|
||||
match item {
|
||||
web::MultipartItem::Field(field) => Box::new(save_file(field).into_stream()),
|
||||
web::MultipartItem::Nested(mp) => Box::new(
|
||||
Item::Field(field) => Box::new(save_file(field).into_stream()),
|
||||
Item::Nested(mp) => Box::new(
|
||||
mp.map_err(error::ErrorInternalServerError)
|
||||
.map(handle_multipart_item)
|
||||
.flatten(),
|
||||
@ -48,21 +48,46 @@ pub fn handle_multipart_item(
|
||||
}
|
||||
|
||||
pub fn upload(
|
||||
multipart: web::Multipart,
|
||||
multipart: Multipart,
|
||||
counter: web::Data<Cell<usize>>,
|
||||
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||
counter.set(counter.get() + 1);
|
||||
println!("{:?}", counter.get());
|
||||
|
||||
multipart
|
||||
.map_err(error::ErrorInternalServerError)
|
||||
.map(handle_multipart_item)
|
||||
.flatten()
|
||||
.from_err::<Error>()
|
||||
.take(1)
|
||||
.collect()
|
||||
.map(|sizes| HttpResponse::Ok().json(sizes))
|
||||
.map_err(|e| {
|
||||
println!("failed: {}", e);
|
||||
e
|
||||
.map(|v| v.into_iter().next().expect("wat"))
|
||||
.and_then(|item| match item {
|
||||
Item::Field(field) => {
|
||||
if let Some(disp) = field.content_disposition() {
|
||||
if let Some(disp_fn) = disp.get_filename() {
|
||||
if let Some(ext) = Path::new(&disp_fn).extension() {
|
||||
let fname = format!("{}.{}", 10, ext.to_string_lossy());
|
||||
let pth = Path::new("./").join(&fname);
|
||||
if let Ok(mut ff) = File::create(&pth) {
|
||||
return Either::A(
|
||||
field
|
||||
.from_err::<Error>()
|
||||
.map(move |c| ff.write_all(&c))
|
||||
.fold((), |_, _| Ok::<_, Error>(()))
|
||||
//.finish()
|
||||
.and_then(move |_| {
|
||||
ok(HttpResponse::Created().body(format!(
|
||||
"{{\"path\": \"{}\"}}",
|
||||
fname
|
||||
)))
|
||||
})
|
||||
.or_else(|_| {
|
||||
ok(HttpResponse::InternalServerError()
|
||||
.finish())
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Either::B(ok(HttpResponse::BadRequest().finish()))
|
||||
}
|
||||
Item::Nested(_) => Either::B(ok(HttpResponse::BadRequest().finish())),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -13,4 +13,4 @@ derive_more = "0.14"
|
||||
prost = "0.2.0"
|
||||
prost-derive = "0.2.0"
|
||||
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
|
@ -7,7 +7,7 @@ workspace = ".."
|
||||
|
||||
[dependencies]
|
||||
actix-rt = "0.2"
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
|
||||
futures = "0.1"
|
||||
env_logger = "0.6"
|
||||
|
@ -7,7 +7,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix = "0.8.0-alpha.2"
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-session = "0.1.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
actix-session = "0.1.0-alpha.4"
|
||||
actix-redis = { git = "https://github.com/actix/actix-redis.git", features = ["web"] }
|
||||
env_logger = "0.6"
|
||||
|
@ -12,5 +12,5 @@ path = "src/main.rs"
|
||||
[dependencies]
|
||||
env_logger = "0.5"
|
||||
rustls = "0.15"
|
||||
actix-web = { version = "1.0.0-alpha.3", features=["rust-tls"] }
|
||||
actix-files = "0.1.0-alpha.2"
|
||||
actix-web = { version = "1.0.0-alpha.4", features=["rust-tls"] }
|
||||
actix-files = "0.1.0-alpha.4"
|
||||
|
@ -8,8 +8,8 @@ workspace = ".."
|
||||
[dependencies]
|
||||
actix = { version = "0.8.0-alpha.2", features = ["http"] }
|
||||
actix-rt = "0.2.2"
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-files = "0.1.0-alpha.2"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
actix-files = "0.1.0-alpha.4"
|
||||
|
||||
bcrypt = "0.2.1"
|
||||
chrono = { version = "0.4.6", features = ["serde"] }
|
||||
|
@ -1,6 +1,6 @@
|
||||
use actix::{Handler, Message};
|
||||
use actix_web::{dev::ServiceFromRequest, Error};
|
||||
use actix_web::{middleware::identity::Identity, FromRequest, HttpRequest};
|
||||
use actix_web::{dev::Payload, Error, HttpRequest};
|
||||
use actix_web::{middleware::identity::Identity, FromRequest};
|
||||
use bcrypt::verify;
|
||||
use diesel::prelude::*;
|
||||
|
||||
@ -50,8 +50,8 @@ impl<P> FromRequest<P> for LoggedUser {
|
||||
type Error = Error;
|
||||
type Future = Result<LoggedUser, Error>;
|
||||
|
||||
fn from_request(req: &mut ServiceFromRequest<P>) -> Self::Future {
|
||||
if let Some(identity) = Identity::from_request(req)?.identity() {
|
||||
fn from_request(req: &HttpRequest, pl: &mut Payload<P>) -> Self::Future {
|
||||
if let Some(identity) = Identity::from_request(req, pl)?.identity() {
|
||||
let user: SlimUser = decode_token(&identity)?;
|
||||
return Ok(user as LoggedUser);
|
||||
}
|
||||
|
@ -6,6 +6,6 @@ workspace = ".."
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
futures = "0.1.25"
|
||||
env_logger = "0.6"
|
||||
|
@ -9,5 +9,5 @@ edition = "2018"
|
||||
futures = "0.1"
|
||||
env_logger = "0.5"
|
||||
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-files = "0.1.0-alpha.2"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
actix-files = "0.1.0-alpha.4"
|
||||
|
@ -6,8 +6,7 @@ workspace = ".."
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
#askama = { version = "0.8", features = ["with-actix-web"] }
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
env_logger = "0.6"
|
||||
askama = "0.8"
|
||||
|
||||
|
@ -8,4 +8,4 @@ edition = "2018"
|
||||
[dependencies]
|
||||
env_logger = "0.6"
|
||||
tera = "0.11"
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
|
@ -12,7 +12,7 @@ env_logger = "0.6"
|
||||
|
||||
yarte = { version = "0.2", features=["with-actix-web"] }
|
||||
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
|
||||
[build-dependencies]
|
||||
yarte = { version = "0.2", features=["with-actix-web"] }
|
||||
@ -20,4 +20,4 @@ yarte = { version = "0.2", features=["with-actix-web"] }
|
||||
[dev-dependencies]
|
||||
bytes = "0.4"
|
||||
actix-http-test = "0.1.0-alpha.3"
|
||||
actix-http = "0.1.0-alpha.3"
|
||||
actix-http = "0.1.0-alpha.4"
|
||||
|
@ -11,6 +11,6 @@ path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
actix-rt = "0.2"
|
||||
actix-web = { version="1.0.0-alpha.3", features=["ssl"] }
|
||||
actix-web = { version="1.0.0-alpha.4", features=["ssl"] }
|
||||
env_logger = "0.6"
|
||||
openssl = { version="0.10" }
|
||||
|
@ -6,7 +6,7 @@ workspace = "../../"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
|
@ -11,9 +11,9 @@ path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
actix = "0.8.0-alpha.2"
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web-actors = "1.0.0-alpha.3"
|
||||
actix-files = "0.1.0-alpha.2"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
actix-web-actors = "1.0.0-alpha.2"
|
||||
actix-files = "0.1.0-alpha.4"
|
||||
|
||||
rand = "0.6"
|
||||
bytes = "0.4"
|
||||
|
@ -15,9 +15,9 @@ path = "src/client.rs"
|
||||
|
||||
[dependencies]
|
||||
actix = "0.8.0-alpha.2"
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
actix-web-actors = "1.0.0-alpha.3"
|
||||
actix-files = "0.1.0-alpha.2"
|
||||
actix-files = "0.1.0-alpha.4"
|
||||
|
||||
rand = "0.6"
|
||||
bytes = "0.4"
|
||||
|
@ -15,9 +15,9 @@ path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
actix = "0.8.0-alpha.2"
|
||||
actix-web = "1.0.0-alpha.3"
|
||||
actix-web = "1.0.0-alpha.4"
|
||||
actix-web-actors = "1.0.0-alpha.3"
|
||||
actix-files = "0.1.0-alpha.2"
|
||||
actix-files = "0.1.0-alpha.4"
|
||||
env_logger = "0.6"
|
||||
futures = "0.1"
|
||||
bytes = "0.4"
|
Loading…
Reference in New Issue
Block a user