Fix upload avatar
This commit is contained in:
parent
09e941ff8a
commit
25d5991ffb
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1901,6 +1901,7 @@ dependencies = [
|
||||
"lettre",
|
||||
"lettre_email",
|
||||
"libc",
|
||||
"log",
|
||||
"openssl-sys",
|
||||
"serde",
|
||||
"toml",
|
||||
|
@ -51,6 +51,9 @@ impl actix::Handler<CreateFile> for FileSystemExecutor {
|
||||
|
||||
fn handle(&mut self, msg: CreateFile, _ctx: &mut Self::Context) -> Self::Result {
|
||||
let Configuration { store_path, .. } = &self.config;
|
||||
if std::fs::metadata(&store_path).is_err() {
|
||||
let _ = std::fs::create_dir_all(&store_path);
|
||||
}
|
||||
let CreateFile {
|
||||
mut source,
|
||||
file_name,
|
||||
|
@ -30,6 +30,8 @@ libc = { version = "0.2.0", default-features = false }
|
||||
lettre = { version = "*" }
|
||||
lettre_email = { version = "*" }
|
||||
|
||||
log = { version = "*" }
|
||||
|
||||
[dependencies.jirs-config]
|
||||
path = "../../shared/jirs-config"
|
||||
features = ["mail", "web"]
|
||||
|
@ -41,6 +41,9 @@ impl Handler<Welcome> for MailExecutor {
|
||||
"#,
|
||||
bind_token = msg.bind_token,
|
||||
);
|
||||
if cfg!(debug_assetrions) {
|
||||
log::info!("Sending email:\n{}", html);
|
||||
}
|
||||
|
||||
let email = lettre_email::Email::builder()
|
||||
.from(from)
|
||||
|
@ -15,7 +15,7 @@ path = "./src/lib.rs"
|
||||
[features]
|
||||
local-storage = ["filesystem-actor"]
|
||||
aws-s3 = ["amazon-actor"]
|
||||
default = ["local-storage", "aws-s3"]
|
||||
default = ["local-storage"]
|
||||
|
||||
[dependencies]
|
||||
common = { path = "../../shared/common" }
|
||||
|
@ -13,7 +13,7 @@ use database_actor::DbExecutor;
|
||||
#[cfg(feature = "local-storage")]
|
||||
use futures::executor::block_on;
|
||||
use futures::{StreamExt, TryStreamExt};
|
||||
use jirs_data::msg::WsMsgUser;
|
||||
use jirs_data::msg::{WsMsg, WsMsgUser};
|
||||
use jirs_data::{User, UserId};
|
||||
use websocket_actor::server::InnerMsg::BroadcastToChannel;
|
||||
use websocket_actor::server::WsServer;
|
||||
@ -136,7 +136,7 @@ pub async fn upload(
|
||||
let user = update_user_avatar(user_id, avatar_url.clone(), db).await?;
|
||||
ws.send(BroadcastToChannel(
|
||||
project_id,
|
||||
WsMsg::AvatarUrlChanged(user.id, avatar_url),
|
||||
WsMsg::User(WsMsgUser::AvatarUrlChanged(user.id, avatar_url)),
|
||||
))
|
||||
.await
|
||||
.map_err(|_| HttpResponse::UnprocessableEntity().finish())?;
|
||||
|
@ -134,7 +134,7 @@ async fn aws_s3(
|
||||
async fn local_storage_write(
|
||||
system_file_name: String,
|
||||
fs: Data<Addr<filesystem_actor::FileSystemExecutor>>,
|
||||
user_id: jirs_data::UserId,
|
||||
_user_id: jirs_data::UserId,
|
||||
receiver: Receiver<bytes::Bytes>,
|
||||
) -> Option<String> {
|
||||
let web_config = jirs_config::web::config();
|
||||
@ -148,15 +148,9 @@ async fn local_storage_write(
|
||||
.await
|
||||
{
|
||||
Ok(Ok(_)) => Some(format!(
|
||||
"{proto}://{bind}{port}{client_path}/{user_id}-{filename}",
|
||||
proto = if web_config.ssl { "https" } else { "http" },
|
||||
bind = web_config.bind,
|
||||
port = match web_config.port.as_str() {
|
||||
"80" | "443" => "".to_string(),
|
||||
p => format!(":{}", p),
|
||||
},
|
||||
"{addr}{client_path}/{filename}",
|
||||
addr = web_config.full_addr(),
|
||||
client_path = fs_config.client_path,
|
||||
user_id = user_id,
|
||||
filename = system_file_name
|
||||
)),
|
||||
Ok(_) => None,
|
||||
|
@ -47,6 +47,7 @@ path = "../actors/database-actor"
|
||||
|
||||
[dependencies.web-actor]
|
||||
path = "../actors/web-actor"
|
||||
features = ["local-storage"]
|
||||
|
||||
[dependencies.websocket-actor]
|
||||
path = "../actors/websocket-actor"
|
||||
|
@ -70,7 +70,7 @@ async fn main() -> Result<(), String> {
|
||||
app
|
||||
})
|
||||
.workers(web_config.concurrency)
|
||||
.bind(web_config.addr())
|
||||
.bind(web_config.bind_addr())
|
||||
.map_err(|e| format!("{}", e))?
|
||||
.run()
|
||||
.await
|
||||
|
@ -12,6 +12,7 @@ pub struct Configuration {
|
||||
pub port: String,
|
||||
pub bind: String,
|
||||
pub ssl: bool,
|
||||
pub public_addr: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for Configuration {
|
||||
@ -21,12 +22,20 @@ impl Default for Configuration {
|
||||
port: "5000".to_string(),
|
||||
bind: "0.0.0.0".to_string(),
|
||||
ssl: false,
|
||||
public_addr: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Configuration {
|
||||
pub fn addr(&self) -> String {
|
||||
match self.public_addr.as_deref() {
|
||||
Some(s) => String::from(s),
|
||||
_ => format!("{}:{}", self.bind, self.port),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bind_addr(&self) -> String {
|
||||
format!("{}:{}", self.bind, self.port)
|
||||
}
|
||||
|
||||
|
@ -34,8 +34,8 @@ mod shared;
|
||||
pub mod validations;
|
||||
mod ws;
|
||||
|
||||
// #[global_allocator]
|
||||
// static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||
#[global_allocator]
|
||||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[repr(C)]
|
||||
@ -190,6 +190,7 @@ fn update(msg: Msg, model: &mut model::Model, orders: &mut impl Orders<Msg>) {
|
||||
}));
|
||||
}
|
||||
Ok(m) => {
|
||||
log::info!("INCOMING {:?}", m);
|
||||
orders
|
||||
.skip()
|
||||
.send_msg(Msg::WebSocketChange(WebSocketChanged::WsMsg(m)));
|
||||
@ -200,6 +201,7 @@ fn update(msg: Msg, model: &mut model::Model, orders: &mut impl Orders<Msg>) {
|
||||
}
|
||||
WebSocketChanged::WebSocketClosed => {
|
||||
open_socket(model, orders);
|
||||
return;
|
||||
}
|
||||
WebSocketChanged::Bounced(ws_msg) => {
|
||||
model.ws_queue.push(ws_msg);
|
||||
@ -207,7 +209,6 @@ fn update(msg: Msg, model: &mut model::Model, orders: &mut impl Orders<Msg>) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
Msg::WebSocketChange(change)
|
||||
}
|
||||
_ => msg,
|
||||
};
|
||||
|
@ -5,9 +5,9 @@ use crate::validator;
|
||||
validator!(EmailFormat, is_email, "Not a valid e-mail address");
|
||||
validator!(UuidFormat, is_token, "Malformed token");
|
||||
|
||||
pub type UsernameValidator = Touched<Between<4, 20>>;
|
||||
pub type UsernameValidator = Touched<Between<4, 36>>;
|
||||
pub type EmailValidator = Touched<Chain<Changed<AtLeast<6>>, Changed<EmailFormat>>>;
|
||||
pub type TokenValidator = Touched<Chain<Between<10, 20>, Changed<UuidFormat>>>;
|
||||
pub type TokenValidator = Touched<Chain<Between<10, 36>, Changed<UuidFormat>>>;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct SignInPage {
|
||||
|
@ -432,7 +432,26 @@ pub fn update(msg: WsMsg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
Some(id),
|
||||
));
|
||||
}
|
||||
_ => (),
|
||||
WsMsg::Session(WsMsgSession::AuthenticateSuccess) => {
|
||||
let page = crate::match_page_mut!(model, SignIn);
|
||||
page.login_success = true;
|
||||
}
|
||||
WsMsg::Session(WsMsgSession::BindTokenOk(access_token)) => {
|
||||
match write_auth_token(Some(access_token)) {
|
||||
Ok(msg) => {
|
||||
orders.skip().send_msg(msg);
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("{}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
log::info!(
|
||||
"got web socket message but don't know what to do with it {:?}",
|
||||
msg
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user