}
pub trait Perform {
- type Response: serde::ser::Serialize;
+ type Response: serde::ser::Serialize + Send;
fn perform(
&self,
use crate::api::site::*;
use crate::api::user::*;
use crate::rate_limit::RateLimit;
-use actix_web::guard;
pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
cfg.service(
);
}
-fn perform<Request>(
+async fn perform<Request>(
data: Request,
db: DbPoolParam,
chat_server: ChatServerParam,
) -> Result<HttpResponse, Error>
where
Oper<Request>: Perform,
+ Request: Send + 'static,
{
let ws_info = WebsocketInfo {
chatserver: chat_server.get_ref().to_owned(),
let oper: Oper<Request> = Oper::new(data);
- let res = oper.perform(db.get_ref().to_owned(), Some(ws_info));
-
- Ok(HttpResponse::Ok().json(res?))
+ let res = web::block(move || oper.perform(db.get_ref().to_owned(), Some(ws_info)))
+ .await
+ .map(|json| HttpResponse::Ok().json(json))
+ .map_err(|e| ErrorBadRequest(e))?;
+ Ok(res)
}
async fn route_get<Data>(
chat_server: ChatServerParam,
) -> Result<HttpResponse, Error>
where
- Data: Serialize,
+ Data: Serialize + Send + 'static,
Oper<Data>: Perform,
{
- perform::<Data>(data.0, db, chat_server)
+ perform::<Data>(data.0, db, chat_server).await
}
async fn route_post<Data>(
chat_server: ChatServerParam,
) -> Result<HttpResponse, Error>
where
- Data: Serialize,
+ Data: Serialize + Send + 'static,
Oper<Data>: Perform,
{
- perform::<Data>(data.0, db, chat_server)
+ perform::<Data>(data.0, db, chat_server).await
}
async fn get_all_feed(
info: web::Query<Params>,
db: web::Data<Pool<ConnectionManager<PgConnection>>>,
-) -> Result<HttpResponse, actix_web::Error> {
+) -> Result<HttpResponse, Error> {
let res = web::block(move || {
let conn = db.get()?;
get_feed_all_data(&conn, &get_sort_type(info)?)
.content_type("application/rss+xml")
.body(rss)
})
- .map_err(|_| HttpResponse::InternalServerError())?;
+ .map_err(|e| ErrorBadRequest(e))?;
Ok(res)
}
path: web::Path<(String, String)>,
info: web::Query<Params>,
db: web::Data<Pool<ConnectionManager<PgConnection>>>,
-) -> Result<HttpResponse, actix_web::Error> {
+) -> Result<HttpResponse, Error> {
let res = web::block(move || {
let conn = db.get()?;
.content_type("application/rss+xml")
.body(rss)
})
- .map_err(|_| HttpResponse::InternalServerError())?;
+ .map_err(|e| ErrorBadRequest(e))?;
Ok(res)
}
conn: &PgConnection,
sort_type: &SortType,
user_name: String,
-) -> Result<ChannelBuilder, Error> {
+) -> Result<ChannelBuilder, failure::Error> {
let site_view = SiteView::read(&conn)?;
let user = User_::find_by_username(&conn, &user_name)?;
let user_url = user.get_profile_url();
conn: &PgConnection,
sort_type: &SortType,
community_name: String,
-) -> Result<ChannelBuilder, Error> {
+) -> Result<ChannelBuilder, failure::Error> {
let site_view = SiteView::read(&conn)?;
let community = Community::read_from_name(&conn, community_name)?;
let community_url = community.get_url();
conn: &PgConnection,
sort_type: &SortType,
jwt: String,
-) -> Result<ChannelBuilder, Error> {
+) -> Result<ChannelBuilder, failure::Error> {
let site_view = SiteView::read(&conn)?;
let user_id = Claims::decode(&jwt)?.claims.id;
Ok(channel_builder)
}
-fn get_feed_inbox(conn: &PgConnection, jwt: String) -> Result<ChannelBuilder, Error> {
+fn get_feed_inbox(conn: &PgConnection, jwt: String) -> Result<ChannelBuilder, failure::Error> {
let site_view = SiteView::read(&conn)?;
let user_id = Claims::decode(&jwt)?.claims.id;
.route("/password_change/{token}", web::get().to(index));
}
-async fn index() -> Result<NamedFile, actix_web::error::Error> {
+async fn index() -> Result<NamedFile, Error> {
Ok(NamedFile::open(
Settings::get().front_end_dir + "/index.html",
)?)
use crate::{get_ip, markdown_to_html, version, Settings};
use actix::prelude::*;
use actix_files::NamedFile;
-use actix_web::{body::Body, web::Query, *};
+use actix_web::{body::Body, error::ErrorBadRequest, web::Query, *};
use actix_web_actors::ws;
use chrono::{DateTime, NaiveDateTime, Utc};
use diesel::{
r2d2::{ConnectionManager, Pool},
PgConnection,
};
-use failure::Error;
use log::{error, info};
use regex::Regex;
use rss::{CategoryBuilder, ChannelBuilder, GuidBuilder, Item, ItemBuilder};
async fn node_info(
db: web::Data<Pool<ConnectionManager<PgConnection>>>,
-) -> Result<HttpResponse, actix_web::Error> {
+) -> Result<HttpResponse, Error> {
let res = web::block(move || {
let conn = db.get()?;
let site_view = match SiteView::read(&conn) {
})
.await
.map(|json| HttpResponse::Ok().json(json))
- .map_err(|_| HttpResponse::InternalServerError())?;
+ .map_err(|e| ErrorBadRequest(e))?;
Ok(res)
}
async fn get_webfinger_response(
info: Query<Params>,
db: web::Data<Pool<ConnectionManager<PgConnection>>>,
-) -> Result<HttpResponse, actix_web::Error> {
+) -> Result<HttpResponse, Error> {
let res = web::block(move || {
let conn = db.get()?;
})
.await
.map(|json| HttpResponse::Ok().json(json))
- .map_err(|_| HttpResponse::InternalServerError())?;
+ .map_err(|e| ErrorBadRequest(e))?;
Ok(res)
}
use super::*;
use crate::websocket::server::*;
-use actix_web::{Error, Result};
/// How often heartbeat pings are sent
const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);
.then(|res, _, ctx| {
match res {
Ok(Ok(res)) => ctx.text(res),
- Ok(Err(e)) => match e {},
+ Ok(Err(_)) => {}
Err(e) => error!("{}", &e),
}
actix::fut::ready(())