Follow Rust and crates update

This commit is contained in:
Kitaiti Makoto
2021-11-28 07:53:13 +09:00
parent 9187e4dde9
commit ae3344f318
35 changed files with 208 additions and 160 deletions
-6
View File
@@ -19,12 +19,6 @@ impl From<Error> for ApiError {
}
}
impl From<std::option::NoneError> for ApiError {
fn from(err: std::option::NoneError) -> ApiError {
ApiError(err.into())
}
}
impl<'r> Responder<'r> for ApiError {
fn respond_to(self, req: &Request<'_>) -> response::Result<'r> {
match self.0 {
+12 -9
View File
@@ -1,7 +1,7 @@
use chrono::NaiveDateTime;
use rocket_contrib::json::Json;
use crate::api::{authorization::*, Api};
use crate::api::{authorization::*, Api, ApiError};
use plume_api::posts::*;
use plume_common::{activity_pub::broadcast, utils::md_to_html};
use plume_models::{
@@ -121,14 +121,17 @@ pub fn create(
Some(Media::get_media_processor(&conn, vec![&author])),
);
let blog = payload.blog_id.or_else(|| {
let blogs = Blog::find_for_author(&conn, &author).ok()?;
if blogs.len() == 1 {
Some(blogs[0].id)
} else {
None
}
})?;
let blog = payload
.blog_id
.or_else(|| {
let blogs = Blog::find_for_author(&conn, &author).ok()?;
if blogs.len() == 1 {
Some(blogs[0].id)
} else {
None
}
})
.ok_or(ApiError(Error::NotFound))?;
if Post::find_by_slug(&conn, slug, blog).is_ok() {
return Err(Error::InvalidValue.into());
+2 -2
View File
@@ -90,8 +90,8 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for SignedJson<T> {
o: Transformed<'a, Self>,
) -> rocket::data::Outcome<Self, Self::Error> {
let string = o.borrowed()?;
match serde_json::from_str(&string) {
Ok(v) => Success(SignedJson(Digest::from_body(&string), Json(v))),
match serde_json::from_str(string) {
Ok(v) => Success(SignedJson(Digest::from_body(string), Json(v))),
Err(e) => {
if e.is_data() {
Failure((Status::UnprocessableEntity, JsonError::Parse(string, e)))
+1 -1
View File
@@ -1,5 +1,5 @@
#![allow(clippy::too_many_arguments)]
#![feature(decl_macro, proc_macro_hygiene, try_trait)]
#![feature(decl_macro, proc_macro_hygiene)]
#[macro_use]
extern crate gettext_macros;
+1 -1
View File
@@ -372,7 +372,7 @@ fn ban(id: i32, conn: &Connection, worker: &ScheduledThreadPool) -> Result<(), E
.unwrap_or(false)
{
BlocklistedEmail::insert(
&conn,
conn,
NewBlocklistedEmail {
email_address: u.email.clone().unwrap(),
note: "Banned".to_string(),
+1 -6
View File
@@ -77,12 +77,7 @@ pub fn upload(
.map(|ext| format!(".{}", ext))
})
.unwrap_or_default();
let dest = format!(
"{}/{}{}",
CONFIG.media_directory,
GUID::rand().to_string(),
ext
);
let dest = format!("{}/{}{}", CONFIG.media_directory, GUID::rand(), ext);
match fields["file"][0].data {
SavedData::Bytes(ref bytes) => fs::write(&dest, bytes)
+1 -1
View File
@@ -425,7 +425,7 @@ pub fn create(
Ok(_) => ValidationErrors::new(),
Err(e) => e,
};
if Post::find_by_slug(&conn, &slug, blog.id).is_ok() {
if Post::find_by_slug(&conn, slug, blog.id).is_ok() {
errors.add(
"title",
ValidationError {
+1 -1
View File
@@ -54,7 +54,7 @@ pub fn search(query: Option<Form<SearchQuery>>, conn: DbConn, rockets: PlumeRock
let query = query.map(Form::into_inner).unwrap_or_default();
let page = query.page.unwrap_or_default();
let mut parsed_query =
Query::from_str(&query.q.as_deref().unwrap_or_default()).unwrap_or_default();
Query::from_str(query.q.as_deref().unwrap_or_default()).unwrap_or_default();
param_to_query!(query, parsed_query; normal: title, subtitle, content, tag,
instance, author, blog, lang, license;
+3 -3
View File
@@ -553,14 +553,14 @@ pub fn ap_followers(
#[get("/@/<name>/atom.xml")]
pub fn atom_feed(name: String, conn: DbConn) -> Option<Content<String>> {
let conn = &conn;
let author = User::find_by_fqn(&conn, &name).ok()?;
let entries = Post::get_recents_for_author(&conn, &author, 15).ok()?;
let author = User::find_by_fqn(conn, &name).ok()?;
let entries = Post::get_recents_for_author(conn, &author, 15).ok()?;
let uri = Instance::get_local()
.ok()?
.compute_box("@", &name, "atom.xml");
let title = &author.display_name;
let default_updated = &author.creation_date;
let feed = super::build_atom_feed(entries, &uri, title, default_updated, &conn);
let feed = super::build_atom_feed(entries, &uri, title, default_updated, conn);
Some(Content(
ContentType::new("application", "atom+xml"),
feed.to_string(),
+1 -1
View File
@@ -41,7 +41,7 @@ impl IntoContext for (&DbConn, &PlumeRocket) {
Option<(String, String)>,
) {
(
&self.0,
self.0,
&self.1.intl.catalog,
self.1.user.clone(),
self.1.flash_msg.clone(),