1
0
mirror of https://github.com/actix/examples synced 2024-11-27 16:02:57 +01:00

upgrade to alpha4

This commit is contained in:
Nikolay Kim 2019-04-07 23:39:45 -07:00
parent 86e0f3e02c
commit 815e34f32d
34 changed files with 97 additions and 72 deletions

View File

@ -7,7 +7,7 @@ workspace = ".."
[dependencies] [dependencies]
actix = "0.8.0-alpha.2" 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" } actix-redis = { git="https://github.com/actix/actix-redis.git" }
futures = "0.1.23" futures = "0.1.23"
redis-async = "0.4.0" redis-async = "0.4.0"

View File

@ -6,9 +6,9 @@ workspace = ".."
edition = "2018" edition = "2018"
[dependencies] [dependencies]
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
actix-files = "0.1.0-alpha.2" actix-files = "0.1.0-alpha.4"
actix-session = "0.1.0-alpha.3" actix-session = "0.1.0-alpha.4"
dotenv = "0.13.0" dotenv = "0.13.0"
env_logger = "0.5.10" env_logger = "0.5.10"
futures = "0.1.22" futures = "0.1.22"

View File

@ -7,7 +7,7 @@ workspace = ".."
[dependencies] [dependencies]
actix-rt = "0.2" actix-rt = "0.2"
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
dotenv = "0.10" dotenv = "0.10"
env_logger = "0.5" env_logger = "0.5"

View File

@ -7,7 +7,7 @@ workspace = ".."
[dependencies] [dependencies]
actix-rt = "0.2" 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" futures = "0.1"
serde = "1.0.43" serde = "1.0.43"

View File

@ -7,9 +7,9 @@ edition = "2018"
[dependencies] [dependencies]
actix-rt = "0.2" actix-rt = "0.2"
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
actix-files = "0.1.0-alpha.2" actix-files = "0.1.0-alpha.4"
actix-session = "0.1.0-alpha.3" actix-session = "0.1.0-alpha.4"
futures = "0.1.25" futures = "0.1.25"
env_logger = "0.5" env_logger = "0.5"

View File

@ -6,5 +6,5 @@ edition = "2018"
workspace = ".." workspace = ".."
[dependencies] [dependencies]
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
env_logger = "0.6" env_logger = "0.6"

View File

@ -6,8 +6,8 @@ workspace = ".."
edition = "2018" edition = "2018"
[dependencies] [dependencies]
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
actix-session = "0.1.0-alpha.3" actix-session = "0.1.0-alpha.4"
futures = "0.1" futures = "0.1"
time = "0.1" time = "0.1"

View File

@ -6,7 +6,7 @@ workspace = ".."
edition = "2018" edition = "2018"
[dependencies] [dependencies]
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
bytes = "0.4" bytes = "0.4"
env_logger = "0.6" env_logger = "0.6"

View File

@ -6,7 +6,7 @@ edition = "2018"
workspace = ".." workspace = ".."
[dependencies] [dependencies]
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
derive_more = "0.14.0" derive_more = "0.14.0"
futures = "0.1.23" futures = "0.1.23"

View File

@ -6,7 +6,7 @@ edition = "2018"
workspace = ".." workspace = ".."
[dependencies] [dependencies]
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
serde = "1.0" serde = "1.0"
serde_derive = "1.0" serde_derive = "1.0"

View File

@ -6,5 +6,5 @@ workspace = ".."
edition = "2018" edition = "2018"
[dependencies] [dependencies]
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
env_logger = "0.6" env_logger = "0.6"

View File

@ -7,7 +7,7 @@ edition = "2018"
[dependencies] [dependencies]
actix-rt = "0.2" actix-rt = "0.2"
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
clap = "2.32.0" clap = "2.32.0"
futures = "0.1.25" futures = "0.1.25"

View File

@ -15,7 +15,7 @@ path = "src/server.rs"
[dependencies] [dependencies]
actix-rt = "0.2" actix-rt = "0.2"
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
env_logger = "0.5" env_logger = "0.5"
futures = "0.1" futures = "0.1"

View File

@ -6,7 +6,7 @@ workspace = ".."
edition = "2018" edition = "2018"
[dependencies] [dependencies]
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
bytes = "0.4" bytes = "0.4"
futures = "0.1" futures = "0.1"

View File

@ -6,7 +6,7 @@ workspace = ".."
edition = "2018" edition = "2018"
[dependencies] [dependencies]
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
env_logger = "0.6" env_logger = "0.6"
futures = "0.1" futures = "0.1"
serde = "1.0" serde = "1.0"

View File

@ -6,7 +6,7 @@ edition = "2018"
workspace = ".." workspace = ".."
[dependencies] [dependencies]
actix-service = "0.3.3" actix-service = "0.3.6"
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
futures = "0.1.25" futures = "0.1.25"
env_logger = "0.6" env_logger = "0.6"

View File

@ -10,7 +10,8 @@ name = "multipart"
path = "src/main.rs" path = "src/main.rs"
[dependencies] [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" env_logger = "0.6"
futures = "0.1.25" futures = "0.1.25"

View File

@ -1,16 +1,18 @@
use std::cell::Cell; use std::cell::Cell;
use std::fs; use std::fs::{self, File};
use std::io::Write; 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 actix_web::{error, middleware, web, App, Error, HttpResponse, HttpServer};
use futures::future::{err, Either}; use futures::future::{err, ok, Either};
use futures::{Future, Stream}; use futures::{Future, Stream};
pub struct AppState { pub struct AppState {
pub counter: Cell<usize>, 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 file_path_string = "upload.png";
let mut file = match fs::File::create(file_path_string) { let mut file = match fs::File::create(file_path_string) {
Ok(file) => file, 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(|_| acc + bytes.len() as i64)
.map_err(|e| { .map_err(|e| {
println!("file.write_all failed: {:?}", e); println!("file.write_all failed: {:?}", e);
error::MultipartError::Payload(error::PayloadError::Io(e)) MultipartError::Payload(error::PayloadError::Io(e))
}) })
}) })
.map_err(|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( pub fn handle_multipart_item(item: Item) -> Box<Stream<Item = i64, Error = Error>> {
item: web::MultipartItem,
) -> Box<Stream<Item = i64, Error = Error>> {
match item { match item {
web::MultipartItem::Field(field) => Box::new(save_file(field).into_stream()), Item::Field(field) => Box::new(save_file(field).into_stream()),
web::MultipartItem::Nested(mp) => Box::new( Item::Nested(mp) => Box::new(
mp.map_err(error::ErrorInternalServerError) mp.map_err(error::ErrorInternalServerError)
.map(handle_multipart_item) .map(handle_multipart_item)
.flatten(), .flatten(),
@ -48,21 +48,46 @@ pub fn handle_multipart_item(
} }
pub fn upload( pub fn upload(
multipart: web::Multipart, multipart: Multipart,
counter: web::Data<Cell<usize>>, counter: web::Data<Cell<usize>>,
) -> impl Future<Item = HttpResponse, Error = Error> { ) -> impl Future<Item = HttpResponse, Error = Error> {
counter.set(counter.get() + 1);
println!("{:?}", counter.get());
multipart multipart
.map_err(error::ErrorInternalServerError) .from_err::<Error>()
.map(handle_multipart_item) .take(1)
.flatten()
.collect() .collect()
.map(|sizes| HttpResponse::Ok().json(sizes)) .map(|v| v.into_iter().next().expect("wat"))
.map_err(|e| { .and_then(|item| match item {
println!("failed: {}", e); Item::Field(field) => {
e 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())),
}) })
} }

View File

@ -13,4 +13,4 @@ derive_more = "0.14"
prost = "0.2.0" prost = "0.2.0"
prost-derive = "0.2.0" prost-derive = "0.2.0"
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"

View File

@ -7,7 +7,7 @@ workspace = ".."
[dependencies] [dependencies]
actix-rt = "0.2" actix-rt = "0.2"
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
futures = "0.1" futures = "0.1"
env_logger = "0.6" env_logger = "0.6"

View File

@ -7,7 +7,7 @@ edition = "2018"
[dependencies] [dependencies]
actix = "0.8.0-alpha.2" actix = "0.8.0-alpha.2"
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
actix-session = "0.1.0-alpha.3" actix-session = "0.1.0-alpha.4"
actix-redis = { git = "https://github.com/actix/actix-redis.git", features = ["web"] } actix-redis = { git = "https://github.com/actix/actix-redis.git", features = ["web"] }
env_logger = "0.6" env_logger = "0.6"

View File

@ -12,5 +12,5 @@ path = "src/main.rs"
[dependencies] [dependencies]
env_logger = "0.5" env_logger = "0.5"
rustls = "0.15" rustls = "0.15"
actix-web = { version = "1.0.0-alpha.3", features=["rust-tls"] } actix-web = { version = "1.0.0-alpha.4", features=["rust-tls"] }
actix-files = "0.1.0-alpha.2" actix-files = "0.1.0-alpha.4"

View File

@ -8,8 +8,8 @@ workspace = ".."
[dependencies] [dependencies]
actix = { version = "0.8.0-alpha.2", features = ["http"] } actix = { version = "0.8.0-alpha.2", features = ["http"] }
actix-rt = "0.2.2" actix-rt = "0.2.2"
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
actix-files = "0.1.0-alpha.2" actix-files = "0.1.0-alpha.4"
bcrypt = "0.2.1" bcrypt = "0.2.1"
chrono = { version = "0.4.6", features = ["serde"] } chrono = { version = "0.4.6", features = ["serde"] }

View File

@ -1,6 +1,6 @@
use actix::{Handler, Message}; use actix::{Handler, Message};
use actix_web::{dev::ServiceFromRequest, Error}; use actix_web::{dev::Payload, Error, HttpRequest};
use actix_web::{middleware::identity::Identity, FromRequest, HttpRequest}; use actix_web::{middleware::identity::Identity, FromRequest};
use bcrypt::verify; use bcrypt::verify;
use diesel::prelude::*; use diesel::prelude::*;
@ -50,8 +50,8 @@ impl<P> FromRequest<P> for LoggedUser {
type Error = Error; type Error = Error;
type Future = Result<LoggedUser, Error>; type Future = Result<LoggedUser, Error>;
fn from_request(req: &mut ServiceFromRequest<P>) -> Self::Future { fn from_request(req: &HttpRequest, pl: &mut Payload<P>) -> Self::Future {
if let Some(identity) = Identity::from_request(req)?.identity() { if let Some(identity) = Identity::from_request(req, pl)?.identity() {
let user: SlimUser = decode_token(&identity)?; let user: SlimUser = decode_token(&identity)?;
return Ok(user as LoggedUser); return Ok(user as LoggedUser);
} }

View File

@ -6,6 +6,6 @@ workspace = ".."
edition = "2018" edition = "2018"
[dependencies] [dependencies]
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
futures = "0.1.25" futures = "0.1.25"
env_logger = "0.6" env_logger = "0.6"

View File

@ -9,5 +9,5 @@ edition = "2018"
futures = "0.1" futures = "0.1"
env_logger = "0.5" env_logger = "0.5"
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
actix-files = "0.1.0-alpha.2" actix-files = "0.1.0-alpha.4"

View File

@ -6,8 +6,7 @@ workspace = ".."
edition = "2018" edition = "2018"
[dependencies] [dependencies]
#askama = { version = "0.8", features = ["with-actix-web"] } actix-web = "1.0.0-alpha.4"
actix-web = "1.0.0-alpha.3"
env_logger = "0.6" env_logger = "0.6"
askama = "0.8" askama = "0.8"

View File

@ -8,4 +8,4 @@ edition = "2018"
[dependencies] [dependencies]
env_logger = "0.6" env_logger = "0.6"
tera = "0.11" tera = "0.11"
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"

View File

@ -12,7 +12,7 @@ env_logger = "0.6"
yarte = { version = "0.2", features=["with-actix-web"] } yarte = { version = "0.2", features=["with-actix-web"] }
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
[build-dependencies] [build-dependencies]
yarte = { version = "0.2", features=["with-actix-web"] } yarte = { version = "0.2", features=["with-actix-web"] }
@ -20,4 +20,4 @@ yarte = { version = "0.2", features=["with-actix-web"] }
[dev-dependencies] [dev-dependencies]
bytes = "0.4" bytes = "0.4"
actix-http-test = "0.1.0-alpha.3" actix-http-test = "0.1.0-alpha.3"
actix-http = "0.1.0-alpha.3" actix-http = "0.1.0-alpha.4"

View File

@ -11,6 +11,6 @@ path = "src/main.rs"
[dependencies] [dependencies]
actix-rt = "0.2" 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" env_logger = "0.6"
openssl = { version="0.10" } openssl = { version="0.10" }

View File

@ -6,7 +6,7 @@ workspace = "../../"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
actix-web = "1.0.0-alpha.3" actix-web = "1.0.0-alpha.4"
serde = "1.0" serde = "1.0"
serde_derive = "1.0" serde_derive = "1.0"
serde_json = "1.0" serde_json = "1.0"

View File

@ -11,9 +11,9 @@ path = "src/main.rs"
[dependencies] [dependencies]
actix = "0.8.0-alpha.2" 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-web-actors = "1.0.0-alpha.2"
actix-files = "0.1.0-alpha.2" actix-files = "0.1.0-alpha.4"
rand = "0.6" rand = "0.6"
bytes = "0.4" bytes = "0.4"

View File

@ -15,9 +15,9 @@ path = "src/client.rs"
[dependencies] [dependencies]
actix = "0.8.0-alpha.2" 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-web-actors = "1.0.0-alpha.3"
actix-files = "0.1.0-alpha.2" actix-files = "0.1.0-alpha.4"
rand = "0.6" rand = "0.6"
bytes = "0.4" bytes = "0.4"

View File

@ -15,9 +15,9 @@ path = "src/main.rs"
[dependencies] [dependencies]
actix = "0.8.0-alpha.2" 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-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" env_logger = "0.6"
futures = "0.1" futures = "0.1"
bytes = "0.4" bytes = "0.4"