Compare commits

..

2 Commits

Author SHA1 Message Date
Violet white 26867ca6be Retrieve signing user from database instead of expecting it to materialize from thin air 2020-01-14 13:56:51 -05:00
Violet white 2b4e802914 Work towards authorized fetch 2020-01-12 22:09:56 -05:00
130 changed files with 2290 additions and 2811 deletions
+1 -2
View File
@@ -10,7 +10,7 @@ executors:
type: boolean type: boolean
default: false default: false
docker: docker:
- image: plumeorg/plume-buildenv:v0.0.9 - image: plumeorg/plume-buildenv:v0.0.8
- image: <<#parameters.postgres>>circleci/postgres:9.6-alpine<</parameters.postgres>><<^parameters.postgres>>alpine:latest<</parameters.postgres>> - image: <<#parameters.postgres>>circleci/postgres:9.6-alpine<</parameters.postgres>><<^parameters.postgres>>alpine:latest<</parameters.postgres>>
environment: environment:
POSTGRES_USER: postgres POSTGRES_USER: postgres
@@ -226,7 +226,6 @@ jobs:
steps: steps:
- restore_env: - restore_env:
cache: none cache: none
- run: cargo build
- run: crowdin upload -b master - run: crowdin upload -b master
workflows: workflows:
+1 -1
View File
@@ -8,7 +8,7 @@ RUN apt update &&\
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
#install and configure rust #install and configure rust
RUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly-2020-01-15 -y &&\ RUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly-2019-03-23 -y &&\
rustup component add rustfmt clippy &&\ rustup component add rustfmt clippy &&\
rustup component add rust-std --target wasm32-unknown-unknown rustup component add rust-std --target wasm32-unknown-unknown
Generated
+1373 -1794
View File
File diff suppressed because it is too large Load Diff
+5 -6
View File
@@ -3,7 +3,6 @@ authors = ["Plume contributors"]
name = "plume" name = "plume"
version = "0.4.0" version = "0.4.0"
repository = "https://github.com/Plume-org/Plume" repository = "https://github.com/Plume-org/Plume"
edition = "2018"
[dependencies] [dependencies]
activitypub = "0.1.3" activitypub = "0.1.3"
@@ -20,10 +19,11 @@ heck = "0.3.0"
lettre = "0.9.2" lettre = "0.9.2"
lettre_email = "0.9.2" lettre_email = "0.9.2"
num_cpus = "1.10" num_cpus = "1.10"
rocket = "0.4.2" rocket = "0.4.0"
rocket_contrib = { version = "0.4.2", features = ["json"] } rocket_contrib = { version = "0.4.0", features = ["json"] }
rocket_i18n = { git = "https://github.com/Plume-org/rocket_i18n", rev = "e922afa7c366038b3433278c03b1456b346074f2" } rocket_i18n = { git = "https://github.com/Plume-org/rocket_i18n", rev = "e922afa7c366038b3433278c03b1456b346074f2" }
rpassword = "4.0" rpassword = "4.0"
runtime-fmt = "0.3.0"
scheduled-thread-pool = "0.2.2" scheduled-thread-pool = "0.2.2"
serde = "1.0" serde = "1.0"
serde_json = "1.0" serde_json = "1.0"
@@ -66,10 +66,10 @@ path = "plume-models"
[dependencies.rocket_csrf] [dependencies.rocket_csrf]
git = "https://github.com/fdb-hiroshima/rocket_csrf" git = "https://github.com/fdb-hiroshima/rocket_csrf"
rev = "29910f2829e7e590a540da3804336577b48c7b31" rev = "4a72ea2ec716cb0b26188fb00bccf2ef7d1e031c"
[build-dependencies] [build-dependencies]
ructe = "0.9.0" ructe = "0.6.2"
rsass = "0.9" rsass = "0.9"
[features] [features]
@@ -78,7 +78,6 @@ postgres = ["plume-models/postgres", "diesel/postgres"]
sqlite = ["plume-models/sqlite", "diesel/sqlite"] sqlite = ["plume-models/sqlite", "diesel/sqlite"]
debug-mailer = [] debug-mailer = []
test = [] test = []
search-lindera = ["plume-models/search-lindera"]
[workspace] [workspace]
members = ["plume-api", "plume-cli", "plume-models", "plume-common", "plume-front", "plume-macro"] members = ["plume-api", "plume-cli", "plume-models", "plume-common", "plume-front", "plume-macro"]
+1 -2
View File
@@ -10,8 +10,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \ gcc \
make \ make \
openssl \ openssl \
libssl-dev \ libssl-dev
clang
WORKDIR /scratch WORKDIR /scratch
COPY script/wasm-deps.sh . COPY script/wasm-deps.sh .
+88 -22
View File
@@ -190,28 +190,7 @@ p.error {
background: $gray; background: $gray;
text-overflow: ellipsis; text-overflow: ellipsis;
footer.authors {
div {
float: left;
margin-right: 0.25em;
}
.likes { color: $red; }
.reshares { color: $primary; }
span.likes, span.resahres {
font-family: "Route159",serif;
font-size: 1em;
}
svg.feather {
width: 0.85em;
height: 0.85em;
}
}
> * { > * {
margin: 20px; margin: 20px;
@@ -490,6 +469,93 @@ figure {
/// Small screens /// Small screens
@media screen and (max-width: 600px) { @media screen and (max-width: 600px) {
@keyframes menuOpening {
from {
transform: scaleX(0);
transform-origin: left;
opacity: 0;
}
to {
transform: scaleX(1);
transform-origin: left;
opacity: 1;
}
}
body > header {
flex-direction: column;
nav#menu {
display: inline-flex;
z-index: 21;
}
#content {
display: none;
appearance: none;
text-align: center;
z-index: 20;
}
}
body > header:focus-within #content, #content.show {
position: fixed;
display: flex;
flex-direction: column;
justify-content: flex-start;
top: 0;
left: 0;
width: 100%;
height: 100%;
box-sizing: border-box;
animation: 0.2s menuOpening;
&::before {
content: "";
position: absolute;
transform: skewX(-10deg);
top: 0;
left: -20%;
width: 100%;
height: 100%;
z-index: -10;
background: $primary;
}
> nav {
flex-direction: column;
align-items: flex-start;
a {
display: flex;
flex-direction: row;
align-items: center;
margin: 0;
padding: 1rem 1.5rem;
color: $background;
font-size: 1.4em;
font-weight: 300;
&.title { font-size: 1.8em; }
> *:first-child { width: 3rem; }
> img:first-child { height: 3rem; }
> *:last-child { margin-left: 1rem; }
> nav hr {
display: block;
margin: 0;
width: 100%;
border: solid $background 0.1rem;
}
.mobile-label { display: initial; }
}
}
}
main .article-meta { main .article-meta {
> *, .comments { > *, .comments {
margin: 0 5%; margin: 0 5%;
-90
View File
@@ -101,96 +101,6 @@ body > header {
} }
} }
/// Small screens
@media screen and (max-width: 600px) {
@keyframes menuOpening {
from {
transform: scaleX(0);
transform-origin: left;
opacity: 0;
}
to {
transform: scaleX(1);
transform-origin: left;
opacity: 1;
}
}
body > header {
flex-direction: column;
nav#menu {
display: inline-flex;
z-index: 21;
}
#content {
display: none;
appearance: none;
text-align: center;
z-index: 20;
}
}
body > header:focus-within #content, #content.show {
position: fixed;
display: flex;
flex-direction: column;
justify-content: flex-start;
top: 0;
left: 0;
width: 100%;
height: 100%;
box-sizing: border-box;
animation: 0.2s menuOpening;
&::before {
content: "";
position: absolute;
transform: skewX(-10deg);
top: 0;
left: -20%;
width: 100%;
height: 100%;
z-index: -10;
background: $primary;
}
> nav {
flex-direction: column;
align-items: flex-start;
a {
display: flex;
flex-direction: row;
align-items: center;
margin: 0;
padding: 1rem 1.5rem;
color: $background;
font-size: 1.4em;
font-weight: 300;
&.title { font-size: 1.8em; }
> *:first-child { width: 3rem; }
> img:first-child { height: 3rem; }
> *:last-child { margin-left: 1rem; }
> nav hr {
display: block;
margin: 0;
width: 100%;
border: solid $background 0.1rem;
}
.mobile-label { display: initial; }
}
}
}
}
/* Only enable label animations on large screens */ /* Only enable label animations on large screens */
@media screen and (min-width: 600px) { @media screen and (min-width: 600px) {
header nav a { header nav a {
+3 -3
View File
@@ -1,8 +1,8 @@
use rsass; extern crate rsass;
extern crate ructe;
use ructe::Ructe; use ructe::Ructe;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use std::{ffi::OsStr, fs::*, io::Write, path::*}; use std::{env, ffi::OsStr, fs::*, io::Write, path::*};
fn compute_static_hash() -> String { fn compute_static_hash() -> String {
//"find static/ -type f ! -path 'static/media/*' | sort | xargs stat -c'%n %Y' | openssl dgst -r" //"find static/ -type f ! -path 'static/media/*' | sort | xargs stat -c'%n %Y' | openssl dgst -r"
-1
View File
@@ -2,7 +2,6 @@
name = "plume-api" name = "plume-api"
version = "0.4.0" version = "0.4.0"
authors = ["Plume contributors"] authors = ["Plume contributors"]
edition = "2018"
[dependencies] [dependencies]
serde = "1.0" serde = "1.0"
+1
View File
@@ -1,3 +1,4 @@
extern crate serde;
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
-2
View File
@@ -2,7 +2,6 @@
name = "plume-cli" name = "plume-cli"
version = "0.4.0" version = "0.4.0"
authors = ["Plume contributors"] authors = ["Plume contributors"]
edition = "2018"
[[bin]] [[bin]]
name = "plm" name = "plm"
@@ -23,4 +22,3 @@ path = "../plume-models"
[features] [features]
postgres = ["plume-models/postgres", "diesel/postgres"] postgres = ["plume-models/postgres", "diesel/postgres"]
sqlite = ["plume-models/sqlite", "diesel/sqlite"] sqlite = ["plume-models/sqlite", "diesel/sqlite"]
search-lindera = ["plume-models/search-lindera"]
+5 -1
View File
@@ -1,4 +1,8 @@
use dotenv; extern crate clap;
extern crate diesel;
extern crate dotenv;
extern crate plume_models;
extern crate rpassword;
use clap::App; use clap::App;
use diesel::Connection; use diesel::Connection;
+2 -3
View File
@@ -82,7 +82,7 @@ fn init<'a>(args: &ArgMatches<'a>, conn: &Connection) {
} }
}; };
if can_do || force { if can_do || force {
let searcher = Searcher::create(&path, &CONFIG.search_tokenizers).unwrap(); let searcher = Searcher::create(&path).unwrap();
refill(args, conn, Some(searcher)); refill(args, conn, Some(searcher));
} else { } else {
eprintln!( eprintln!(
@@ -98,8 +98,7 @@ fn refill<'a>(args: &ArgMatches<'a>, conn: &Connection, searcher: Option<Searche
Some(path) => Path::new(path).join("search_index"), Some(path) => Path::new(path).join("search_index"),
None => Path::new(&CONFIG.search_index).to_path_buf(), None => Path::new(&CONFIG.search_index).to_path_buf(),
}; };
let searcher = let searcher = searcher.unwrap_or_else(|| Searcher::open(&path).unwrap());
searcher.unwrap_or_else(|| Searcher::open(&path, &CONFIG.search_tokenizers).unwrap());
searcher.fill(conn).expect("Couldn't import post"); searcher.fill(conn).expect("Couldn't import post");
println!("Commiting result"); println!("Commiting result");
-2
View File
@@ -2,7 +2,6 @@
name = "plume-common" name = "plume-common"
version = "0.4.0" version = "0.4.0"
authors = ["Plume contributors"] authors = ["Plume contributors"]
edition = "2018"
[dependencies] [dependencies]
activitypub = "0.1.1" activitypub = "0.1.1"
@@ -22,7 +21,6 @@ serde_json = "1.0"
shrinkwraprs = "0.2.1" shrinkwraprs = "0.2.1"
syntect = "3.3" syntect = "3.3"
tokio = "0.1.22" tokio = "0.1.22"
regex-syntax = { version = "0.6.17", default-features = false, features = ["unicode-perl"] }
[dependencies.chrono] [dependencies.chrono]
features = ["serde"] features = ["serde"]
+1 -1
View File
@@ -64,7 +64,7 @@ impl<T> ActivityStream<T> {
} }
impl<'r, O: Object> Responder<'r> for ActivityStream<O> { impl<'r, O: Object> Responder<'r> for ActivityStream<O> {
fn respond_to(self, request: &Request<'_>) -> Result<Response<'r>, Status> { fn respond_to(self, request: &Request) -> Result<Response<'r>, Status> {
let mut json = serde_json::to_value(&self.0).map_err(|_| Status::InternalServerError)?; let mut json = serde_json::to_value(&self.0).map_err(|_| Status::InternalServerError)?;
json["@context"] = context(); json["@context"] = context();
serde_json::to_string(&json).respond_to(request).map(|r| { serde_json::to_string(&json).respond_to(request).map(|r| {
+2 -2
View File
@@ -5,8 +5,8 @@ use reqwest::header::{HeaderMap, HeaderValue, ACCEPT, CONTENT_TYPE, DATE, USER_A
use std::ops::Deref; use std::ops::Deref;
use std::time::SystemTime; use std::time::SystemTime;
use crate::activity_pub::sign::Signer; use activity_pub::sign::Signer;
use crate::activity_pub::{ap_accept_header, AP_CONTENT_TYPE}; use activity_pub::{ap_accept_header, AP_CONTENT_TYPE};
const PLUME_USER_AGENT: &str = concat!("Plume/", env!("CARGO_PKG_VERSION")); const PLUME_USER_AGENT: &str = concat!("Plume/", env!("CARGO_PKG_VERSION"));
+1 -1
View File
@@ -131,7 +131,7 @@ impl SignatureValidity {
pub fn verify_http_headers<S: Signer + ::std::fmt::Debug>( pub fn verify_http_headers<S: Signer + ::std::fmt::Debug>(
sender: &S, sender: &S,
all_headers: &HeaderMap<'_>, all_headers: &HeaderMap,
data: &request::Digest, data: &request::Digest,
) -> SignatureValidity { ) -> SignatureValidity {
let sig_header = all_headers.get_one("Signature"); let sig_header = all_headers.get_one("Signature");
+15 -4
View File
@@ -1,16 +1,27 @@
#![feature(associated_type_defaults)] #![feature(custom_attribute, associated_type_defaults)]
extern crate activitypub;
#[macro_use] #[macro_use]
extern crate activitystreams_derive; extern crate activitystreams_derive;
use activitystreams_traits; extern crate activitystreams_traits;
extern crate array_tool;
use serde; extern crate base64;
extern crate chrono;
extern crate heck;
extern crate hex;
extern crate openssl;
extern crate pulldown_cmark;
extern crate reqwest;
extern crate rocket;
extern crate serde;
#[macro_use] #[macro_use]
extern crate shrinkwraprs; extern crate shrinkwraprs;
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
#[macro_use] #[macro_use]
extern crate serde_json; extern crate serde_json;
extern crate syntect;
extern crate tokio;
pub mod activity_pub; pub mod activity_pub;
pub mod utils; pub mod utils;
+14 -33
View File
@@ -1,7 +1,6 @@
use heck::CamelCase; use heck::CamelCase;
use openssl::rand::rand_bytes; use openssl::rand::rand_bytes;
use pulldown_cmark::{html, Event, Options, Parser, Tag}; use pulldown_cmark::{html, Event, Options, Parser, Tag};
use regex_syntax::is_word_character;
use rocket::{ use rocket::{
http::uri::Uri, http::uri::Uri,
response::{Flash, Redirect}, response::{Flash, Redirect},
@@ -49,7 +48,7 @@ enum State {
Ready, Ready,
} }
fn to_inline(tag: Tag<'_>) -> Tag<'_> { fn to_inline(tag: Tag) -> Tag {
match tag { match tag {
Tag::Header(_) | Tag::Table(_) | Tag::TableHead | Tag::TableRow | Tag::TableCell => { Tag::Header(_) | Tag::Table(_) | Tag::TableHead | Tag::TableRow | Tag::TableCell => {
Tag::Paragraph Tag::Paragraph
@@ -147,7 +146,7 @@ fn inline_tags<'a>(
} }
} }
pub type MediaProcessor<'a> = Box<dyn 'a + Fn(i32) -> Option<(String, Option<String>)>>; pub type MediaProcessor<'a> = Box<'a + Fn(i32) -> Option<(String, Option<String>)>>;
fn process_image<'a, 'b>( fn process_image<'a, 'b>(
evt: Event<'a>, evt: Event<'a>,
@@ -158,7 +157,9 @@ fn process_image<'a, 'b>(
match evt { match evt {
Event::Start(Tag::Image(id, title)) => { Event::Start(Tag::Image(id, title)) => {
if let Some((url, cw)) = id.parse::<i32>().ok().and_then(processor.as_ref()) { if let Some((url, cw)) = id.parse::<i32>().ok().and_then(processor.as_ref()) {
if let (Some(cw), false) = (cw, inline) { if inline || cw.is_none() {
Event::Start(Tag::Image(Cow::Owned(url), title))
} else {
// there is a cw, and where are not inline // there is a cw, and where are not inline
Event::Html(Cow::Owned(format!( Event::Html(Cow::Owned(format!(
r#"<label for="postcontent-cw-{id}"> r#"<label for="postcontent-cw-{id}">
@@ -169,11 +170,9 @@ fn process_image<'a, 'b>(
</span> </span>
<img src="{url}" alt=""#, <img src="{url}" alt=""#,
id = random_hex(), id = random_hex(),
cw = cw, cw = cw.unwrap(),
url = url url = url
))) )))
} else {
Event::Start(Tag::Image(Cow::Owned(url), title))
} }
} else { } else {
Event::Start(Tag::Image(id, title)) Event::Start(Tag::Image(id, title))
@@ -201,12 +200,6 @@ fn process_image<'a, 'b>(
} }
} }
#[derive(Default, Debug)]
struct DocumentContext {
in_code: bool,
in_link: bool,
}
/// Returns (HTML, mentions, hashtags) /// Returns (HTML, mentions, hashtags)
pub fn md_to_html<'a>( pub fn md_to_html<'a>(
md: &str, md: &str,
@@ -221,7 +214,7 @@ pub fn md_to_html<'a>(
}; };
let parser = Parser::new_ext(md, Options::all()); let parser = Parser::new_ext(md, Options::all());
let (parser, mentions, hashtags): (Vec<Event<'_>>, Vec<String>, Vec<String>) = parser let (parser, mentions, hashtags): (Vec<Event>, Vec<String>, Vec<String>) = parser
// Flatten text because pulldown_cmark break #hashtag in two individual text elements // Flatten text because pulldown_cmark break #hashtag in two individual text elements
.scan(None, flatten_text) .scan(None, flatten_text)
.flatten() .flatten()
@@ -230,21 +223,13 @@ pub fn md_to_html<'a>(
.map(|evt| process_image(evt, inline, &media_processor)) .map(|evt| process_image(evt, inline, &media_processor))
// Ignore headings, images, and tables if inline = true // Ignore headings, images, and tables if inline = true
.scan((vec![], inline), inline_tags) .scan((vec![], inline), inline_tags)
.scan(&mut DocumentContext::default(), |ctx, evt| match evt { .scan(false, |in_code, evt| match evt {
Event::Start(Tag::CodeBlock(_)) | Event::Start(Tag::Code) => { Event::Start(Tag::CodeBlock(_)) | Event::Start(Tag::Code) => {
ctx.in_code = true; *in_code = true;
Some((vec![evt], vec![], vec![])) Some((vec![evt], vec![], vec![]))
} }
Event::End(Tag::CodeBlock(_)) | Event::End(Tag::Code) => { Event::End(Tag::CodeBlock(_)) | Event::End(Tag::Code) => {
ctx.in_code = false; *in_code = false;
Some((vec![evt], vec![], vec![]))
}
Event::Start(Tag::Link(_, _)) => {
ctx.in_link = true;
Some((vec![evt], vec![], vec![]))
}
Event::End(Tag::Link(_, _)) => {
ctx.in_link = false;
Some((vec![evt], vec![], vec![])) Some((vec![evt], vec![], vec![]))
} }
Event::Text(txt) => { Event::Text(txt) => {
@@ -262,7 +247,7 @@ pub fn md_to_html<'a>(
text_acc.push(c) text_acc.push(c)
} }
let mention = text_acc; let mention = text_acc;
let short_mention = mention.splitn(1, '@').next().unwrap_or(""); let short_mention = mention.splitn(1, '@').nth(0).unwrap_or("");
let link = Tag::Link( let link = Tag::Link(
format!("{}@/{}/", base_url, &mention).into(), format!("{}@/{}/", base_url, &mention).into(),
short_mention.to_owned().into(), short_mention.to_owned().into(),
@@ -284,7 +269,7 @@ pub fn md_to_html<'a>(
} }
} }
State::Hashtag => { State::Hashtag => {
let char_matches = c == '-' || is_word_character(c); let char_matches = c.is_alphanumeric() || "-_".contains(c);
if char_matches && (n < (txt.chars().count() - 1)) { if char_matches && (n < (txt.chars().count() - 1)) {
text_acc.push(c); text_acc.push(c);
(events, State::Hashtag, text_acc, n + 1, mentions, hashtags) (events, State::Hashtag, text_acc, n + 1, mentions, hashtags)
@@ -315,7 +300,7 @@ pub fn md_to_html<'a>(
} }
} }
State::Ready => { State::Ready => {
if !ctx.in_code && !ctx.in_link && c == '@' { if !*in_code && c == '@' {
events.push(Event::Text(text_acc.into())); events.push(Event::Text(text_acc.into()));
( (
events, events,
@@ -325,7 +310,7 @@ pub fn md_to_html<'a>(
mentions, mentions,
hashtags, hashtags,
) )
} else if !ctx.in_code && !ctx.in_link && c == '#' { } else if !*in_code && c == '#' {
events.push(Event::Text(text_acc.into())); events.push(Event::Text(text_acc.into()));
( (
events, events,
@@ -414,7 +399,6 @@ mod tests {
("not_a@mention", vec![]), ("not_a@mention", vec![]),
("`@helo`", vec![]), ("`@helo`", vec![]),
("```\n@hello\n```", vec![]), ("```\n@hello\n```", vec![]),
("[@atmark in link](https://example.org/)", vec![]),
]; ];
for (md, mentions) in tests { for (md, mentions) in tests {
@@ -440,9 +424,6 @@ mod tests {
("with some punctuation #test!", vec!["test"]), ("with some punctuation #test!", vec!["test"]),
(" #spaces ", vec!["spaces"]), (" #spaces ", vec!["spaces"]),
("not_a#hashtag", vec![]), ("not_a#hashtag", vec![]),
("#نرم‌افزار_آزاد", vec!["نرم‌افزار_آزاد"]),
("[#hash in link](https://example.org/)", vec![]),
("#zwsp\u{200b}inhash", vec!["zwsp"]),
]; ];
for (md, mentions) in tests { for (md, mentions) in tests {
-1
View File
@@ -2,7 +2,6 @@
name = "plume-front" name = "plume-front"
version = "0.4.0" version = "0.4.0"
authors = ["Plume contributors"] authors = ["Plume contributors"]
edition = "2018"
[dependencies] [dependencies]
stdweb = "=0.4.18" stdweb = "=0.4.18"
+1 -1
View File
@@ -1,4 +1,3 @@
use crate::CATALOG;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json; use serde_json;
use std::sync::Mutex; use std::sync::Mutex;
@@ -6,6 +5,7 @@ use stdweb::{
unstable::{TryFrom, TryInto}, unstable::{TryFrom, TryInto},
web::{event::*, html_element::*, *}, web::{event::*, html_element::*, *},
}; };
use CATALOG;
macro_rules! mv { macro_rules! mv {
( $( $var:ident ),* => $exp:expr ) => { ( $( $var:ident ),* => $exp:expr ) => {
+3 -4
View File
@@ -1,12 +1,15 @@
#![recursion_limit = "128"] #![recursion_limit = "128"]
#![feature(decl_macro, proc_macro_hygiene, try_trait)] #![feature(decl_macro, proc_macro_hygiene, try_trait)]
extern crate gettext;
#[macro_use] #[macro_use]
extern crate gettext_macros; extern crate gettext_macros;
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;
#[macro_use] #[macro_use]
extern crate stdweb; extern crate stdweb;
extern crate serde;
extern crate serde_json;
use stdweb::web::{event::*, *}; use stdweb::web::{event::*, *};
init_i18n!( init_i18n!(
@@ -19,7 +22,6 @@ init_i18n!(
en, en,
eo, eo,
es, es,
fa,
fr, fr,
gl, gl,
hi, hi,
@@ -46,9 +48,6 @@ lazy_static! {
let lang = js! { return navigator.language }.into_string().unwrap(); let lang = js! { return navigator.language }.into_string().unwrap();
let lang = lang.splitn(2, '-').next().unwrap_or("en"); let lang = lang.splitn(2, '-').next().unwrap_or("en");
// Force a language (Add .env setting)
//let lang = "fa"; ???
let english_position = catalogs let english_position = catalogs
.iter() .iter()
.position(|(language_code, _)| *language_code == "en") .position(|(language_code, _)| *language_code == "en")
+14 -11
View File
@@ -1,7 +1,8 @@
#![recursion_limit = "128"] #![recursion_limit = "128"]
extern crate proc_macro;
#[macro_use] #[macro_use]
extern crate quote; extern crate quote;
extern crate syn;
use proc_macro::TokenStream; use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2; use proc_macro2::TokenStream as TokenStream2;
@@ -102,17 +103,19 @@ fn file_to_migration(file: &str) -> TokenStream2 {
acc.push_str(line); acc.push_str(line);
acc.push('\n'); acc.push('\n');
} }
} else if line.starts_with("--#!") {
acc.push_str(&line[4..]);
acc.push('\n');
} else if line.starts_with("--") {
continue;
} else { } else {
let func: TokenStream2 = trampoline(TokenStream::from_str(&acc).unwrap().into()); if line.starts_with("--#!") {
actions.push(quote!(Action::Function(&#func))); acc.push_str(&line[4..]);
sql = true; acc.push('\n');
acc = line.to_string(); } else if line.starts_with("--") {
acc.push('\n'); continue;
} else {
let func: TokenStream2 = trampoline(TokenStream::from_str(&acc).unwrap().into());
actions.push(quote!(Action::Function(&#func)));
sql = true;
acc = line.to_string();
acc.push('\n');
}
} }
} }
if !acc.trim().is_empty() { if !acc.trim().is_empty() {
+2 -5
View File
@@ -2,7 +2,6 @@
name = "plume-models" name = "plume-models"
version = "0.4.0" version = "0.4.0"
authors = ["Plume contributors"] authors = ["Plume contributors"]
edition = "2018"
[dependencies] [dependencies]
activitypub = "0.1.1" activitypub = "0.1.1"
@@ -12,7 +11,7 @@ bcrypt = "0.5"
guid-create = "0.1" guid-create = "0.1"
heck = "0.3.0" heck = "0.3.0"
itertools = "0.8.0" itertools = "0.8.0"
lazy_static = "1.0" lazy_static = "*"
migrations_internals= "1.4.0" migrations_internals= "1.4.0"
openssl = "0.10.22" openssl = "0.10.22"
rocket = "0.4.0" rocket = "0.4.0"
@@ -22,7 +21,7 @@ scheduled-thread-pool = "0.2.2"
serde = "1.0" serde = "1.0"
serde_derive = "1.0" serde_derive = "1.0"
serde_json = "1.0" serde_json = "1.0"
tantivy = "0.12.0" tantivy = "0.10.1"
url = "2.1" url = "2.1"
walkdir = "2.2" walkdir = "2.2"
webfinger = "0.4.1" webfinger = "0.4.1"
@@ -30,7 +29,6 @@ whatlang = "0.7.1"
shrinkwraprs = "0.2.1" shrinkwraprs = "0.2.1"
diesel-derive-newtype = "0.1.2" diesel-derive-newtype = "0.1.2"
glob = "0.3.0" glob = "0.3.0"
lindera-tantivy = { version = "0.1.2", optional = true }
[dependencies.chrono] [dependencies.chrono]
features = ["serde"] features = ["serde"]
@@ -55,4 +53,3 @@ diesel_migrations = "1.3.0"
[features] [features]
postgres = ["diesel/postgres", "plume-macro/postgres" ] postgres = ["diesel/postgres", "plume-macro/postgres" ]
sqlite = ["diesel/sqlite", "plume-macro/sqlite" ] sqlite = ["diesel/sqlite", "plume-macro/sqlite" ]
search-lindera = ["lindera-tantivy"]
+2 -1
View File
@@ -1,10 +1,11 @@
use crate::users::User;
use rocket::{ use rocket::{
http::Status, http::Status,
request::{self, FromRequest, Request}, request::{self, FromRequest, Request},
Outcome, Outcome,
}; };
use users::User;
/// Wrapper around User to use as a request guard on pages reserved to admins. /// Wrapper around User to use as a request guard on pages reserved to admins.
pub struct Admin(pub User); pub struct Admin(pub User);
+4 -1
View File
@@ -1,4 +1,3 @@
use crate::{db_conn::DbConn, schema::api_tokens, Error, Result};
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
use rocket::{ use rocket::{
@@ -7,6 +6,10 @@ use rocket::{
Outcome, Outcome,
}; };
use db_conn::DbConn;
use schema::api_tokens;
use {Error, Result};
#[derive(Clone, Queryable)] #[derive(Clone, Queryable)]
pub struct ApiToken { pub struct ApiToken {
pub id: i32, pub id: i32,
+3 -1
View File
@@ -1,7 +1,9 @@
use crate::{schema::apps, Error, Result};
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
use schema::apps;
use {Error, Result};
#[derive(Clone, Queryable, Serialize)] #[derive(Clone, Queryable, Serialize)]
pub struct App { pub struct App {
pub id: i32, pub id: i32,
+6 -3
View File
@@ -1,7 +1,9 @@
use crate::{schema::email_blocklist, Connection, Error, Result};
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, TextExpressionMethods}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, TextExpressionMethods};
use glob::Pattern; use glob::Pattern;
use schema::email_blocklist;
use {Connection, Error, Result};
#[derive(Clone, Queryable, Identifiable)] #[derive(Clone, Queryable, Identifiable)]
#[table_name = "email_blocklist"] #[table_name = "email_blocklist"]
pub struct BlocklistedEmail { pub struct BlocklistedEmail {
@@ -87,9 +89,10 @@ impl BlocklistedEmail {
#[cfg(test)] #[cfg(test)]
pub(crate) mod tests { pub(crate) mod tests {
use super::*; use super::*;
use crate::{instance::tests as instance_tests, tests::rockets, Connection as Conn};
use diesel::Connection; use diesel::Connection;
use instance::tests as instance_tests;
use tests::rockets;
use Connection as Conn;
pub(crate) fn fill_database(conn: &Conn) -> Vec<BlocklistedEmail> { pub(crate) fn fill_database(conn: &Conn) -> Vec<BlocklistedEmail> {
instance_tests::fill_database(conn); instance_tests::fill_database(conn);
let domainblock = let domainblock =
+3 -1
View File
@@ -1,6 +1,8 @@
use crate::{schema::blog_authors, Error, Result};
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
use schema::blog_authors;
use {Error, Result};
#[derive(Clone, Queryable, Identifiable)] #[derive(Clone, Queryable, Identifiable)]
pub struct BlogAuthor { pub struct BlogAuthor {
pub id: i32, pub id: i32,
+25 -25
View File
@@ -1,7 +1,3 @@
use crate::{
ap_url, instance::*, medias::Media, posts::Post, safe_string::SafeString, schema::blogs,
search::Searcher, users::User, Connection, Error, PlumeRocket, Result, ITEMS_PER_PAGE,
};
use activitypub::{ use activitypub::{
actor::Group, actor::Group,
collection::{OrderedCollection, OrderedCollectionPage}, collection::{OrderedCollection, OrderedCollectionPage},
@@ -16,13 +12,22 @@ use openssl::{
rsa::Rsa, rsa::Rsa,
sign::{Signer, Verifier}, sign::{Signer, Verifier},
}; };
use serde_json;
use url::Url;
use webfinger::*;
use instance::*;
use medias::Media;
use plume_common::activity_pub::{ use plume_common::activity_pub::{
inbox::{AsActor, FromId}, inbox::{AsActor, FromId},
sign, ActivityStream, ApSignature, Id, IntoId, PublicKey, Source, sign, ActivityStream, ApSignature, Id, IntoId, PublicKey, Source,
}; };
use serde_json; use posts::Post;
use url::Url; use safe_string::SafeString;
use webfinger::*; use schema::blogs;
use search::Searcher;
use users::User;
use {ap_url, Connection, Error, PlumeRocket, Result, ITEMS_PER_PAGE};
pub type CustomGroup = CustomObject<ApSignature, Group>; pub type CustomGroup = CustomObject<ApSignature, Group>;
@@ -101,8 +106,8 @@ impl Blog {
} }
pub fn list_authors(&self, conn: &Connection) -> Result<Vec<User>> { pub fn list_authors(&self, conn: &Connection) -> Result<Vec<User>> {
use crate::schema::blog_authors; use schema::blog_authors;
use crate::schema::users; use schema::users;
let authors_ids = blog_authors::table let authors_ids = blog_authors::table
.filter(blog_authors::blog_id.eq(self.id)) .filter(blog_authors::blog_id.eq(self.id))
.select(blog_authors::author_id); .select(blog_authors::author_id);
@@ -113,7 +118,7 @@ impl Blog {
} }
pub fn count_authors(&self, conn: &Connection) -> Result<i64> { pub fn count_authors(&self, conn: &Connection) -> Result<i64> {
use crate::schema::blog_authors; use schema::blog_authors;
blog_authors::table blog_authors::table
.filter(blog_authors::blog_id.eq(self.id)) .filter(blog_authors::blog_id.eq(self.id))
.count() .count()
@@ -122,7 +127,7 @@ impl Blog {
} }
pub fn find_for_author(conn: &Connection, author: &User) -> Result<Vec<Blog>> { pub fn find_for_author(conn: &Connection, author: &User) -> Result<Vec<Blog>> {
use crate::schema::blog_authors; use schema::blog_authors;
let author_ids = blog_authors::table let author_ids = blog_authors::table
.filter(blog_authors::author_id.eq(author.id)) .filter(blog_authors::author_id.eq(author.id))
.select(blog_authors::blog_id); .select(blog_authors::blog_id);
@@ -496,17 +501,14 @@ impl NewBlog {
#[cfg(test)] #[cfg(test)]
pub(crate) mod tests { pub(crate) mod tests {
use super::*; use super::*;
use crate::{ use blog_authors::*;
blog_authors::*,
config::CONFIG,
instance::tests as instance_tests,
medias::NewMedia,
search::tests::get_searcher,
tests::{db, rockets},
users::tests as usersTests,
Connection as Conn,
};
use diesel::Connection; use diesel::Connection;
use instance::tests as instance_tests;
use medias::NewMedia;
use search::tests::get_searcher;
use tests::{db, rockets};
use users::tests as usersTests;
use Connection as Conn;
pub(crate) fn fill_database(conn: &Conn) -> (Vec<User>, Vec<Blog>) { pub(crate) fn fill_database(conn: &Conn) -> (Vec<User>, Vec<Blog>) {
instance_tests::fill_database(conn); instance_tests::fill_database(conn);
@@ -768,9 +770,7 @@ pub(crate) mod tests {
conn.test_transaction::<_, (), _>(|| { conn.test_transaction::<_, (), _>(|| {
let (_, blogs) = fill_database(conn); let (_, blogs) = fill_database(conn);
blogs[0] blogs[0].delete(conn, &get_searcher()).unwrap();
.delete(conn, &get_searcher(&CONFIG.search_tokenizers))
.unwrap();
assert!(Blog::get(conn, blogs[0].id).is_err()); assert!(Blog::get(conn, blogs[0].id).is_err());
Ok(()) Ok(())
}) })
@@ -780,7 +780,7 @@ pub(crate) mod tests {
fn delete_via_user() { fn delete_via_user() {
let conn = &db(); let conn = &db();
conn.test_transaction::<_, (), _>(|| { conn.test_transaction::<_, (), _>(|| {
let searcher = get_searcher(&CONFIG.search_tokenizers); let searcher = get_searcher();
let (user, _) = fill_database(conn); let (user, _) = fill_database(conn);
let b1 = Blog::insert( let b1 = Blog::insert(
+5 -1
View File
@@ -1,6 +1,10 @@
use crate::{comments::Comment, schema::comment_seers, users::User, Connection, Error, Result};
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
use comments::Comment;
use schema::comment_seers;
use users::User;
use {Connection, Error, Result};
#[derive(Queryable, Clone)] #[derive(Queryable, Clone)]
pub struct CommentSeers { pub struct CommentSeers {
pub id: i32, pub id: i32,
+21 -22
View File
@@ -1,15 +1,3 @@
use crate::{
comment_seers::{CommentSeers, NewCommentSeers},
instance::Instance,
medias::Media,
mentions::Mention,
notifications::*,
posts::Post,
safe_string::SafeString,
schema::comments,
users::User,
Connection, Error, PlumeRocket, Result,
};
use activitypub::{ use activitypub::{
activity::{Create, Delete}, activity::{Create, Delete},
link, link,
@@ -17,16 +5,26 @@ use activitypub::{
}; };
use chrono::{self, NaiveDateTime}; use chrono::{self, NaiveDateTime};
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl};
use plume_common::{
activity_pub::{
inbox::{AsActor, AsObject, FromId},
Id, IntoId, PUBLIC_VISIBILITY,
},
utils,
};
use serde_json; use serde_json;
use std::collections::HashSet; use std::collections::HashSet;
use comment_seers::{CommentSeers, NewCommentSeers};
use instance::Instance;
use medias::Media;
use mentions::Mention;
use notifications::*;
use plume_common::activity_pub::{
inbox::{AsActor, AsObject, FromId},
Id, IntoId, PUBLIC_VISIBILITY,
};
use plume_common::utils;
use posts::Post;
use safe_string::SafeString;
use schema::comments;
use users::User;
use {Connection, Error, PlumeRocket, Result};
#[derive(Queryable, Identifiable, Clone, AsChangeset)] #[derive(Queryable, Identifiable, Clone, AsChangeset)]
pub struct Comment { pub struct Comment {
pub id: i32, pub id: i32,
@@ -79,7 +77,7 @@ impl Comment {
} }
pub fn count_local(conn: &Connection) -> Result<i64> { pub fn count_local(conn: &Connection) -> Result<i64> {
use crate::schema::users; use schema::users;
let local_authors = users::table let local_authors = users::table
.filter(users::instance_id.eq(Instance::get_local()?.id)) .filter(users::instance_id.eq(Instance::get_local()?.id))
.select(users::id); .select(users::id);
@@ -129,8 +127,9 @@ impl Comment {
)?))?; )?))?;
note.object_props note.object_props
.set_published_string(chrono::Utc::now().to_rfc3339())?; .set_published_string(chrono::Utc::now().to_rfc3339())?;
note.object_props.set_attributed_to_link(author.into_id())?; note.object_props
note.object_props.set_to_link_vec(to)?; .set_attributed_to_link(author.clone().into_id())?;
note.object_props.set_to_link_vec(to.clone())?;
note.object_props.set_tag_link_vec( note.object_props.set_tag_link_vec(
mentions mentions
.into_iter() .into_iter()
-63
View File
@@ -1,4 +1,3 @@
use crate::search::TokenizerKind as SearchTokenizer;
use rocket::config::Limits; use rocket::config::Limits;
use rocket::Config as RocketConfig; use rocket::Config as RocketConfig;
use std::env::{self, var}; use std::env::{self, var};
@@ -12,10 +11,7 @@ pub struct Config {
pub base_url: String, pub base_url: String,
pub database_url: String, pub database_url: String,
pub db_name: &'static str, pub db_name: &'static str,
pub db_max_size: Option<u32>,
pub db_min_idle: Option<u32>,
pub search_index: String, pub search_index: String,
pub search_tokenizers: SearchTokenizerConfig,
pub rocket: Result<RocketConfig, RocketError>, pub rocket: Result<RocketConfig, RocketError>,
pub logo: LogoConfig, pub logo: LogoConfig,
pub default_theme: String, pub default_theme: String,
@@ -190,56 +186,6 @@ impl Default for LogoConfig {
} }
} }
pub struct SearchTokenizerConfig {
pub tag_tokenizer: SearchTokenizer,
pub content_tokenizer: SearchTokenizer,
pub property_tokenizer: SearchTokenizer,
}
impl SearchTokenizerConfig {
pub fn init() -> Self {
use SearchTokenizer::*;
match var("SEARCH_LANG").ok().as_deref() {
Some("ja") => {
#[cfg(not(feature = "search-lindera"))]
panic!("You need build Plume with search-lindera feature, or execute it with SEARCH_TAG_TOKENIZER=ngram and SEARCH_CONTENT_TOKENIZER=ngram to enable Japanese search feature");
#[cfg(feature = "search-lindera")]
Self {
tag_tokenizer: Self::determine_tokenizer("SEARCH_TAG_TOKENIZER", Lindera),
content_tokenizer: Self::determine_tokenizer(
"SEARCH_CONTENT_TOKENIZER",
Lindera,
),
property_tokenizer: Ngram,
}
}
_ => Self {
tag_tokenizer: Self::determine_tokenizer("SEARCH_TAG_TOKENIZER", Whitespace),
content_tokenizer: Self::determine_tokenizer("SEARCH_CONTENT_TOKENIZER", Simple),
property_tokenizer: Ngram,
},
}
}
fn determine_tokenizer(var_name: &str, default: SearchTokenizer) -> SearchTokenizer {
use SearchTokenizer::*;
match var(var_name).ok().as_deref() {
Some("simple") => Simple,
Some("ngram") => Ngram,
Some("whitespace") => Whitespace,
Some("lindera") => {
#[cfg(not(feature = "search-lindera"))]
panic!("You need build Plume with search-lindera feature to use Lindera tokenizer");
#[cfg(feature = "search-lindera")]
Lindera
}
_ => default,
}
}
}
lazy_static! { lazy_static! {
pub static ref CONFIG: Config = Config { pub static ref CONFIG: Config = Config {
base_url: var("BASE_URL").unwrap_or_else(|_| format!( base_url: var("BASE_URL").unwrap_or_else(|_| format!(
@@ -247,21 +193,12 @@ lazy_static! {
var("ROCKET_PORT").unwrap_or_else(|_| "7878".to_owned()) var("ROCKET_PORT").unwrap_or_else(|_| "7878".to_owned())
)), )),
db_name: DB_NAME, db_name: DB_NAME,
db_max_size: var("DB_MAX_SIZE").map_or(None, |s| Some(
s.parse::<u32>()
.expect("Couldn't parse DB_MAX_SIZE into u32")
)),
db_min_idle: var("DB_MIN_IDLE").map_or(None, |s| Some(
s.parse::<u32>()
.expect("Couldn't parse DB_MIN_IDLE into u32")
)),
#[cfg(feature = "postgres")] #[cfg(feature = "postgres")]
database_url: var("DATABASE_URL") database_url: var("DATABASE_URL")
.unwrap_or_else(|_| format!("postgres://plume:plume@localhost/{}", DB_NAME)), .unwrap_or_else(|_| format!("postgres://plume:plume@localhost/{}", DB_NAME)),
#[cfg(feature = "sqlite")] #[cfg(feature = "sqlite")]
database_url: var("DATABASE_URL").unwrap_or_else(|_| format!("{}.sqlite", DB_NAME)), database_url: var("DATABASE_URL").unwrap_or_else(|_| format!("{}.sqlite", DB_NAME)),
search_index: var("SEARCH_INDEX").unwrap_or_else(|_| "search_index".to_owned()), search_index: var("SEARCH_INDEX").unwrap_or_else(|_| "search_index".to_owned()),
search_tokenizers: SearchTokenizerConfig::init(),
rocket: get_rocket_config(), rocket: get_rocket_config(),
logo: LogoConfig::default(), logo: LogoConfig::default(),
default_theme: var("DEFAULT_THEME").unwrap_or_else(|_| "default-light".to_owned()), default_theme: var("DEFAULT_THEME").unwrap_or_else(|_| "default-light".to_owned()),
+4 -2
View File
@@ -1,4 +1,3 @@
use crate::Connection;
use diesel::r2d2::{ use diesel::r2d2::{
ConnectionManager, CustomizeConnection, Error as ConnError, Pool, PooledConnection, ConnectionManager, CustomizeConnection, Error as ConnError, Pool, PooledConnection,
}; };
@@ -11,6 +10,8 @@ use rocket::{
}; };
use std::ops::Deref; use std::ops::Deref;
use Connection;
pub type DbPool = Pool<ConnectionManager<Connection>>; pub type DbPool = Pool<ConnectionManager<Connection>>;
// From rocket documentation // From rocket documentation
@@ -25,7 +26,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for DbConn {
type Error = (); type Error = ();
fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> { fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
let pool = request.guard::<State<'_, DbPool>>()?; let pool = request.guard::<State<DbPool>>()?;
match pool.get() { match pool.get() {
Ok(conn) => Outcome::Success(DbConn(conn)), Ok(conn) => Outcome::Success(DbConn(conn)),
Err(_) => Outcome::Failure((Status::ServiceUnavailable, ())), Err(_) => Outcome::Failure((Status::ServiceUnavailable, ())),
@@ -72,4 +73,5 @@ pub(crate) mod tests {
Ok(conn.begin_test_transaction().unwrap()) Ok(conn.begin_test_transaction().unwrap())
} }
} }
} }
+9 -6
View File
@@ -1,15 +1,16 @@
use crate::{
ap_url, notifications::*, schema::follows, users::User, Connection, Error, PlumeRocket, Result,
CONFIG,
};
use activitypub::activity::{Accept, Follow as FollowAct, Undo}; use activitypub::activity::{Accept, Follow as FollowAct, Undo};
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl};
use notifications::*;
use plume_common::activity_pub::{ use plume_common::activity_pub::{
broadcast, broadcast,
inbox::{AsActor, AsObject, FromId}, inbox::{AsActor, AsObject, FromId},
sign::Signer, sign::Signer,
Id, IntoId, PUBLIC_VISIBILITY, Id, IntoId, PUBLIC_VISIBILITY,
}; };
use schema::follows;
use users::User;
use {ap_url, Connection, Error, PlumeRocket, Result, CONFIG};
#[derive(Clone, Queryable, Identifiable, Associations, AsChangeset)] #[derive(Clone, Queryable, Identifiable, Associations, AsChangeset)]
#[belongs_to(User, foreign_key = "following_id")] #[belongs_to(User, foreign_key = "following_id")]
@@ -55,7 +56,8 @@ impl Follow {
let target = User::get(conn, self.following_id)?; let target = User::get(conn, self.following_id)?;
let mut act = FollowAct::default(); let mut act = FollowAct::default();
act.follow_props.set_actor_link::<Id>(user.into_id())?; act.follow_props
.set_actor_link::<Id>(user.clone().into_id())?;
act.follow_props act.follow_props
.set_object_link::<Id>(target.clone().into_id())?; .set_object_link::<Id>(target.clone().into_id())?;
act.object_props.set_id_string(self.ap_url.clone())?; act.object_props.set_id_string(self.ap_url.clone())?;
@@ -200,8 +202,9 @@ impl IntoId for Follow {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::{tests::db, users::tests as user_tests};
use diesel::Connection; use diesel::Connection;
use tests::db;
use users::tests as user_tests;
#[test] #[test]
fn test_id() { fn test_id() {
+10 -11
View File
@@ -1,16 +1,15 @@
use crate::{
ap_url,
medias::Media,
safe_string::SafeString,
schema::{instances, users},
users::{Role, User},
Connection, Error, Result,
};
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
use plume_common::utils::md_to_html;
use std::sync::RwLock; use std::sync::RwLock;
use ap_url;
use medias::Media;
use plume_common::utils::md_to_html;
use safe_string::SafeString;
use schema::{instances, users};
use users::{Role, User};
use {Connection, Error, Result};
#[derive(Clone, Identifiable, Queryable)] #[derive(Clone, Identifiable, Queryable)]
pub struct Instance { pub struct Instance {
pub id: i32, pub id: i32,
@@ -57,7 +56,6 @@ impl Instance {
.clone() .clone()
.ok_or(Error::NotFound) .ok_or(Error::NotFound)
} }
pub fn get_local_uncached(conn: &Connection) -> Result<Instance> { pub fn get_local_uncached(conn: &Connection) -> Result<Instance> {
instances::table instances::table
.filter(instances::local.eq(true)) .filter(instances::local.eq(true))
@@ -243,8 +241,9 @@ impl Instance {
#[cfg(test)] #[cfg(test)]
pub(crate) mod tests { pub(crate) mod tests {
use super::*; use super::*;
use crate::{tests::db, Connection as Conn};
use diesel::Connection; use diesel::Connection;
use tests::db;
use Connection as Conn;
pub(crate) fn fill_database(conn: &Conn) -> Vec<(NewInstance, Instance)> { pub(crate) fn fill_database(conn: &Conn) -> Vec<(NewInstance, Instance)> {
let res = vec![ let res = vec![
+30 -6
View File
@@ -1,21 +1,43 @@
#![feature(try_trait)] #![feature(try_trait)]
#![feature(never_type)] #![feature(never_type)]
#![feature(custom_attribute)]
#![feature(proc_macro_hygiene)] #![feature(proc_macro_hygiene)]
extern crate activitypub;
extern crate ammonia;
extern crate askama_escape;
extern crate bcrypt;
extern crate chrono;
#[macro_use] #[macro_use]
extern crate diesel; extern crate diesel;
extern crate guid_create;
extern crate heck;
extern crate itertools;
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;
extern crate migrations_internals;
extern crate openssl;
extern crate plume_api;
extern crate plume_common;
#[macro_use] #[macro_use]
extern crate plume_macro; extern crate plume_macro;
extern crate reqwest;
#[macro_use] #[macro_use]
extern crate rocket; extern crate rocket;
extern crate rocket_i18n;
extern crate scheduled_thread_pool;
extern crate serde;
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
#[macro_use] #[macro_use]
extern crate serde_json; extern crate serde_json;
#[macro_use] #[macro_use]
extern crate tantivy; extern crate tantivy;
extern crate glob;
extern crate url;
extern crate walkdir;
extern crate webfinger;
extern crate whatlang;
use plume_common::activity_pub::inbox::InboxError; use plume_common::activity_pub::inbox::InboxError;
@@ -228,13 +250,12 @@ macro_rules! get {
/// Model::insert(connection, NewModelType::new()); /// Model::insert(connection, NewModelType::new());
/// ``` /// ```
macro_rules! insert { macro_rules! insert {
($table:ident, $from:ty) => { ($table:ident, $from:ident) => {
insert!($table, $from, |x, _conn| Ok(x)); insert!($table, $from, |x, _conn| Ok(x));
}; };
($table:ident, $from:ty, |$val:ident, $conn:ident | $( $after:tt )+) => { ($table:ident, $from:ident, |$val:ident, $conn:ident | $( $after:tt )+) => {
last!($table); last!($table);
#[allow(dead_code)]
pub fn insert(conn: &crate::Connection, new: $from) -> Result<Self> { pub fn insert(conn: &crate::Connection, new: $from) -> Result<Self> {
diesel::insert_into($table::table) diesel::insert_into($table::table)
.values(new) .values(new)
@@ -261,7 +282,6 @@ macro_rules! insert {
/// ``` /// ```
macro_rules! last { macro_rules! last {
($table:ident) => { ($table:ident) => {
#[allow(dead_code)]
pub fn last(conn: &crate::Connection) -> Result<Self> { pub fn last(conn: &crate::Connection) -> Result<Self> {
$table::table $table::table
.order_by($table::id.desc()) .order_by($table::id.desc())
@@ -281,12 +301,16 @@ pub fn ap_url(url: &str) -> String {
#[cfg(test)] #[cfg(test)]
#[macro_use] #[macro_use]
mod tests { mod tests {
use crate::{db_conn, migrations::IMPORTED_MIGRATIONS, search, Connection as Conn, CONFIG}; use db_conn;
use diesel::r2d2::ConnectionManager; use diesel::r2d2::ConnectionManager;
use migrations::IMPORTED_MIGRATIONS;
use plume_common::utils::random_hex; use plume_common::utils::random_hex;
use scheduled_thread_pool::ScheduledThreadPool; use scheduled_thread_pool::ScheduledThreadPool;
use search;
use std::env::temp_dir; use std::env::temp_dir;
use std::sync::Arc; use std::sync::Arc;
use Connection as Conn;
use CONFIG;
#[macro_export] #[macro_export]
macro_rules! part_eq { macro_rules! part_eq {
@@ -320,7 +344,7 @@ mod tests {
pub fn rockets() -> super::PlumeRocket { pub fn rockets() -> super::PlumeRocket {
super::PlumeRocket { super::PlumeRocket {
conn: db_conn::DbConn((*DB_POOL).get().unwrap()), conn: db_conn::DbConn((*DB_POOL).get().unwrap()),
searcher: Arc::new(search::tests::get_searcher(&CONFIG.search_tokenizers)), searcher: Arc::new(search::tests::get_searcher()),
worker: Arc::new(ScheduledThreadPool::new(2)), worker: Arc::new(ScheduledThreadPool::new(2)),
user: None, user: None,
} }
+7 -4
View File
@@ -1,14 +1,17 @@
use crate::{
notifications::*, posts::Post, schema::likes, timeline::*, users::User, Connection, Error,
PlumeRocket, Result,
};
use activitypub::activity; use activitypub::activity;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
use notifications::*;
use plume_common::activity_pub::{ use plume_common::activity_pub::{
inbox::{AsActor, AsObject, FromId}, inbox::{AsActor, AsObject, FromId},
Id, IntoId, PUBLIC_VISIBILITY, Id, IntoId, PUBLIC_VISIBILITY,
}; };
use posts::Post;
use schema::likes;
use timeline::*;
use users::User;
use {Connection, Error, PlumeRocket, Result};
#[derive(Clone, Queryable, Identifiable)] #[derive(Clone, Queryable, Identifiable)]
pub struct Like { pub struct Like {
+10 -9
View File
@@ -1,11 +1,10 @@
use crate::{
blogs::Blog,
schema::{blogs, list_elems, lists, users},
users::User,
Connection, Error, Result,
};
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
use blogs::Blog;
use schema::{blogs, list_elems, lists, users};
use std::convert::{TryFrom, TryInto}; use std::convert::{TryFrom, TryInto};
use users::User;
use {Connection, Error, Result};
/// Represent what a list is supposed to store. Represented in database as an integer /// Represent what a list is supposed to store. Represented in database as an integer
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -165,7 +164,7 @@ impl List {
last!(lists); last!(lists);
get!(lists); get!(lists);
fn insert(conn: &Connection, val: NewList<'_>) -> Result<Self> { fn insert(conn: &Connection, val: NewList) -> Result<Self> {
diesel::insert_into(lists::table) diesel::insert_into(lists::table)
.values(val) .values(val)
.execute(conn)?; .execute(conn)?;
@@ -310,7 +309,7 @@ mod private {
}; };
impl ListElem { impl ListElem {
insert!(list_elems, NewListElem<'_>); insert!(list_elems, NewListElem);
pub fn user_in_list(conn: &Connection, list: &List, user: i32) -> Result<bool> { pub fn user_in_list(conn: &Connection, list: &List, user: i32) -> Result<bool> {
dsl::select(dsl::exists( dsl::select(dsl::exists(
@@ -360,8 +359,9 @@ mod private {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::{blogs::tests as blog_tests, tests::db}; use blogs::tests as blog_tests;
use diesel::Connection; use diesel::Connection;
use tests::db;
#[test] #[test]
fn list_type() { fn list_type() {
@@ -551,4 +551,5 @@ mod tests {
Ok(()) Ok(())
}); });
} }
} }
+15 -14
View File
@@ -1,17 +1,20 @@
use crate::{
ap_url, instance::Instance, safe_string::SafeString, schema::medias, users::User, Connection,
Error, PlumeRocket, Result,
};
use activitypub::object::Image; use activitypub::object::Image;
use askama_escape::escape; use askama_escape::escape;
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
use guid_create::GUID; use guid_create::GUID;
use reqwest;
use std::{fs, path::Path};
use plume_common::{ use plume_common::{
activity_pub::{inbox::FromId, Id}, activity_pub::{inbox::FromId, Id},
utils::MediaProcessor, utils::MediaProcessor,
}; };
use reqwest;
use std::{fs, path::Path}; use instance::Instance;
use safe_string::SafeString;
use schema::medias;
use users::User;
use {ap_url, Connection, Error, PlumeRocket, Result};
#[derive(Clone, Identifiable, Queryable)] #[derive(Clone, Identifiable, Queryable)]
pub struct Media { pub struct Media {
@@ -114,19 +117,15 @@ impl Media {
Ok(match self.category() { Ok(match self.category() {
MediaCategory::Image => SafeString::trusted(&format!( MediaCategory::Image => SafeString::trusted(&format!(
r#"<img src="{}" alt="{}" title="{}">"#, r#"<img src="{}" alt="{}" title="{}">"#,
url, url, escape(&self.alt_text), escape(&self.alt_text)
escape(&self.alt_text),
escape(&self.alt_text)
)), )),
MediaCategory::Audio => SafeString::trusted(&format!( MediaCategory::Audio => SafeString::trusted(&format!(
r#"<div class="media-preview audio"></div><audio src="{}" title="{}" controls></audio>"#, r#"<div class="media-preview audio"></div><audio src="{}" title="{}" controls></audio>"#,
url, url, escape(&self.alt_text)
escape(&self.alt_text)
)), )),
MediaCategory::Video => SafeString::trusted(&format!( MediaCategory::Video => SafeString::trusted(&format!(
r#"<video src="{}" title="{}" controls></video>"#, r#"<video src="{}" title="{}" controls></video>"#,
url, url, escape(&self.alt_text)
escape(&self.alt_text)
)), )),
MediaCategory::Unknown => SafeString::trusted(&format!( MediaCategory::Unknown => SafeString::trusted(&format!(
r#"<a href="{}" class="media-preview unknown"></a>"#, r#"<a href="{}" class="media-preview unknown"></a>"#,
@@ -260,11 +259,13 @@ impl Media {
#[cfg(test)] #[cfg(test)]
pub(crate) mod tests { pub(crate) mod tests {
use super::*; use super::*;
use crate::{tests::db, users::tests as usersTests, Connection as Conn};
use diesel::Connection; use diesel::Connection;
use std::env::{current_dir, set_current_dir}; use std::env::{current_dir, set_current_dir};
use std::fs; use std::fs;
use std::path::Path; use std::path::Path;
use tests::db;
use users::tests as usersTests;
use Connection as Conn;
pub(crate) fn fill_database(conn: &Conn) -> (Vec<User>, Vec<Media>) { pub(crate) fn fill_database(conn: &Conn) -> (Vec<User>, Vec<Media>) {
let mut wd = current_dir().unwrap().to_path_buf(); let mut wd = current_dir().unwrap().to_path_buf();
+8 -4
View File
@@ -1,10 +1,14 @@
use crate::{
comments::Comment, notifications::*, posts::Post, schema::mentions, users::User, Connection,
Error, PlumeRocket, Result,
};
use activitypub::link; use activitypub::link;
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
use comments::Comment;
use notifications::*;
use plume_common::activity_pub::inbox::AsActor; use plume_common::activity_pub::inbox::AsActor;
use posts::Post;
use schema::mentions;
use users::User;
use PlumeRocket;
use {Connection, Error, Result};
#[derive(Clone, Queryable, Identifiable)] #[derive(Clone, Queryable, Identifiable)]
pub struct Mention { pub struct Mention {
+6 -2
View File
@@ -1,12 +1,16 @@
use crate::{Connection, Error, Result}; use Connection;
use Error;
use Result;
use diesel::connection::{Connection as Conn, SimpleConnection}; use diesel::connection::{Connection as Conn, SimpleConnection};
use migrations_internals::{setup_database, MigrationConnection}; use migrations_internals::{setup_database, MigrationConnection};
use std::path::Path; use std::path::Path;
#[allow(dead_code)] //variants might not be constructed if not required by current migrations #[allow(dead_code)] //variants might not be constructed if not required by current migrations
enum Action { enum Action {
Sql(&'static str), Sql(&'static str),
Function(&'static dyn Fn(&Connection, &Path) -> Result<()>), Function(&'static Fn(&Connection, &Path) -> Result<()>),
} }
impl Action { impl Action {
+10 -11
View File
@@ -1,17 +1,16 @@
use crate::{
comments::Comment,
follows::Follow,
likes::Like,
mentions::Mention,
posts::Post,
reshares::Reshare,
schema::{follows, notifications},
users::User,
Connection, Error, Result,
};
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use diesel::{self, ExpressionMethods, JoinOnDsl, QueryDsl, RunQueryDsl}; use diesel::{self, ExpressionMethods, JoinOnDsl, QueryDsl, RunQueryDsl};
use comments::Comment;
use follows::Follow;
use likes::Like;
use mentions::Mention;
use posts::Post;
use reshares::Reshare;
use schema::{follows, notifications};
use users::User;
use {Connection, Error, Result};
pub mod notification_kind { pub mod notification_kind {
pub const COMMENT: &str = "COMMENT"; pub const COMMENT: &str = "COMMENT";
pub const FOLLOW: &str = "FOLLOW"; pub const FOLLOW: &str = "FOLLOW";
+4 -2
View File
@@ -1,6 +1,7 @@
use crate::{schema::password_reset_requests, Connection, Error, Result};
use chrono::{offset::Utc, Duration, NaiveDateTime}; use chrono::{offset::Utc, Duration, NaiveDateTime};
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl}; use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl};
use schema::password_reset_requests;
use {Connection, Error, Result};
#[derive(Clone, Identifiable, Queryable)] #[derive(Clone, Identifiable, Queryable)]
pub struct PasswordResetRequest { pub struct PasswordResetRequest {
@@ -74,8 +75,9 @@ impl PasswordResetRequest {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::{tests::db, users::tests as user_tests};
use diesel::Connection; use diesel::Connection;
use tests::db;
use users::tests as user_tests;
#[test] #[test]
fn test_insert_and_find_password_reset_request() { fn test_insert_and_find_password_reset_request() {
+11 -7
View File
@@ -2,7 +2,9 @@ pub use self::module::PlumeRocket;
#[cfg(not(test))] #[cfg(not(test))]
mod module { mod module {
use crate::{db_conn::DbConn, search, users}; use crate::db_conn::DbConn;
use crate::search;
use crate::users;
use rocket::{ use rocket::{
request::{self, FlashMessage, FromRequest, Request}, request::{self, FlashMessage, FromRequest, Request},
Outcome, State, Outcome, State,
@@ -27,9 +29,9 @@ mod module {
let conn = request.guard::<DbConn>()?; let conn = request.guard::<DbConn>()?;
let intl = request.guard::<rocket_i18n::I18n>()?; let intl = request.guard::<rocket_i18n::I18n>()?;
let user = request.guard::<users::User>().succeeded(); let user = request.guard::<users::User>().succeeded();
let worker = request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>()?; let worker = request.guard::<State<Arc<ScheduledThreadPool>>>()?;
let searcher = request.guard::<'_, State<'_, Arc<search::Searcher>>>()?; let searcher = request.guard::<State<Arc<search::Searcher>>>()?;
let flash_msg = request.guard::<FlashMessage<'_, '_>>().succeeded(); let flash_msg = request.guard::<FlashMessage>().succeeded();
Outcome::Success(PlumeRocket { Outcome::Success(PlumeRocket {
conn, conn,
intl, intl,
@@ -44,7 +46,9 @@ mod module {
#[cfg(test)] #[cfg(test)]
mod module { mod module {
use crate::{db_conn::DbConn, search, users}; use crate::db_conn::DbConn;
use crate::search;
use crate::users;
use rocket::{ use rocket::{
request::{self, FromRequest, Request}, request::{self, FromRequest, Request},
Outcome, State, Outcome, State,
@@ -66,8 +70,8 @@ mod module {
fn from_request(request: &'a Request<'r>) -> request::Outcome<PlumeRocket, ()> { fn from_request(request: &'a Request<'r>) -> request::Outcome<PlumeRocket, ()> {
let conn = request.guard::<DbConn>()?; let conn = request.guard::<DbConn>()?;
let user = request.guard::<users::User>().succeeded(); let user = request.guard::<users::User>().succeeded();
let worker = request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>()?; let worker = request.guard::<State<Arc<ScheduledThreadPool>>>()?;
let searcher = request.guard::<'_, State<'_, Arc<search::Searcher>>>()?; let searcher = request.guard::<State<Arc<search::Searcher>>>()?;
Outcome::Success(PlumeRocket { Outcome::Success(PlumeRocket {
conn, conn,
user, user,
+5 -1
View File
@@ -1,6 +1,10 @@
use crate::{posts::Post, schema::post_authors, users::User, Error, Result};
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
use posts::Post;
use schema::post_authors;
use users::User;
use {Error, Result};
#[derive(Clone, Queryable, Identifiable, Associations)] #[derive(Clone, Queryable, Identifiable, Associations)]
#[belongs_to(Post)] #[belongs_to(Post)]
#[belongs_to(User, foreign_key = "author_id")] #[belongs_to(User, foreign_key = "author_id")]
+30 -22
View File
@@ -1,8 +1,3 @@
use crate::{
ap_url, blogs::Blog, instance::Instance, medias::Media, mentions::Mention, post_authors::*,
safe_string::SafeString, schema::posts, search::Searcher, tags::*, timeline::*, users::User,
Connection, Error, PlumeRocket, Result, CONFIG,
};
use activitypub::{ use activitypub::{
activity::{Create, Delete, Update}, activity::{Create, Delete, Update},
link, link,
@@ -12,6 +7,13 @@ use activitypub::{
use chrono::{NaiveDateTime, TimeZone, Utc}; use chrono::{NaiveDateTime, TimeZone, Utc};
use diesel::{self, BelongingToDsl, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl}; use diesel::{self, BelongingToDsl, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl};
use heck::{CamelCase, KebabCase}; use heck::{CamelCase, KebabCase};
use serde_json;
use std::collections::HashSet;
use blogs::Blog;
use instance::Instance;
use medias::Media;
use mentions::Mention;
use plume_common::{ use plume_common::{
activity_pub::{ activity_pub::{
inbox::{AsObject, FromId}, inbox::{AsObject, FromId},
@@ -19,8 +21,14 @@ use plume_common::{
}, },
utils::md_to_html, utils::md_to_html,
}; };
use serde_json; use post_authors::*;
use std::collections::HashSet; use safe_string::SafeString;
use schema::posts;
use search::Searcher;
use tags::*;
use timeline::*;
use users::User;
use {ap_url, Connection, Error, PlumeRocket, Result, CONFIG};
pub type LicensedArticle = CustomObject<Licensed, Article>; pub type LicensedArticle = CustomObject<Licensed, Article>;
@@ -103,7 +111,7 @@ impl Post {
tag: String, tag: String,
(min, max): (i32, i32), (min, max): (i32, i32),
) -> Result<Vec<Post>> { ) -> Result<Vec<Post>> {
use crate::schema::tags; use schema::tags;
let ids = tags::table.filter(tags::tag.eq(tag)).select(tags::post_id); let ids = tags::table.filter(tags::tag.eq(tag)).select(tags::post_id);
posts::table posts::table
@@ -117,7 +125,7 @@ impl Post {
} }
pub fn count_for_tag(conn: &Connection, tag: String) -> Result<i64> { pub fn count_for_tag(conn: &Connection, tag: String) -> Result<i64> {
use crate::schema::tags; use schema::tags;
let ids = tags::table.filter(tags::tag.eq(tag)).select(tags::post_id); let ids = tags::table.filter(tags::tag.eq(tag)).select(tags::post_id);
posts::table posts::table
.filter(posts::id.eq_any(ids)) .filter(posts::id.eq_any(ids))
@@ -131,8 +139,8 @@ impl Post {
} }
pub fn count_local(conn: &Connection) -> Result<i64> { pub fn count_local(conn: &Connection) -> Result<i64> {
use crate::schema::post_authors; use schema::post_authors;
use crate::schema::users; use schema::users;
let local_authors = users::table let local_authors = users::table
.filter(users::instance_id.eq(Instance::get_local()?.id)) .filter(users::instance_id.eq(Instance::get_local()?.id))
.select(users::id); .select(users::id);
@@ -180,7 +188,7 @@ impl Post {
author: &User, author: &User,
limit: i64, limit: i64,
) -> Result<Vec<Post>> { ) -> Result<Vec<Post>> {
use crate::schema::post_authors; use schema::post_authors;
let posts = PostAuthor::belonging_to(author).select(post_authors::post_id); let posts = PostAuthor::belonging_to(author).select(post_authors::post_id);
posts::table posts::table
@@ -231,7 +239,7 @@ impl Post {
} }
pub fn drafts_by_author(conn: &Connection, author: &User) -> Result<Vec<Post>> { pub fn drafts_by_author(conn: &Connection, author: &User) -> Result<Vec<Post>> {
use crate::schema::post_authors; use schema::post_authors;
let posts = PostAuthor::belonging_to(author).select(post_authors::post_id); let posts = PostAuthor::belonging_to(author).select(post_authors::post_id);
posts::table posts::table
@@ -243,8 +251,8 @@ impl Post {
} }
pub fn get_authors(&self, conn: &Connection) -> Result<Vec<User>> { pub fn get_authors(&self, conn: &Connection) -> Result<Vec<User>> {
use crate::schema::post_authors; use schema::post_authors;
use crate::schema::users; use schema::users;
let author_list = PostAuthor::belonging_to(self).select(post_authors::author_id); let author_list = PostAuthor::belonging_to(self).select(post_authors::author_id);
users::table users::table
.filter(users::id.eq_any(author_list)) .filter(users::id.eq_any(author_list))
@@ -253,7 +261,7 @@ impl Post {
} }
pub fn is_author(&self, conn: &Connection, author_id: i32) -> Result<bool> { pub fn is_author(&self, conn: &Connection, author_id: i32) -> Result<bool> {
use crate::schema::post_authors; use schema::post_authors;
Ok(PostAuthor::belonging_to(self) Ok(PostAuthor::belonging_to(self)
.filter(post_authors::author_id.eq(author_id)) .filter(post_authors::author_id.eq(author_id))
.count() .count()
@@ -262,7 +270,7 @@ impl Post {
} }
pub fn get_blog(&self, conn: &Connection) -> Result<Blog> { pub fn get_blog(&self, conn: &Connection) -> Result<Blog> {
use crate::schema::blogs; use schema::blogs;
blogs::table blogs::table
.filter(blogs::id.eq(self.blog_id)) .filter(blogs::id.eq(self.blog_id))
.first(conn) .first(conn)
@@ -270,7 +278,7 @@ impl Post {
} }
pub fn count_likes(&self, conn: &Connection) -> Result<i64> { pub fn count_likes(&self, conn: &Connection) -> Result<i64> {
use crate::schema::likes; use schema::likes;
likes::table likes::table
.filter(likes::post_id.eq(self.id)) .filter(likes::post_id.eq(self.id))
.count() .count()
@@ -279,7 +287,7 @@ impl Post {
} }
pub fn count_reshares(&self, conn: &Connection) -> Result<i64> { pub fn count_reshares(&self, conn: &Connection) -> Result<i64> {
use crate::schema::reshares; use schema::reshares;
reshares::table reshares::table
.filter(reshares::post_id.eq(self.id)) .filter(reshares::post_id.eq(self.id))
.count() .count()
@@ -624,7 +632,7 @@ impl FromId<PlumeRocket> for Post {
.into_iter() .into_iter()
.map(|s| s.to_camel_case()) .map(|s| s.to_camel_case())
.collect::<HashSet<_>>(); .collect::<HashSet<_>>();
if let Some(serde_json::Value::Array(tags)) = article.object_props.tag { if let Some(serde_json::Value::Array(tags)) = article.object_props.tag.clone() {
for tag in tags { for tag in tags {
serde_json::from_value::<link::Mention>(tag.clone()) serde_json::from_value::<link::Mention>(tag.clone())
.map(|m| Mention::from_activity(conn, &m, post.id, true, true)) .map(|m| Mention::from_activity(conn, &m, post.id, true, true))
@@ -717,7 +725,7 @@ impl FromId<PlumeRocket> for PostUpdate {
.ok() .ok()
.map(|x| x.content), .map(|x| x.content),
license: updated.custom_props.license_string().ok(), license: updated.custom_props.license_string().ok(),
tags: updated.object.object_props.tag, tags: updated.object.object_props.tag.clone(),
}) })
} }
} }
@@ -798,7 +806,7 @@ impl AsObject<User, Update, &PlumeRocket> for PostUpdate {
impl IntoId for Post { impl IntoId for Post {
fn into_id(self) -> Id { fn into_id(self) -> Id {
Id::new(self.ap_url) Id::new(self.ap_url.clone())
} }
} }
+7 -4
View File
@@ -1,14 +1,17 @@
use crate::{
notifications::*, posts::Post, schema::reshares, timeline::*, users::User, Connection, Error,
PlumeRocket, Result,
};
use activitypub::activity::{Announce, Undo}; use activitypub::activity::{Announce, Undo};
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
use notifications::*;
use plume_common::activity_pub::{ use plume_common::activity_pub::{
inbox::{AsActor, AsObject, FromId}, inbox::{AsActor, AsObject, FromId},
Id, IntoId, PUBLIC_VISIBILITY, Id, IntoId, PUBLIC_VISIBILITY,
}; };
use posts::Post;
use schema::reshares;
use timeline::*;
use users::User;
use {Connection, Error, PlumeRocket, Result};
#[derive(Clone, Queryable, Identifiable)] #[derive(Clone, Queryable, Identifiable)]
pub struct Reshare { pub struct Reshare {
+4 -4
View File
@@ -82,7 +82,7 @@ lazy_static! {
}; };
} }
fn url_add_prefix(url: &str) -> Option<Cow<'_, str>> { fn url_add_prefix(url: &str) -> Option<Cow<str>> {
if url.starts_with('#') && !url.starts_with("#postcontent-") { if url.starts_with('#') && !url.starts_with("#postcontent-") {
//if start with an # //if start with an #
let mut new_url = "#postcontent-".to_owned(); //change to valid id let mut new_url = "#postcontent-".to_owned(); //change to valid id
@@ -139,7 +139,7 @@ struct SafeStringVisitor;
impl<'de> Visitor<'de> for SafeStringVisitor { impl<'de> Visitor<'de> for SafeStringVisitor {
type Value = SafeString; type Value = SafeString;
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("a string") formatter.write_str("a string")
} }
@@ -181,7 +181,7 @@ where
DB: diesel::backend::Backend, DB: diesel::backend::Backend,
str: ToSql<diesel::sql_types::Text, DB>, str: ToSql<diesel::sql_types::Text, DB>,
{ {
fn to_sql<W: Write>(&self, out: &mut Output<'_, W, DB>) -> serialize::Result { fn to_sql<W: Write>(&self, out: &mut Output<W, DB>) -> serialize::Result {
str::to_sql(&self.value, out) str::to_sql(&self.value, out)
} }
} }
@@ -193,7 +193,7 @@ impl Borrow<str> for SafeString {
} }
impl Display for SafeString { impl Display for SafeString {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.value) write!(f, "{}", self.value)
} }
} }
-1
View File
@@ -29,7 +29,6 @@ table! {
is_owner -> Bool, is_owner -> Bool,
} }
} }
table! { table! {
blogs (id) { blogs (id) {
id -> Int4, id -> Int4,
+18 -82
View File
@@ -3,32 +3,27 @@ mod searcher;
mod tokenizer; mod tokenizer;
pub use self::query::PlumeQuery as Query; pub use self::query::PlumeQuery as Query;
pub use self::searcher::*; pub use self::searcher::*;
pub use self::tokenizer::TokenizerKind;
#[cfg(test)] #[cfg(test)]
pub(crate) mod tests { pub(crate) mod tests {
use super::{Query, Searcher, TokenizerKind}; use super::{Query, Searcher};
use diesel::Connection; use diesel::Connection;
use plume_common::utils::random_hex;
use std::env::temp_dir; use std::env::temp_dir;
use std::str::FromStr; use std::str::FromStr;
use crate::{ use blogs::tests::fill_database;
blogs::tests::fill_database, use plume_common::utils::random_hex;
config::SearchTokenizerConfig, use post_authors::*;
post_authors::*, use posts::{NewPost, Post};
posts::{NewPost, Post}, use safe_string::SafeString;
safe_string::SafeString, use tests::db;
tests::db,
CONFIG,
};
pub(crate) fn get_searcher(tokenizers: &SearchTokenizerConfig) -> Searcher { pub(crate) fn get_searcher() -> Searcher {
let dir = temp_dir().join(&format!("plume-test-{}", random_hex())); let dir = temp_dir().join(&format!("plume-test-{}", random_hex()));
if dir.exists() { if dir.exists() {
Searcher::open(&dir, tokenizers) Searcher::open(&dir)
} else { } else {
Searcher::create(&dir, tokenizers) Searcher::create(&dir)
} }
.unwrap() .unwrap()
} }
@@ -103,27 +98,27 @@ pub(crate) mod tests {
fn open() { fn open() {
let dir = temp_dir().join(format!("plume-test-{}", random_hex())); let dir = temp_dir().join(format!("plume-test-{}", random_hex()));
{ {
Searcher::create(&dir, &CONFIG.search_tokenizers).unwrap(); Searcher::create(&dir).unwrap();
} }
Searcher::open(&dir, &CONFIG.search_tokenizers).unwrap(); Searcher::open(&dir).unwrap();
} }
#[test] #[test]
fn create() { fn create() {
let dir = temp_dir().join(format!("plume-test-{}", random_hex())); let dir = temp_dir().join(format!("plume-test-{}", random_hex()));
assert!(Searcher::open(&dir, &CONFIG.search_tokenizers).is_err()); assert!(Searcher::open(&dir).is_err());
{ {
Searcher::create(&dir, &CONFIG.search_tokenizers).unwrap(); Searcher::create(&dir).unwrap();
} }
Searcher::open(&dir, &CONFIG.search_tokenizers).unwrap(); //verify it's well created Searcher::open(&dir).unwrap(); //verify it's well created
} }
#[test] #[test]
fn search() { fn search() {
let conn = &db(); let conn = &db();
conn.test_transaction::<_, (), _>(|| { conn.test_transaction::<_, (), _>(|| {
let searcher = get_searcher(&CONFIG.search_tokenizers); let searcher = get_searcher();
let blog = &fill_database(conn).1[0]; let blog = &fill_database(conn).1[0];
let author = &blog.list_authors(conn).unwrap()[0]; let author = &blog.list_authors(conn).unwrap()[0];
@@ -183,69 +178,10 @@ pub(crate) mod tests {
}); });
} }
#[cfg(feature = "search-lindera")]
#[test]
fn search_japanese() {
let conn = &db();
conn.test_transaction::<_, (), _>(|| {
let tokenizers = SearchTokenizerConfig {
tag_tokenizer: TokenizerKind::Lindera,
content_tokenizer: TokenizerKind::Lindera,
property_tokenizer: TokenizerKind::Ngram,
};
let searcher = get_searcher(&tokenizers);
let blog = &fill_database(conn).1[0];
let title = random_hex()[..8].to_owned();
let post = Post::insert(
conn,
NewPost {
blog_id: blog.id,
slug: title.clone(),
title: title.clone(),
content: SafeString::new("ブログエンジンPlumeです。"),
published: true,
license: "CC-BY-SA".to_owned(),
ap_url: "".to_owned(),
creation_date: None,
subtitle: "".to_owned(),
source: "".to_owned(),
cover_id: None,
},
&searcher,
)
.unwrap();
searcher.commit();
assert_eq!(
searcher.search_document(conn, Query::from_str("ブログエンジン").unwrap(), (0, 1))
[0]
.id,
post.id
);
assert_eq!(
searcher.search_document(conn, Query::from_str("Plume").unwrap(), (0, 1))[0].id,
post.id
);
assert_eq!(
searcher.search_document(conn, Query::from_str("です").unwrap(), (0, 1))[0].id,
post.id
);
assert_eq!(
searcher.search_document(conn, Query::from_str("").unwrap(), (0, 1))[0].id,
post.id
);
Ok(())
});
}
#[test] #[test]
fn drop_writer() { fn drop_writer() {
let searcher = get_searcher(&CONFIG.search_tokenizers); let searcher = get_searcher();
searcher.drop_writer(); searcher.drop_writer();
get_searcher(&CONFIG.search_tokenizers); get_searcher();
} }
} }
+3 -3
View File
@@ -1,5 +1,5 @@
use crate::search::searcher::Searcher;
use chrono::{naive::NaiveDate, offset::Utc, Datelike}; use chrono::{naive::NaiveDate, offset::Utc, Datelike};
use search::searcher::Searcher;
use std::{cmp, ops::Bound}; use std::{cmp, ops::Bound};
use tantivy::{query::*, schema::*, Term}; use tantivy::{query::*, schema::*, Term};
@@ -153,7 +153,7 @@ impl PlumeQuery {
/// Convert this Query to a Tantivy Query /// Convert this Query to a Tantivy Query
pub fn into_query(self) -> BooleanQuery { pub fn into_query(self) -> BooleanQuery {
let mut result: Vec<(Occur, Box<dyn Query>)> = Vec::new(); let mut result: Vec<(Occur, Box<Query>)> = Vec::new();
gen_to_query!(self, result; normal: title, subtitle, content, tag; gen_to_query!(self, result; normal: title, subtitle, content, tag;
oneoff: instance, author, blog, lang, license); oneoff: instance, author, blog, lang, license);
@@ -279,7 +279,7 @@ impl PlumeQuery {
} }
// map a token and it's field to a query // map a token and it's field to a query
fn token_to_query(token: &str, field_name: &str) -> Box<dyn Query> { fn token_to_query(token: &str, field_name: &str) -> Box<Query> {
let token = token.to_lowercase(); let token = token.to_lowercase();
let token = token.as_str(); let token = token.as_str();
let field = Searcher::schema().get_field(field_name).unwrap(); let field = Searcher::schema().get_field(field_name).unwrap();
+42 -35
View File
@@ -1,17 +1,23 @@
use crate::{ use instance::Instance;
config::SearchTokenizerConfig, instance::Instance, posts::Post, schema::posts, use posts::Post;
search::query::PlumeQuery, tags::Tag, Connection, Result, use schema::posts;
}; use tags::Tag;
use Connection;
use chrono::Datelike; use chrono::Datelike;
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl}; use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl};
use itertools::Itertools; use itertools::Itertools;
use std::{cmp, fs::create_dir_all, path::Path, sync::Mutex}; use std::{cmp, fs::create_dir_all, path::Path, sync::Mutex};
use tantivy::{ use tantivy::{
collector::TopDocs, directory::MmapDirectory, schema::*, Index, IndexReader, IndexWriter, collector::TopDocs, directory::MmapDirectory, schema::*, tokenizer::*, Index, IndexReader,
ReloadPolicy, Term, IndexWriter, ReloadPolicy, Term,
}; };
use whatlang::{detect as detect_lang, Lang}; use whatlang::{detect as detect_lang, Lang};
use super::tokenizer;
use search::query::PlumeQuery;
use Result;
#[derive(Debug)] #[derive(Debug)]
pub enum SearcherError { pub enum SearcherError {
IndexCreationError, IndexCreationError,
@@ -30,7 +36,7 @@ impl Searcher {
pub fn schema() -> Schema { pub fn schema() -> Schema {
let tag_indexing = TextOptions::default().set_indexing_options( let tag_indexing = TextOptions::default().set_indexing_options(
TextFieldIndexing::default() TextFieldIndexing::default()
.set_tokenizer("tag_tokenizer") .set_tokenizer("whitespace_tokenizer")
.set_index_option(IndexRecordOption::Basic), .set_index_option(IndexRecordOption::Basic),
); );
@@ -66,7 +72,15 @@ impl Searcher {
schema_builder.build() schema_builder.build()
} }
pub fn create(path: &dyn AsRef<Path>, tokenizers: &SearchTokenizerConfig) -> Result<Self> { pub fn create(path: &AsRef<Path>) -> Result<Self> {
let whitespace_tokenizer = tokenizer::WhitespaceTokenizer.filter(LowerCaser);
let content_tokenizer = SimpleTokenizer
.filter(RemoveLongFilter::limit(40))
.filter(LowerCaser);
let property_tokenizer = NgramTokenizer::new(2, 8, false).filter(LowerCaser);
let schema = Self::schema(); let schema = Self::schema();
create_dir_all(path).map_err(|_| SearcherError::IndexCreationError)?; create_dir_all(path).map_err(|_| SearcherError::IndexCreationError)?;
@@ -78,9 +92,9 @@ impl Searcher {
{ {
let tokenizer_manager = index.tokenizers(); let tokenizer_manager = index.tokenizers();
tokenizer_manager.register("tag_tokenizer", tokenizers.tag_tokenizer); tokenizer_manager.register("whitespace_tokenizer", whitespace_tokenizer);
tokenizer_manager.register("content_tokenizer", tokenizers.content_tokenizer); tokenizer_manager.register("content_tokenizer", content_tokenizer);
tokenizer_manager.register("property_tokenizer", tokenizers.property_tokenizer); tokenizer_manager.register("property_tokenizer", property_tokenizer);
} //to please the borrow checker } //to please the borrow checker
Ok(Self { Ok(Self {
writer: Mutex::new(Some( writer: Mutex::new(Some(
@@ -97,38 +111,31 @@ impl Searcher {
}) })
} }
pub fn open(path: &dyn AsRef<Path>, tokenizers: &SearchTokenizerConfig) -> Result<Self> { pub fn open(path: &AsRef<Path>) -> Result<Self> {
let mut index = let whitespace_tokenizer = tokenizer::WhitespaceTokenizer.filter(LowerCaser);
let content_tokenizer = SimpleTokenizer
.filter(RemoveLongFilter::limit(40))
.filter(LowerCaser);
let property_tokenizer = NgramTokenizer::new(2, 8, false).filter(LowerCaser);
let index =
Index::open(MmapDirectory::open(path).map_err(|_| SearcherError::IndexOpeningError)?) Index::open(MmapDirectory::open(path).map_err(|_| SearcherError::IndexOpeningError)?)
.map_err(|_| SearcherError::IndexOpeningError)?; .map_err(|_| SearcherError::IndexOpeningError)?;
{ {
let tokenizer_manager = index.tokenizers(); let tokenizer_manager = index.tokenizers();
tokenizer_manager.register("tag_tokenizer", tokenizers.tag_tokenizer); tokenizer_manager.register("whitespace_tokenizer", whitespace_tokenizer);
tokenizer_manager.register("content_tokenizer", tokenizers.content_tokenizer); tokenizer_manager.register("content_tokenizer", content_tokenizer);
tokenizer_manager.register("property_tokenizer", tokenizers.property_tokenizer); tokenizer_manager.register("property_tokenizer", property_tokenizer);
} //to please the borrow checker } //to please the borrow checker
let writer = index let mut writer = index
.writer(50_000_000) .writer(50_000_000)
.map_err(|_| SearcherError::WriteLockAcquisitionError)?; .map_err(|_| SearcherError::WriteLockAcquisitionError)?;
writer
// Since Tantivy v0.12.0, IndexWriter::garbage_collect_files() returns Future. .garbage_collect_files()
// To avoid conflict with Plume async project, we don't introduce async now.
// After async is introduced to Plume, we can use garbage_collect_files() again.
// Algorithm stolen from Tantivy's SegmentUpdater::list_files()
use std::collections::HashSet;
use std::path::PathBuf;
let mut files: HashSet<PathBuf> = index
.list_all_segment_metas()
.into_iter()
.flat_map(|segment_meta| segment_meta.list_files())
.collect();
files.insert(Path::new("meta.json").to_path_buf());
index
.directory_mut()
.garbage_collect(|| files)
.map_err(|_| SearcherError::IndexEditionError)?; .map_err(|_| SearcherError::IndexEditionError)?;
Ok(Self { Ok(Self {
writer: Mutex::new(Some(writer)), writer: Mutex::new(Some(writer)),
reader: index reader: index
@@ -168,7 +175,7 @@ impl Searcher {
post_id => i64::from(post.id), post_id => i64::from(post.id),
author => post.get_authors(conn)?.into_iter().map(|u| u.fqn).join(" "), author => post.get_authors(conn)?.into_iter().map(|u| u.fqn).join(" "),
creation_date => i64::from(post.creation_date.num_days_from_ce()), creation_date => i64::from(post.creation_date.num_days_from_ce()),
instance => Instance::get(conn, post.get_blog(conn)?.instance_id)?.public_domain, instance => Instance::get(conn, post.get_blog(conn)?.instance_id)?.public_domain.clone(),
tag => Tag::for_post(conn, post.id)?.into_iter().map(|t| t.tag).join(" "), tag => Tag::for_post(conn, post.id)?.into_iter().map(|t| t.tag).join(" "),
blog_name => post.get_blog(conn)?.title, blog_name => post.get_blog(conn)?.title,
content => post.content.get().clone(), content => post.content.get().clone(),
+7 -34
View File
@@ -1,34 +1,5 @@
#[cfg(feature = "search-lindera")]
use lindera_tantivy::tokenizer::LinderaTokenizer;
use std::str::CharIndices; use std::str::CharIndices;
use tantivy::tokenizer::*; use tantivy::tokenizer::{Token, TokenStream, Tokenizer};
#[derive(Clone, Copy)]
pub enum TokenizerKind {
Simple,
Ngram,
Whitespace,
#[cfg(feature = "search-lindera")]
Lindera,
}
impl From<TokenizerKind> for TextAnalyzer {
fn from(tokenizer: TokenizerKind) -> TextAnalyzer {
use TokenizerKind::*;
match tokenizer {
Simple => TextAnalyzer::from(SimpleTokenizer)
.filter(RemoveLongFilter::limit(40))
.filter(LowerCaser),
Ngram => TextAnalyzer::from(NgramTokenizer::new(2, 8, false)).filter(LowerCaser),
Whitespace => TextAnalyzer::from(WhitespaceTokenizer).filter(LowerCaser),
#[cfg(feature = "search-lindera")]
Lindera => {
TextAnalyzer::from(LinderaTokenizer::new("decompose", "")).filter(LowerCaser)
}
}
}
}
/// Tokenize the text by splitting on whitespaces. Pretty much a copy of Tantivy's SimpleTokenizer, /// Tokenize the text by splitting on whitespaces. Pretty much a copy of Tantivy's SimpleTokenizer,
/// but not splitting on punctuation /// but not splitting on punctuation
@@ -41,13 +12,15 @@ pub struct WhitespaceTokenStream<'a> {
token: Token, token: Token,
} }
impl Tokenizer for WhitespaceTokenizer { impl<'a> Tokenizer<'a> for WhitespaceTokenizer {
fn token_stream<'a>(&self, text: &'a str) -> BoxTokenStream<'a> { type TokenStreamImpl = WhitespaceTokenStream<'a>;
BoxTokenStream::from(WhitespaceTokenStream {
fn token_stream(&self, text: &'a str) -> Self::TokenStreamImpl {
WhitespaceTokenStream {
text, text,
chars: text.char_indices(), chars: text.char_indices(),
token: Token::default(), token: Token::default(),
}) }
} }
} }
impl<'a> WhitespaceTokenStream<'a> { impl<'a> WhitespaceTokenStream<'a> {
+4 -1
View File
@@ -1,6 +1,9 @@
use crate::{ap_url, instance::Instance, schema::tags, Connection, Error, Result};
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl}; use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
use instance::Instance;
use plume_common::activity_pub::Hashtag; use plume_common::activity_pub::Hashtag;
use schema::tags;
use {ap_url, Connection, Error, Result};
#[derive(Clone, Identifiable, Queryable)] #[derive(Clone, Identifiable, Queryable)]
pub struct Tag { pub struct Tag {
+22 -23
View File
@@ -1,17 +1,17 @@
use crate::{
lists::List,
posts::Post,
schema::{posts, timeline, timeline_definition},
Connection, Error, PlumeRocket, Result,
};
use diesel::{self, BoolExpressionMethods, ExpressionMethods, QueryDsl, RunQueryDsl}; use diesel::{self, BoolExpressionMethods, ExpressionMethods, QueryDsl, RunQueryDsl};
use lists::List;
use posts::Post;
use schema::{posts, timeline, timeline_definition};
use std::ops::Deref; use std::ops::Deref;
use {Connection, Error, PlumeRocket, Result};
pub(crate) mod query; pub(crate) mod query;
pub use self::query::Kind;
use self::query::{QueryError, TimelineQuery}; use self::query::{QueryError, TimelineQuery};
pub use self::query::Kind;
#[derive(Clone, Debug, PartialEq, Queryable, Identifiable, AsChangeset)] #[derive(Clone, Debug, PartialEq, Queryable, Identifiable, AsChangeset)]
#[table_name = "timeline_definition"] #[table_name = "timeline_definition"]
pub struct Timeline { pub struct Timeline {
@@ -119,7 +119,7 @@ impl Timeline {
} }
}) })
{ {
return Err(err); Err(err)?;
} }
} }
Self::insert( Self::insert(
@@ -157,7 +157,7 @@ impl Timeline {
} }
}) })
{ {
return Err(err); Err(err)?;
} }
} }
Self::insert( Self::insert(
@@ -208,7 +208,7 @@ impl Timeline {
.map_err(Error::from) .map_err(Error::from)
} }
pub fn add_to_all_timelines(rocket: &PlumeRocket, post: &Post, kind: Kind<'_>) -> Result<()> { pub fn add_to_all_timelines(rocket: &PlumeRocket, post: &Post, kind: Kind) -> Result<()> {
let timelines = timeline_definition::table let timelines = timeline_definition::table
.load::<Self>(rocket.conn.deref()) .load::<Self>(rocket.conn.deref())
.map_err(Error::from)?; .map_err(Error::from)?;
@@ -231,7 +231,7 @@ impl Timeline {
Ok(()) Ok(())
} }
pub fn matches(&self, rocket: &PlumeRocket, post: &Post, kind: Kind<'_>) -> Result<bool> { pub fn matches(&self, rocket: &PlumeRocket, post: &Post, kind: Kind) -> Result<bool> {
let query = TimelineQuery::parse(&self.query)?; let query = TimelineQuery::parse(&self.query)?;
query.matches(rocket, self, post, kind) query.matches(rocket, self, post, kind)
} }
@@ -240,18 +240,16 @@ impl Timeline {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::{ use blogs::tests as blogTests;
blogs::tests as blogTests,
follows::*,
lists::ListType,
post_authors::{NewPostAuthor, PostAuthor},
posts::NewPost,
safe_string::SafeString,
tags::Tag,
tests::{db, rockets},
users::tests as userTests,
};
use diesel::Connection; use diesel::Connection;
use follows::*;
use lists::ListType;
use post_authors::{NewPostAuthor, PostAuthor};
use posts::NewPost;
use safe_string::SafeString;
use tags::Tag;
use tests::{db, rockets};
use users::tests as userTests;
#[test] #[test]
fn test_timeline() { fn test_timeline() {
@@ -497,7 +495,8 @@ mod tests {
), ),
published: true, published: true,
license: "GPL".to_string(), license: "GPL".to_string(),
source: "Actually, GNU+Linux, GNU×Linux, or GNU¿Linux are better.".to_string(), source: "Actually, GNU+Linux, GNU×Linux, or GNU¿Linux are better."
.to_string(),
ap_url: "".to_string(), ap_url: "".to_string(),
creation_date: None, creation_date: None,
subtitle: "".to_string(), subtitle: "".to_string(),
+24 -33
View File
@@ -1,15 +1,15 @@
use crate::{ use blogs::Blog;
blogs::Blog, use lists::{self, ListType};
lists::{self, ListType},
posts::Post,
tags::Tag,
timeline::Timeline,
users::User,
PlumeRocket, Result,
};
use plume_common::activity_pub::inbox::AsActor; use plume_common::activity_pub::inbox::AsActor;
use posts::Post;
use tags::Tag;
use users::User;
use whatlang::{self, Lang}; use whatlang::{self, Lang};
use {PlumeRocket, Result};
use super::Timeline;
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub enum QueryError { pub enum QueryError {
SyntaxError(usize, usize, String), SyntaxError(usize, usize, String),
@@ -65,7 +65,7 @@ impl<'a> Token<'a> {
} }
} }
fn get_error<T>(&self, token: Token<'_>) -> QueryResult<T> { fn get_error<T>(&self, token: Token) -> QueryResult<T> {
let (b, e) = self.get_pos(); let (b, e) = self.get_pos();
let message = format!( let message = format!(
"Syntax Error: Expected {}, got {}", "Syntax Error: Expected {}, got {}",
@@ -79,7 +79,7 @@ impl<'a> Token<'a> {
impl<'a> ToString for Token<'a> { impl<'a> ToString for Token<'a> {
fn to_string(&self) -> String { fn to_string(&self) -> String {
if let Token::Word(0, 0, v) = self { if let Token::Word(0, 0, v) = self {
return (*v).to_string(); return v.to_string();
} }
format!( format!(
"'{}'", "'{}'",
@@ -127,7 +127,7 @@ macro_rules! gen_tokenizer {
} }
} }
fn lex(stream: &str) -> Vec<Token<'_>> { fn lex(stream: &str) -> Vec<Token> {
stream stream
.chars() .chars()
.chain(" ".chars()) // force a last whitespace to empty scan's state .chain(" ".chars()) // force a last whitespace to empty scan's state
@@ -163,7 +163,7 @@ impl<'a> TQ<'a> {
rocket: &PlumeRocket, rocket: &PlumeRocket,
timeline: &Timeline, timeline: &Timeline,
post: &Post, post: &Post,
kind: Kind<'_>, kind: Kind,
) -> Result<bool> { ) -> Result<bool> {
match self { match self {
TQ::Or(inner) => inner.iter().try_fold(false, |s, e| { TQ::Or(inner) => inner.iter().try_fold(false, |s, e| {
@@ -181,7 +181,7 @@ impl<'a> TQ<'a> {
TQ::Or(inner) => inner.iter().flat_map(TQ::list_used_lists).collect(), TQ::Or(inner) => inner.iter().flat_map(TQ::list_used_lists).collect(),
TQ::And(inner) => inner.iter().flat_map(TQ::list_used_lists).collect(), TQ::And(inner) => inner.iter().flat_map(TQ::list_used_lists).collect(),
TQ::Arg(Arg::In(typ, List::List(name)), _) => vec![( TQ::Arg(Arg::In(typ, List::List(name)), _) => vec![(
(*name).to_string(), name.to_string(),
match typ { match typ {
WithList::Blog => ListType::Blog, WithList::Blog => ListType::Blog,
WithList::Author { .. } => ListType::User, WithList::Author { .. } => ListType::User,
@@ -208,7 +208,7 @@ impl<'a> Arg<'a> {
rocket: &PlumeRocket, rocket: &PlumeRocket,
timeline: &Timeline, timeline: &Timeline,
post: &Post, post: &Post,
kind: Kind<'_>, kind: Kind,
) -> Result<bool> { ) -> Result<bool> {
match self { match self {
Arg::In(t, l) => t.matches(rocket, timeline, post, l, kind), Arg::In(t, l) => t.matches(rocket, timeline, post, l, kind),
@@ -233,8 +233,8 @@ impl WithList {
rocket: &PlumeRocket, rocket: &PlumeRocket,
timeline: &Timeline, timeline: &Timeline,
post: &Post, post: &Post,
list: &List<'_>, list: &List,
kind: Kind<'_>, kind: Kind,
) -> Result<bool> { ) -> Result<bool> {
match list { match list {
List::List(name) => { List::List(name) => {
@@ -290,8 +290,7 @@ impl WithList {
(_, _) => Err(QueryError::RuntimeError(format!( (_, _) => Err(QueryError::RuntimeError(format!(
"The list '{}' is of the wrong type for this usage", "The list '{}' is of the wrong type for this usage",
name name
)) )))?,
.into()),
} }
} }
List::Array(list) => match self { List::Array(list) => match self {
@@ -374,7 +373,7 @@ impl Bool {
rocket: &PlumeRocket, rocket: &PlumeRocket,
timeline: &Timeline, timeline: &Timeline,
post: &Post, post: &Post,
kind: Kind<'_>, kind: Kind,
) -> Result<bool> { ) -> Result<bool> {
match self { match self {
Bool::Followed { boosts, likes } => { Bool::Followed { boosts, likes } => {
@@ -406,8 +405,8 @@ impl Bool {
} }
} }
Bool::HasCover => Ok(post.cover_id.is_some()), Bool::HasCover => Ok(post.cover_id.is_some()),
Bool::Local => Ok(post.get_blog(&rocket.conn)?.is_local() && kind == Kind::Original), Bool::Local => Ok(post.get_blog(&rocket.conn)?.is_local()),
Bool::All => Ok(kind == Kind::Original), Bool::All => Ok(true),
} }
} }
} }
@@ -645,7 +644,7 @@ impl<'a> TimelineQuery<'a> {
rocket: &PlumeRocket, rocket: &PlumeRocket,
timeline: &Timeline, timeline: &Timeline,
post: &Post, post: &Post,
kind: Kind<'_>, kind: Kind,
) -> Result<bool> { ) -> Result<bool> {
self.0.matches(rocket, timeline, post, kind) self.0.matches(rocket, timeline, post, kind)
} }
@@ -812,17 +811,9 @@ mod tests {
); );
let expect_keyword = TimelineQuery::parse(r#"not_a_field contains something"#).unwrap_err(); let expect_keyword = TimelineQuery::parse(r#"not_a_field contains something"#).unwrap_err();
assert_eq!( assert_eq!(expect_keyword, QueryError::SyntaxError(0, 11, "Syntax Error: Expected one of 'blog', \
expect_keyword,
QueryError::SyntaxError(
0,
11,
"Syntax Error: Expected one of 'blog', \
'author', 'license', 'tags', 'lang', 'title', 'subtitle', 'content', 'followed', 'has_cover', \ 'author', 'license', 'tags', 'lang', 'title', 'subtitle', 'content', 'followed', 'has_cover', \
'local' or 'all', got 'not_a_field'" 'local' or 'all', got 'not_a_field'".to_owned()));
.to_owned()
)
);
let expect_bracket_or_comma = TimelineQuery::parse(r#"lang in [en ["#).unwrap_err(); let expect_bracket_or_comma = TimelineQuery::parse(r#"lang in [en ["#).unwrap_err();
assert_eq!( assert_eq!(
+71 -53
View File
@@ -1,9 +1,3 @@
use crate::{
ap_url, blocklisted_emails::BlocklistedEmail, blogs::Blog, db_conn::DbConn, follows::Follow,
instance::*, medias::Media, notifications::Notification, post_authors::PostAuthor, posts::Post,
safe_string::SafeString, schema::users, search::Searcher, timeline::Timeline, Connection,
Error, PlumeRocket, Result, ITEMS_PER_PAGE,
};
use activitypub::{ use activitypub::{
activity::Delete, activity::Delete,
actor::Person, actor::Person,
@@ -20,15 +14,13 @@ use openssl::{
rsa::Rsa, rsa::Rsa,
sign, sign,
}; };
use plume_common::{ use plume_common::activity_pub::{
activity_pub::{ ap_accept_header,
ap_accept_header, inbox::{AsActor, AsObject, FromId},
inbox::{AsActor, AsObject, FromId}, sign::{gen_keypair, Signer},
sign::{gen_keypair, Signer}, ActivityStream, ApSignature, Id, IntoId, PublicKey, PUBLIC_VISIBILITY,
ActivityStream, ApSignature, Id, IntoId, PublicKey, PUBLIC_VISIBILITY,
},
utils,
}; };
use plume_common::utils;
use reqwest::{ use reqwest::{
header::{HeaderValue, ACCEPT}, header::{HeaderValue, ACCEPT},
ClientBuilder, ClientBuilder,
@@ -45,6 +37,23 @@ use std::{
use url::Url; use url::Url;
use webfinger::*; use webfinger::*;
use blogs::Blog;
use db_conn::DbConn;
use follows::Follow;
use instance::*;
use medias::Media;
use notifications::Notification;
use post_authors::PostAuthor;
use posts::Post;
use safe_string::SafeString;
use schema::users;
use search::Searcher;
use timeline::Timeline;
use {
ap_url, blocklisted_emails::BlocklistedEmail, Connection, Error, PlumeRocket, Result,
ITEMS_PER_PAGE,
};
pub type CustomPerson = CustomObject<ApSignature, Person>; pub type CustomPerson = CustomObject<ApSignature, Person>;
pub enum Role { pub enum Role {
@@ -54,7 +63,6 @@ pub enum Role {
} }
#[derive(Queryable, Identifiable, Clone, Debug, AsChangeset)] #[derive(Queryable, Identifiable, Clone, Debug, AsChangeset)]
#[changeset_options(treat_none_as_null = "true")]
pub struct User { pub struct User {
pub id: i32, pub id: i32,
pub username: String, pub username: String,
@@ -131,7 +139,7 @@ impl User {
} }
pub fn delete(&self, conn: &Connection, searcher: &Searcher) -> Result<()> { pub fn delete(&self, conn: &Connection, searcher: &Searcher) -> Result<()> {
use crate::schema::post_authors; use schema::post_authors;
for blog in Blog::find_for_author(conn, self)? for blog in Blog::find_for_author(conn, self)?
.iter() .iter()
@@ -203,6 +211,13 @@ impl User {
} }
} }
pub fn find_first_local(conn: &Connection) -> Result<User> {
users::table
.filter(users::instance_id.eq(Instance::get_local()?.id))
.first(&*conn)
.map_err(|_| Error::NotFound)
}
fn fetch_from_webfinger(c: &PlumeRocket, acct: &str) -> Result<User> { fn fetch_from_webfinger(c: &PlumeRocket, acct: &str) -> Result<User> {
let link = resolve(acct.to_owned(), true)? let link = resolve(acct.to_owned(), true)?
.links .links
@@ -221,21 +236,28 @@ impl User {
.ok_or(Error::Webfinger) .ok_or(Error::Webfinger)
} }
fn fetch(url: &str) -> Result<CustomPerson> { fn fetch(url: &str, lu: User) -> Result<CustomPerson> {
let mut headers = plume_common::activity_pub::request::headers();
headers.insert(
ACCEPT,
HeaderValue::from_str(
&ap_accept_header()
.into_iter()
.collect::<Vec<_>>()
.join(", "),
)?,
);
let mut res = ClientBuilder::new() let mut res = ClientBuilder::new()
.connect_timeout(Some(std::time::Duration::from_secs(5))) .connect_timeout(Some(std::time::Duration::from_secs(5)))
.build()? .build()?
.get(url) .get(url)
.headers(headers.clone())
.header( .header(
ACCEPT, "Signature",
HeaderValue::from_str( plume_common::activity_pub::request::signature(&lu, &headers).expect(""),
&ap_accept_header()
.into_iter()
.collect::<Vec<_>>()
.join(", "),
)?,
) )
.send()?; .send()?;
let text = &res.text()?; let text = &res.text()?;
// without this workaround, publicKey is not correctly deserialized // without this workaround, publicKey is not correctly deserialized
let ap_sign = serde_json::from_str::<ApSignature>(text)?; let ap_sign = serde_json::from_str::<ApSignature>(text)?;
@@ -245,11 +267,12 @@ impl User {
} }
pub fn fetch_from_url(c: &PlumeRocket, url: &str) -> Result<User> { pub fn fetch_from_url(c: &PlumeRocket, url: &str) -> Result<User> {
User::fetch(url).and_then(|json| User::from_activity(c, json)) User::fetch(url, User::find_first_local(&*c.conn)?)
.and_then(|json| User::from_activity(c, json))
} }
pub fn refetch(&self, conn: &Connection) -> Result<()> { pub fn refetch(&self, conn: &Connection) -> Result<()> {
User::fetch(&self.ap_url.clone()).and_then(|json| { User::fetch(&self.ap_url.clone(), User::find_first_local(conn)?).and_then(|json| {
let avatar = Media::save_remote( let avatar = Media::save_remote(
conn, conn,
json.object json.object
@@ -456,8 +479,8 @@ impl User {
.collect::<Vec<String>>()) .collect::<Vec<String>>())
} }
fn get_activities_count(&self, conn: &Connection) -> i64 { fn get_activities_count(&self, conn: &Connection) -> i64 {
use crate::schema::post_authors; use schema::post_authors;
use crate::schema::posts; use schema::posts;
let posts_by_self = PostAuthor::belonging_to(self).select(post_authors::post_id); let posts_by_self = PostAuthor::belonging_to(self).select(post_authors::post_id);
posts::table posts::table
.filter(posts::published.eq(true)) .filter(posts::published.eq(true))
@@ -471,8 +494,8 @@ impl User {
conn: &Connection, conn: &Connection,
(min, max): (i32, i32), (min, max): (i32, i32),
) -> Result<Vec<serde_json::Value>> { ) -> Result<Vec<serde_json::Value>> {
use crate::schema::post_authors; use schema::post_authors;
use crate::schema::posts; use schema::posts;
let posts_by_self = PostAuthor::belonging_to(self).select(post_authors::post_id); let posts_by_self = PostAuthor::belonging_to(self).select(post_authors::post_id);
let posts = posts::table let posts = posts::table
.filter(posts::published.eq(true)) .filter(posts::published.eq(true))
@@ -492,7 +515,7 @@ impl User {
} }
pub fn get_followers(&self, conn: &Connection) -> Result<Vec<User>> { pub fn get_followers(&self, conn: &Connection) -> Result<Vec<User>> {
use crate::schema::follows; use schema::follows;
let follows = Follow::belonging_to(self).select(follows::follower_id); let follows = Follow::belonging_to(self).select(follows::follower_id);
users::table users::table
.filter(users::id.eq_any(follows)) .filter(users::id.eq_any(follows))
@@ -501,7 +524,7 @@ impl User {
} }
pub fn count_followers(&self, conn: &Connection) -> Result<i64> { pub fn count_followers(&self, conn: &Connection) -> Result<i64> {
use crate::schema::follows; use schema::follows;
let follows = Follow::belonging_to(self).select(follows::follower_id); let follows = Follow::belonging_to(self).select(follows::follower_id);
users::table users::table
.filter(users::id.eq_any(follows)) .filter(users::id.eq_any(follows))
@@ -515,7 +538,7 @@ impl User {
conn: &Connection, conn: &Connection,
(min, max): (i32, i32), (min, max): (i32, i32),
) -> Result<Vec<User>> { ) -> Result<Vec<User>> {
use crate::schema::follows; use schema::follows;
let follows = Follow::belonging_to(self).select(follows::follower_id); let follows = Follow::belonging_to(self).select(follows::follower_id);
users::table users::table
.filter(users::id.eq_any(follows)) .filter(users::id.eq_any(follows))
@@ -526,7 +549,7 @@ impl User {
} }
pub fn get_followed(&self, conn: &Connection) -> Result<Vec<User>> { pub fn get_followed(&self, conn: &Connection) -> Result<Vec<User>> {
use crate::schema::follows::dsl::*; use schema::follows::dsl::*;
let f = follows.filter(follower_id.eq(self.id)).select(following_id); let f = follows.filter(follower_id.eq(self.id)).select(following_id);
users::table users::table
.filter(users::id.eq_any(f)) .filter(users::id.eq_any(f))
@@ -535,7 +558,7 @@ impl User {
} }
pub fn count_followed(&self, conn: &Connection) -> Result<i64> { pub fn count_followed(&self, conn: &Connection) -> Result<i64> {
use crate::schema::follows; use schema::follows;
follows::table follows::table
.filter(follows::follower_id.eq(self.id)) .filter(follows::follower_id.eq(self.id))
.count() .count()
@@ -548,7 +571,7 @@ impl User {
conn: &Connection, conn: &Connection,
(min, max): (i32, i32), (min, max): (i32, i32),
) -> Result<Vec<User>> { ) -> Result<Vec<User>> {
use crate::schema::follows; use schema::follows;
let follows = follows::table let follows = follows::table
.filter(follows::follower_id.eq(self.id)) .filter(follows::follower_id.eq(self.id))
.select(follows::following_id) .select(follows::following_id)
@@ -561,7 +584,7 @@ impl User {
} }
pub fn is_followed_by(&self, conn: &Connection, other_id: i32) -> Result<bool> { pub fn is_followed_by(&self, conn: &Connection, other_id: i32) -> Result<bool> {
use crate::schema::follows; use schema::follows;
follows::table follows::table
.filter(follows::follower_id.eq(other_id)) .filter(follows::follower_id.eq(other_id))
.filter(follows::following_id.eq(self.id)) .filter(follows::following_id.eq(self.id))
@@ -572,7 +595,7 @@ impl User {
} }
pub fn is_following(&self, conn: &Connection, other_id: i32) -> Result<bool> { pub fn is_following(&self, conn: &Connection, other_id: i32) -> Result<bool> {
use crate::schema::follows; use schema::follows;
follows::table follows::table
.filter(follows::follower_id.eq(self.id)) .filter(follows::follower_id.eq(self.id))
.filter(follows::following_id.eq(other_id)) .filter(follows::following_id.eq(other_id))
@@ -583,7 +606,7 @@ impl User {
} }
pub fn has_liked(&self, conn: &Connection, post: &Post) -> Result<bool> { pub fn has_liked(&self, conn: &Connection, post: &Post) -> Result<bool> {
use crate::schema::likes; use schema::likes;
likes::table likes::table
.filter(likes::post_id.eq(post.id)) .filter(likes::post_id.eq(post.id))
.filter(likes::user_id.eq(self.id)) .filter(likes::user_id.eq(self.id))
@@ -594,7 +617,7 @@ impl User {
} }
pub fn has_reshared(&self, conn: &Connection, post: &Post) -> Result<bool> { pub fn has_reshared(&self, conn: &Connection, post: &Post) -> Result<bool> {
use crate::schema::reshares; use schema::reshares;
reshares::table reshares::table
.filter(reshares::post_id.eq(post.id)) .filter(reshares::post_id.eq(post.id))
.filter(reshares::user_id.eq(self.id)) .filter(reshares::user_id.eq(self.id))
@@ -605,7 +628,7 @@ impl User {
} }
pub fn is_author_in(&self, conn: &Connection, blog: &Blog) -> Result<bool> { pub fn is_author_in(&self, conn: &Connection, blog: &Blog) -> Result<bool> {
use crate::schema::blog_authors; use schema::blog_authors;
blog_authors::table blog_authors::table
.filter(blog_authors::author_id.eq(self.id)) .filter(blog_authors::author_id.eq(self.id))
.filter(blog_authors::blog_id.eq(blog.id)) .filter(blog_authors::blog_id.eq(blog.id))
@@ -760,7 +783,7 @@ impl User {
mime_type: None, mime_type: None,
href: None, href: None,
template: Some(format!( template: Some(format!(
"https://{}/remote_interact?target={{uri}}", "https://{}/remote_interact?{{uri}}",
self.get_instance(conn)?.public_domain self.get_instance(conn)?.public_domain
)), )),
}, },
@@ -805,7 +828,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for User {
impl IntoId for User { impl IntoId for User {
fn into_id(self) -> Id { fn into_id(self) -> Id {
Id::new(self.ap_url) Id::new(self.ap_url.clone())
} }
} }
@@ -1025,14 +1048,11 @@ impl NewUser {
#[cfg(test)] #[cfg(test)]
pub(crate) mod tests { pub(crate) mod tests {
use super::*; use super::*;
use crate::{
config::CONFIG,
instance::{tests as instance_tests, Instance},
search::tests::get_searcher,
tests::{db, rockets},
Connection as Conn,
};
use diesel::Connection; use diesel::Connection;
use instance::{tests as instance_tests, Instance};
use search::tests::get_searcher;
use tests::{db, rockets};
use Connection as Conn;
pub(crate) fn fill_database(conn: &Conn) -> Vec<User> { pub(crate) fn fill_database(conn: &Conn) -> Vec<User> {
instance_tests::fill_database(conn); instance_tests::fill_database(conn);
@@ -1123,9 +1143,7 @@ pub(crate) mod tests {
let inserted = fill_database(conn); let inserted = fill_database(conn);
assert!(User::get(conn, inserted[0].id).is_ok()); assert!(User::get(conn, inserted[0].id).is_ok());
inserted[0] inserted[0].delete(conn, &get_searcher()).unwrap();
.delete(conn, &get_searcher(&CONFIG.search_tokenizers))
.unwrap();
assert!(User::get(conn, inserted[0].id).is_err()); assert!(User::get(conn, inserted[0].id).is_err());
Ok(()) Ok(())
}); });
+4
View File
@@ -1,3 +1,7 @@
extern crate diesel;
extern crate plume_common;
extern crate plume_models;
use diesel::Connection; use diesel::Connection;
use plume_common::utils::random_hex; use plume_common::utils::random_hex;
use plume_models::migrations::IMPORTED_MIGRATIONS; use plume_models::migrations::IMPORTED_MIGRATIONS;
+1 -1
View File
@@ -10,7 +10,7 @@ msgstr ""
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Crowdin-Project: plume\n" "X-Crowdin-Project: plume\n"
"X-Crowdin-Language: fr\n" "X-Crowdin-Language: fr\n"
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n" "X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
+1 -1
View File
@@ -10,7 +10,7 @@ msgstr ""
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Crowdin-Project: plume\n" "X-Crowdin-Project: plume\n"
"X-Crowdin-Language: fr\n" "X-Crowdin-Language: fr\n"
"X-Crowdin-File: /master/po/plume/plume.pot\n" "X-Crowdin-File: /master/po/plume/plume.pot\n"
+1 -1
View File
@@ -1 +1 @@
nightly-2020-01-15 nightly-2019-03-23
+2 -2
View File
@@ -24,9 +24,9 @@ if [ $ARCH == "aarch64" -o $ARCH == "armv71" ] ; then
apt-get install -y --no-install-recommends build-essential subversion ninja-build cmake apt-get install -y --no-install-recommends build-essential subversion ninja-build cmake
mkdir -p /scratch/src mkdir -p /scratch/src
cd /scratch/src cd /scratch/src
svn co http://llvm.org/svn/llvm-project/llvm/tags/RELEASE_900/final/ llvm svn co http://llvm.org/svn/llvm-project/llvm/tags/RELEASE_800/final/ llvm
cd /scratch/src/llvm/tools cd /scratch/src/llvm/tools
svn co http://llvm.org/svn/llvm-project/lld/tags/RELEASE_900/final/ lld svn co http://llvm.org/svn/llvm-project/lld/tags/RELEASE_800/final/ lld
mkdir -p /scratch/build/arm mkdir -p /scratch/build/arm
cd /scratch/build/arm cd /scratch/build/arm
if [ "$ARCH" == "aarch64" ] ; then if [ "$ARCH" == "aarch64" ] ; then
+3 -4
View File
@@ -8,7 +8,7 @@ description: |
* Media management: you can upload pictures to illustrate your articles, but also audio files if you host a podcast, and manage them all from Plume. * Media management: you can upload pictures to illustrate your articles, but also audio files if you host a podcast, and manage them all from Plume.
* Federation: Plume is part of a network of interconnected websites called the Fediverse. Each of these websites (often called instances) have their own rules and thematics, but they can all communicate with each other. * Federation: Plume is part of a network of interconnected websites called the Fediverse. Each of these websites (often called instances) have their own rules and thematics, but they can all communicate with each other.
* Collaborative writing: invite other people to your blogs, and write articles together. * Collaborative writing: invite other people to your blogs, and write articles together.
grade: stable grade: devel # must be 'stable' to release into candidate/stable channels
confinement: strict confinement: strict
apps: apps:
@@ -25,13 +25,12 @@ parts:
plume: plume:
plugin: rust plugin: rust
source: . source: .
rust-revision: nightly-2020-01-15 rust-revision: nightly-2019-03-23
build-packages: build-packages:
- libssl-dev - libssl-dev
- pkg-config - pkg-config
- libsqlite3-dev - libsqlite3-dev
- gettext - gettext
- libclang-8-dev
- on arm64,armhf,ppc64el,s390x: - on arm64,armhf,ppc64el,s390x:
- lld-8 - lld-8
override-build: | override-build: |
@@ -43,7 +42,7 @@ parts:
# Only Tier 1 Rust platforms get rust-lld # Only Tier 1 Rust platforms get rust-lld
# On the others (arm64, armhf, powerpc64, s390x) fall back to using # On the others (arm64, armhf, powerpc64, s390x) fall back to using
# the system LLD we've installed earlier. # the system LLD we've installed earlier.
case ${SNAPCRAFT_ARCH_TRIPLET} in \ case ${SNAPCRAFT_ARCH_TRIPLE} in \
aarch64-linux-gnu|arm-linux-gnueabihf|powerpc64-linux-gnu|s390x-linux-gnu) \ aarch64-linux-gnu|arm-linux-gnueabihf|powerpc64-linux-gnu|s390x-linux-gnu) \
RUSTFLAGS="-C linker=lld-8" cargo web deploy -p plume-front --release \ RUSTFLAGS="-C linker=lld-8" cargo web deploy -p plume-front --release \
;; \ ;; \
+1 -1
View File
@@ -27,7 +27,7 @@ impl From<std::option::NoneError> for ApiError {
} }
impl<'r> Responder<'r> for ApiError { impl<'r> Responder<'r> for ApiError {
fn respond_to(self, req: &Request<'_>) -> response::Result<'r> { fn respond_to(self, req: &Request) -> response::Result<'r> {
match self.0 { match self.0 {
Error::NotFound => Json(json!({ Error::NotFound => Json(json!({
"error": "Not found" "error": "Not found"
+3 -3
View File
@@ -14,7 +14,7 @@ use std::io::Read;
pub fn handle_incoming( pub fn handle_incoming(
rockets: PlumeRocket, rockets: PlumeRocket,
data: SignedJson<serde_json::Value>, data: SignedJson<serde_json::Value>,
headers: Headers<'_>, headers: Headers,
) -> Result<String, status::BadRequest<&'static str>> { ) -> Result<String, status::BadRequest<&'static str>> {
let conn = &*rockets.conn; let conn = &*rockets.conn;
let act = data.1.into_inner(); let act = data.1.into_inner();
@@ -74,7 +74,7 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for SignedJson<T> {
type Borrowed = str; type Borrowed = str;
fn transform( fn transform(
r: &Request<'_>, r: &Request,
d: Data, d: Data,
) -> Transform<rocket::data::Outcome<Self::Owned, Self::Error>> { ) -> Transform<rocket::data::Outcome<Self::Owned, Self::Error>> {
let size_limit = r.limits().get("json").unwrap_or(JSON_LIMIT); let size_limit = r.limits().get("json").unwrap_or(JSON_LIMIT);
@@ -86,7 +86,7 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for SignedJson<T> {
} }
fn from_data( fn from_data(
_: &Request<'_>, _: &Request,
o: Transformed<'a, Self>, o: Transformed<'a, Self>,
) -> rocket::data::Outcome<Self, Self::Error> { ) -> rocket::data::Outcome<Self, Self::Error> {
let string = o.borrowed()?; let string = o.borrowed()?;
+45 -12
View File
@@ -1,14 +1,43 @@
#![allow(clippy::too_many_arguments)] #![allow(clippy::too_many_arguments)]
#![feature(decl_macro, proc_macro_hygiene, try_trait)] #![feature(decl_macro, proc_macro_hygiene, try_trait)]
extern crate activitypub;
extern crate askama_escape;
extern crate atom_syndication;
extern crate chrono;
extern crate clap;
extern crate colored;
extern crate ctrlc;
extern crate diesel;
extern crate dotenv;
#[macro_use] #[macro_use]
extern crate gettext_macros; extern crate gettext_macros;
extern crate gettext_utils;
extern crate guid_create;
extern crate heck;
extern crate lettre;
extern crate lettre_email;
extern crate multipart;
extern crate num_cpus;
extern crate plume_api;
extern crate plume_common;
extern crate plume_models;
#[macro_use] #[macro_use]
extern crate rocket; extern crate rocket;
extern crate rocket_contrib;
extern crate rocket_csrf;
extern crate rocket_i18n;
#[macro_use]
extern crate runtime_fmt;
extern crate scheduled_thread_pool;
extern crate serde;
#[macro_use] #[macro_use]
extern crate serde_json; extern crate serde_json;
extern crate serde_qs;
extern crate validator;
#[macro_use] #[macro_use]
extern crate validator_derive; extern crate validator_derive;
extern crate webfinger;
use clap::App; use clap::App;
use diesel::r2d2::ConnectionManager; use diesel::r2d2::ConnectionManager;
@@ -26,8 +55,7 @@ use std::sync::{Arc, Mutex};
use std::time::Duration; use std::time::Duration;
init_i18n!( init_i18n!(
"plume", ar, bg, ca, cs, de, en, eo, es, fa, fr, gl, hi, hr, it, ja, nb, pl, pt, ro, ru, sr, "plume", ar, bg, ca, cs, de, en, eo, es, fr, gl, hi, hr, it, ja, nb, pl, pt, ro, ru, sr, sk, sv
sk, sv
); );
mod api; mod api;
@@ -54,13 +82,10 @@ fn init_pool() -> Option<DbPool> {
} }
let manager = ConnectionManager::<Connection>::new(CONFIG.database_url.as_str()); let manager = ConnectionManager::<Connection>::new(CONFIG.database_url.as_str());
let mut builder = DbPool::builder() let pool = DbPool::builder()
.connection_customizer(Box::new(PragmaForeignKey)) .connection_customizer(Box::new(PragmaForeignKey))
.min_idle(CONFIG.db_min_idle); .build(manager)
if let Some(max_size) = CONFIG.db_max_size { .ok()?;
builder = builder.max_size(max_size);
};
let pool = builder.build(manager).ok()?;
Instance::cache_local(&pool.get().unwrap()); Instance::cache_local(&pool.get().unwrap());
Some(pool) Some(pool)
} }
@@ -99,7 +124,7 @@ Then try to restart Plume.
let workpool = ScheduledThreadPool::with_name("worker {}", num_cpus::get()); let workpool = ScheduledThreadPool::with_name("worker {}", num_cpus::get());
// we want a fast exit here, so // we want a fast exit here, so
#[allow(clippy::match_wild_err_arm)] #[allow(clippy::match_wild_err_arm)]
let searcher = match UnmanagedSearcher::open(&CONFIG.search_index, &CONFIG.search_tokenizers) { let searcher = match UnmanagedSearcher::open(&CONFIG.search_index) {
Err(Error::Search(e)) => match e { Err(Error::Search(e)) => match e {
SearcherError::WriteLockAcquisitionError => panic!( SearcherError::WriteLockAcquisitionError => panic!(
r#" r#"
@@ -282,13 +307,21 @@ Then try to restart Plume
rocket::http::Method::Post, rocket::http::Method::Post,
) )
.add_exceptions(vec![ .add_exceptions(vec![
("/inbox".to_owned(), "/inbox".to_owned(), None), (
"/inbox".to_owned(),
"/inbox".to_owned(),
rocket::http::Method::Post,
),
( (
"/@/<name>/inbox".to_owned(), "/@/<name>/inbox".to_owned(),
"/@/<name>/inbox".to_owned(), "/@/<name>/inbox".to_owned(),
None, rocket::http::Method::Post,
),
(
"/api/<path..>".to_owned(),
"/api/<path..>".to_owned(),
rocket::http::Method::Post,
), ),
("/api/<path..>".to_owned(), "/api/<path..>".to_owned(), None),
]) ])
.finalize() .finalize()
.expect("main: csrf fairing creation error"), .expect("main: csrf fairing creation error"),
+18 -10
View File
@@ -1,4 +1,5 @@
use activitypub::collection::{OrderedCollection, OrderedCollectionPage}; use activitypub::collection::{OrderedCollection, OrderedCollectionPage};
use atom_syndication::{Entry, FeedBuilder};
use diesel::SaveChangesDsl; use diesel::SaveChangesDsl;
use rocket::{ use rocket::{
http::ContentType, http::ContentType,
@@ -9,14 +10,14 @@ use rocket_i18n::I18n;
use std::{borrow::Cow, collections::HashMap}; use std::{borrow::Cow, collections::HashMap};
use validator::{Validate, ValidationError, ValidationErrors}; use validator::{Validate, ValidationError, ValidationErrors};
use crate::routes::{errors::ErrorPage, Page, RespondOrRedirect};
use crate::template_utils::{IntoContext, Ructe};
use plume_common::activity_pub::{ActivityStream, ApRequest}; use plume_common::activity_pub::{ActivityStream, ApRequest};
use plume_common::utils; use plume_common::utils;
use plume_models::{ use plume_models::{
blog_authors::*, blogs::*, instance::Instance, medias::*, posts::Post, safe_string::SafeString, blog_authors::*, blogs::*, instance::Instance, medias::*, posts::Post, safe_string::SafeString,
users::User, Connection, PlumeRocket, users::User, Connection, PlumeRocket,
}; };
use routes::{errors::ErrorPage, Page, RespondOrRedirect};
use template_utils::{IntoContext, Ructe};
#[get("/~/<name>?<page>", rank = 2)] #[get("/~/<name>?<page>", rank = 2)]
pub fn details(name: String, page: Option<Page>, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> { pub fn details(name: String, page: Option<Page>, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> {
@@ -136,7 +137,7 @@ pub fn create(form: LenientForm<NewBlogForm>, rockets: PlumeRocket) -> RespondOr
.expect("blog::create: author error"); .expect("blog::create: author error");
Flash::success( Flash::success(
Redirect::to(uri!(details: name = slug, page = _)), Redirect::to(uri!(details: name = slug.clone(), page = _)),
&i18n!(intl, "Your blog was successfully created!"), &i18n!(intl, "Your blog was successfully created!"),
) )
.into() .into()
@@ -360,13 +361,20 @@ pub fn outbox_page(
pub fn atom_feed(name: String, rockets: PlumeRocket) -> Option<Content<String>> { pub fn atom_feed(name: String, rockets: PlumeRocket) -> Option<Content<String>> {
let blog = Blog::find_by_fqn(&rockets, &name).ok()?; let blog = Blog::find_by_fqn(&rockets, &name).ok()?;
let conn = &*rockets.conn; let conn = &*rockets.conn;
let entries = Post::get_recents_for_blog(&*conn, &blog, 15).ok()?; let feed = FeedBuilder::default()
let uri = Instance::get_local() .title(blog.title.clone())
.ok()? .id(Instance::get_local()
.compute_box("~", &name, "atom.xml"); .ok()?
let title = &blog.title; .compute_box("~", &name, "atom.xml"))
let default_updated = &blog.creation_date; .entries(
let feed = super::build_atom_feed(entries, &uri, title, default_updated, conn); Post::get_recents_for_blog(&*conn, &blog, 15)
.ok()?
.into_iter()
.map(|p| super::post_to_atom(p, &*conn))
.collect::<Vec<Entry>>(),
)
.build()
.ok()?;
Some(Content( Some(Content(
ContentType::new("application", "atom+xml"), ContentType::new("application", "atom+xml"),
feed.to_string(), feed.to_string(),
+3 -3
View File
@@ -1,15 +1,13 @@
use crate::template_utils::Ructe;
use activitypub::object::Note; use activitypub::object::Note;
use rocket::{ use rocket::{
request::LenientForm, request::LenientForm,
response::{Flash, Redirect}, response::{Flash, Redirect},
}; };
use template_utils::Ructe;
use validator::Validate; use validator::Validate;
use std::time::Duration; use std::time::Duration;
use crate::routes::errors::ErrorPage;
use crate::template_utils::IntoContext;
use plume_common::{ use plume_common::{
activity_pub::{broadcast, ActivityStream, ApRequest}, activity_pub::{broadcast, ActivityStream, ApRequest},
utils, utils,
@@ -18,6 +16,8 @@ use plume_models::{
blogs::Blog, comments::*, inbox::inbox, instance::Instance, medias::Media, mentions::Mention, blogs::Blog, comments::*, inbox::inbox, instance::Instance, medias::Media, mentions::Mention,
posts::Post, safe_string::SafeString, tags::Tag, users::User, Error, PlumeRocket, posts::Post, safe_string::SafeString, tags::Tag, users::User, Error, PlumeRocket,
}; };
use routes::errors::ErrorPage;
use template_utils::IntoContext;
#[derive(Default, FromForm, Debug, Validate)] #[derive(Default, FromForm, Debug, Validate)]
pub struct NewCommentForm { pub struct NewCommentForm {
+5 -5
View File
@@ -1,9 +1,9 @@
use crate::template_utils::{IntoContext, Ructe};
use plume_models::{Error, PlumeRocket}; use plume_models::{Error, PlumeRocket};
use rocket::{ use rocket::{
response::{self, Responder}, response::{self, Responder},
Request, Request,
}; };
use template_utils::{IntoContext, Ructe};
#[derive(Debug)] #[derive(Debug)]
pub struct ErrorPage(Error); pub struct ErrorPage(Error);
@@ -15,7 +15,7 @@ impl From<Error> for ErrorPage {
} }
impl<'r> Responder<'r> for ErrorPage { impl<'r> Responder<'r> for ErrorPage {
fn respond_to(self, req: &Request<'_>) -> response::Result<'r> { fn respond_to(self, req: &Request) -> response::Result<'r> {
let rockets = req.guard::<PlumeRocket>().unwrap(); let rockets = req.guard::<PlumeRocket>().unwrap();
match self.0 { match self.0 {
@@ -29,19 +29,19 @@ impl<'r> Responder<'r> for ErrorPage {
} }
#[catch(404)] #[catch(404)]
pub fn not_found(req: &Request<'_>) -> Ructe { pub fn not_found(req: &Request) -> Ructe {
let rockets = req.guard::<PlumeRocket>().unwrap(); let rockets = req.guard::<PlumeRocket>().unwrap();
render!(errors::not_found(&rockets.to_context())) render!(errors::not_found(&rockets.to_context()))
} }
#[catch(422)] #[catch(422)]
pub fn unprocessable_entity(req: &Request<'_>) -> Ructe { pub fn unprocessable_entity(req: &Request) -> Ructe {
let rockets = req.guard::<PlumeRocket>().unwrap(); let rockets = req.guard::<PlumeRocket>().unwrap();
render!(errors::unprocessable_entity(&rockets.to_context())) render!(errors::unprocessable_entity(&rockets.to_context()))
} }
#[catch(500)] #[catch(500)]
pub fn server_error(req: &Request<'_>) -> Ructe { pub fn server_error(req: &Request) -> Ructe {
let rockets = req.guard::<PlumeRocket>().unwrap(); let rockets = req.guard::<PlumeRocket>().unwrap();
render!(errors::server_error(&rockets.to_context())) render!(errors::server_error(&rockets.to_context()))
} }
+7 -6
View File
@@ -9,9 +9,7 @@ use serde_json;
use std::str::FromStr; use std::str::FromStr;
use validator::{Validate, ValidationErrors}; use validator::{Validate, ValidationErrors};
use crate::inbox; use inbox;
use crate::routes::{errors::ErrorPage, rocket_uri_macro_static_files, Page, RespondOrRedirect};
use crate::template_utils::{IntoContext, Ructe};
use plume_common::activity_pub::{broadcast, inbox::FromId}; use plume_common::activity_pub::{broadcast, inbox::FromId};
use plume_models::{ use plume_models::{
admin::*, admin::*,
@@ -27,6 +25,8 @@ use plume_models::{
users::{Role, User}, users::{Role, User},
Connection, Error, PlumeRocket, CONFIG, Connection, Error, PlumeRocket, CONFIG,
}; };
use routes::{errors::ErrorPage, rocket_uri_macro_static_files, Page, RespondOrRedirect};
use template_utils::{IntoContext, Ructe};
#[get("/")] #[get("/")]
pub fn index(rockets: PlumeRocket) -> Result<Ructe, ErrorPage> { pub fn index(rockets: PlumeRocket) -> Result<Ructe, ErrorPage> {
@@ -248,7 +248,7 @@ where
{ {
type Error = (); type Error = ();
fn from_form(items: &mut FormItems<'_>, _strict: bool) -> Result<Self, Self::Error> { fn from_form(items: &mut FormItems, _strict: bool) -> Result<Self, Self::Error> {
let (ids, act) = items.fold((vec![], None), |(mut ids, act), item| { let (ids, act) = items.fold((vec![], None), |(mut ids, act), item| {
let (name, val) = item.key_value_decoded(); let (name, val) = item.key_value_decoded();
@@ -379,7 +379,8 @@ fn ban(
.unwrap(); .unwrap();
let target = User::one_by_instance(&*conn)?; let target = User::one_by_instance(&*conn)?;
let delete_act = u.delete_activity(&*conn)?; let delete_act = u.delete_activity(&*conn)?;
worker.execute(move || broadcast(&u, delete_act, target)); let u_clone = u.clone();
worker.execute(move || broadcast(&u_clone, delete_act, target));
} }
Ok(()) Ok(())
@@ -389,7 +390,7 @@ fn ban(
pub fn shared_inbox( pub fn shared_inbox(
rockets: PlumeRocket, rockets: PlumeRocket,
data: inbox::SignedJson<serde_json::Value>, data: inbox::SignedJson<serde_json::Value>,
headers: Headers<'_>, headers: Headers,
) -> Result<String, status::BadRequest<&'static str>> { ) -> Result<String, status::BadRequest<&'static str>> {
inbox::handle_incoming(rockets, data, headers) inbox::handle_incoming(rockets, data, headers)
} }
+1 -1
View File
@@ -1,12 +1,12 @@
use rocket::response::{Flash, Redirect}; use rocket::response::{Flash, Redirect};
use rocket_i18n::I18n; use rocket_i18n::I18n;
use crate::routes::errors::ErrorPage;
use plume_common::activity_pub::broadcast; use plume_common::activity_pub::broadcast;
use plume_common::utils; use plume_common::utils;
use plume_models::{ use plume_models::{
blogs::Blog, inbox::inbox, likes, posts::Post, timeline::*, users::User, Error, PlumeRocket, blogs::Blog, inbox::inbox, likes, posts::Post, timeline::*, users::User, Error, PlumeRocket,
}; };
use routes::errors::ErrorPage;
#[post("/~/<blog>/<slug>/like")] #[post("/~/<blog>/<slug>/like")]
pub fn create( pub fn create(
+2 -2
View File
@@ -1,5 +1,3 @@
use crate::routes::{errors::ErrorPage, Page};
use crate::template_utils::{IntoContext, Ructe};
use guid_create::GUID; use guid_create::GUID;
use multipart::server::{ use multipart::server::{
save::{SaveResult, SavedData}, save::{SaveResult, SavedData},
@@ -12,7 +10,9 @@ use rocket::{
Data, Data,
}; };
use rocket_i18n::I18n; use rocket_i18n::I18n;
use routes::{errors::ErrorPage, Page};
use std::fs; use std::fs;
use template_utils::{IntoContext, Ructe};
#[get("/medias?<page>")] #[get("/medias?<page>")]
pub fn list(user: User, page: Option<Page>, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> { pub fn list(user: User, page: Option<Page>, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> {
Executable → Regular
+5 -46
View File
@@ -1,9 +1,5 @@
#![warn(clippy::too_many_arguments)] #![warn(clippy::too_many_arguments)]
use crate::template_utils::Ructe; use atom_syndication::{ContentBuilder, Entry, EntryBuilder, LinkBuilder, Person, PersonBuilder};
use atom_syndication::{
ContentBuilder, Entry, EntryBuilder, Feed, FeedBuilder, LinkBuilder, Person, PersonBuilder,
};
use chrono::naive::NaiveDateTime;
use plume_models::{posts::Post, Connection, CONFIG, ITEMS_PER_PAGE}; use plume_models::{posts::Post, Connection, CONFIG, ITEMS_PER_PAGE};
use rocket::{ use rocket::{
http::{ http::{
@@ -20,6 +16,7 @@ use std::{
hash::Hasher, hash::Hasher,
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
use template_utils::Ructe;
/// Special return type used for routes that "cannot fail", and instead /// Special return type used for routes that "cannot fail", and instead
/// `Redirect`, or `Flash<Redirect>`, when we cannot deliver a `Ructe` Response /// `Redirect`, or `Flash<Redirect>`, when we cannot deliver a `Ructe` Response
@@ -118,46 +115,13 @@ pub struct RemoteForm {
pub remote: String, pub remote: String,
} }
pub fn build_atom_feed( pub fn post_to_atom(post: Post, conn: &Connection) -> Entry {
entries: Vec<Post>,
uri: &str,
title: &str,
default_updated: &NaiveDateTime,
conn: &Connection,
) -> Feed {
let updated = if entries.is_empty() {
default_updated
} else {
&entries[0].creation_date
};
FeedBuilder::default()
.title(title)
.id(uri)
.updated(updated.format("%Y-%m-%dT%H:%M:%SZ").to_string())
.entries(
entries
.into_iter()
.map(|p| post_to_atom(p, conn))
.collect::<Vec<Entry>>(),
)
.links(vec![LinkBuilder::default()
.href(uri)
.rel("self")
.mime_type("application/atom+xml".to_string())
.build()
.expect("Atom feed: link error")])
.build()
.expect("user::atom_feed: Error building Atom feed")
}
fn post_to_atom(post: Post, conn: &Connection) -> Entry {
let formatted_creation_date = post.creation_date.format("%Y-%m-%dT%H:%M:%SZ").to_string();
EntryBuilder::default() EntryBuilder::default()
.title(format!("<![CDATA[{}]]>", post.title)) .title(format!("<![CDATA[{}]]>", post.title))
.content( .content(
ContentBuilder::default() ContentBuilder::default()
.value(format!("<![CDATA[{}]]>", *post.content.get())) .value(format!("<![CDATA[{}]]>", *post.content.get()))
.src(post.ap_url.clone())
.content_type("html".to_string()) .content_type("html".to_string())
.build() .build()
.expect("Atom feed: content error"), .expect("Atom feed: content error"),
@@ -175,11 +139,6 @@ fn post_to_atom(post: Post, conn: &Connection) -> Entry {
}) })
.collect::<Vec<Person>>(), .collect::<Vec<Person>>(),
) )
// Using RFC 4287 format, see https://tools.ietf.org/html/rfc4287#section-3.3 for dates
// eg: 2003-12-13T18:30:02Z (Z is here because there is no timezone support with the NaiveDateTime crate)
.published(formatted_creation_date.clone())
.updated(formatted_creation_date)
.id(post.ap_url.clone())
.links(vec![LinkBuilder::default() .links(vec![LinkBuilder::default()
.href(post.ap_url) .href(post.ap_url)
.build() .build()
@@ -215,7 +174,7 @@ pub struct CachedFile {
pub struct ThemeFile(NamedFile); pub struct ThemeFile(NamedFile);
impl<'r> Responder<'r> for ThemeFile { impl<'r> Responder<'r> for ThemeFile {
fn respond_to(self, r: &Request<'_>) -> response::Result<'r> { fn respond_to(self, r: &Request) -> response::Result<'r> {
let contents = std::fs::read(self.0.path()).map_err(|_| Status::InternalServerError)?; let contents = std::fs::read(self.0.path()).map_err(|_| Status::InternalServerError)?;
let mut hasher = DefaultHasher::new(); let mut hasher = DefaultHasher::new();
+2 -2
View File
@@ -1,10 +1,10 @@
use rocket::response::{Flash, Redirect}; use rocket::response::{Flash, Redirect};
use rocket_i18n::I18n; use rocket_i18n::I18n;
use crate::routes::{errors::ErrorPage, Page};
use crate::template_utils::{IntoContext, Ructe};
use plume_common::utils; use plume_common::utils;
use plume_models::{notifications::Notification, users::User, PlumeRocket}; use plume_models::{notifications::Notification, users::User, PlumeRocket};
use routes::{errors::ErrorPage, Page};
use template_utils::{IntoContext, Ructe};
#[get("/notifications?<page>")] #[get("/notifications?<page>")]
pub fn notifications( pub fn notifications(
+14 -12
View File
@@ -10,10 +10,6 @@ use std::{
}; };
use validator::{Validate, ValidationError, ValidationErrors}; use validator::{Validate, ValidationError, ValidationErrors};
use crate::routes::{
comments::NewCommentForm, errors::ErrorPage, ContentLen, RemoteForm, RespondOrRedirect,
};
use crate::template_utils::{IntoContext, Ructe};
use plume_common::activity_pub::{broadcast, ActivityStream, ApRequest}; use plume_common::activity_pub::{broadcast, ActivityStream, ApRequest};
use plume_common::utils; use plume_common::utils;
use plume_models::{ use plume_models::{
@@ -31,6 +27,10 @@ use plume_models::{
users::User, users::User,
Error, PlumeRocket, Error, PlumeRocket,
}; };
use routes::{
comments::NewCommentForm, errors::ErrorPage, ContentLen, RemoteForm, RespondOrRedirect,
};
use template_utils::{IntoContext, Ructe};
#[get("/~/<blog>/<slug>?<responding_to>", rank = 4)] #[get("/~/<blog>/<slug>?<responding_to>", rank = 4)]
pub fn details( pub fn details(
@@ -298,7 +298,7 @@ pub fn update(
post.license = form.license.clone(); post.license = form.license.clone();
post.cover_id = form.cover; post.cover_id = form.cover;
post.update(&*conn, &rockets.searcher) post.update(&*conn, &rockets.searcher)
.expect("post::update: update error"); .expect("post::update: update error");;
if post.published { if post.published {
post.update_mentions( post.update_mentions(
@@ -308,7 +308,7 @@ pub fn update(
.filter_map(|m| Mention::build_activity(&rockets, &m).ok()) .filter_map(|m| Mention::build_activity(&rockets, &m).ok())
.collect(), .collect(),
) )
.expect("post::update: mentions error"); .expect("post::update: mentions error");;
} }
let tags = form let tags = form
@@ -367,8 +367,8 @@ pub fn update(
&*form, &*form,
form.draft, form.draft,
Some(post), Some(post),
errors, errors.clone(),
medias, medias.clone(),
cl.0 cl.0
)) ))
.into() .into()
@@ -406,7 +406,7 @@ pub fn create(
rockets: PlumeRocket, rockets: PlumeRocket,
) -> Result<RespondOrRedirect, ErrorPage> { ) -> Result<RespondOrRedirect, ErrorPage> {
let conn = &*rockets.conn; let conn = &*rockets.conn;
let blog = Blog::find_by_fqn(&rockets, &blog_name).expect("post::create: blog error"); let blog = Blog::find_by_fqn(&rockets, &blog_name).expect("post::create: blog error");;
let slug = form.title.to_string().to_kebab_case(); let slug = form.title.to_string().to_kebab_case();
let user = rockets.user.clone().unwrap(); let user = rockets.user.clone().unwrap();
@@ -553,7 +553,7 @@ pub fn create(
&*form, &*form,
form.draft, form.draft,
None, None,
errors, errors.clone(),
medias, medias,
cl.0 cl.0
)) ))
@@ -579,7 +579,9 @@ pub fn delete(
.any(|a| a.id == user.id) .any(|a| a.id == user.id)
{ {
return Ok(Flash::error( return Ok(Flash::error(
Redirect::to(uri!(details: blog = blog_name, slug = slug, responding_to = _)), Redirect::to(
uri!(details: blog = blog_name.clone(), slug = slug.clone(), responding_to = _),
),
i18n!(intl.catalog, "You are not allowed to delete this article."), i18n!(intl.catalog, "You are not allowed to delete this article."),
)); ));
} }
@@ -643,7 +645,7 @@ pub fn remote_interact_post(
.and_then(|blog| Post::find_by_slug(&rockets.conn, &slug, blog.id))?; .and_then(|blog| Post::find_by_slug(&rockets.conn, &slug, blog.id))?;
if let Some(uri) = User::fetch_remote_interact_uri(&remote.remote) if let Some(uri) = User::fetch_remote_interact_uri(&remote.remote)
.ok() .ok()
.map(|uri| uri.replace("{uri}", &target.ap_url)) .and_then(|uri| rt_format!(uri, uri = target.ap_url).ok())
{ {
Ok(Redirect::to(uri).into()) Ok(Redirect::to(uri).into())
} else { } else {
+1 -1
View File
@@ -1,13 +1,13 @@
use rocket::response::{Flash, Redirect}; use rocket::response::{Flash, Redirect};
use rocket_i18n::I18n; use rocket_i18n::I18n;
use crate::routes::errors::ErrorPage;
use plume_common::activity_pub::broadcast; use plume_common::activity_pub::broadcast;
use plume_common::utils; use plume_common::utils;
use plume_models::{ use plume_models::{
blogs::Blog, inbox::inbox, posts::Post, reshares::*, timeline::*, users::User, Error, blogs::Blog, inbox::inbox, posts::Post, reshares::*, timeline::*, users::User, Error,
PlumeRocket, PlumeRocket,
}; };
use routes::errors::ErrorPage;
#[post("/~/<blog>/<slug>/reshare")] #[post("/~/<blog>/<slug>/reshare")]
pub fn create( pub fn create(
+2 -2
View File
@@ -1,10 +1,10 @@
use chrono::offset::Utc; use chrono::offset::Utc;
use rocket::request::Form; use rocket::request::Form;
use crate::routes::Page;
use crate::template_utils::{IntoContext, Ructe};
use plume_models::{search::Query, PlumeRocket}; use plume_models::{search::Query, PlumeRocket};
use routes::Page;
use std::str::FromStr; use std::str::FromStr;
use template_utils::{IntoContext, Ructe};
#[derive(Default, FromForm)] #[derive(Default, FromForm)]
pub struct SearchQuery { pub struct SearchQuery {
+9 -9
View File
@@ -1,13 +1,13 @@
use crate::routes::RespondOrRedirect;
use lettre::Transport; use lettre::Transport;
use rocket::http::ext::IntoOwned; use rocket::http::ext::IntoOwned;
use rocket::{ use rocket::{
http::{uri::Uri, Cookie, Cookies, SameSite}, http::{uri::Uri, Cookie, Cookies, SameSite},
request::LenientForm, request::{Form, LenientForm},
response::{Flash, Redirect}, response::{Flash, Redirect},
State, State,
}; };
use rocket_i18n::I18n; use rocket_i18n::I18n;
use routes::RespondOrRedirect;
use std::{ use std::{
borrow::Cow, borrow::Cow,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
@@ -15,13 +15,13 @@ use std::{
}; };
use validator::{Validate, ValidationError, ValidationErrors}; use validator::{Validate, ValidationError, ValidationErrors};
use crate::mail::{build_mail, Mailer}; use mail::{build_mail, Mailer};
use crate::template_utils::{IntoContext, Ructe};
use plume_models::{ use plume_models::{
password_reset_requests::*, password_reset_requests::*,
users::{User, AUTH_COOKIE}, users::{User, AUTH_COOKIE},
Error, PlumeRocket, CONFIG, Error, PlumeRocket, CONFIG,
}; };
use template_utils::{IntoContext, Ructe};
#[get("/login?<m>")] #[get("/login?<m>")]
pub fn new(m: Option<String>, rockets: PlumeRocket) -> Ructe { pub fn new(m: Option<String>, rockets: PlumeRocket) -> Ructe {
@@ -44,7 +44,7 @@ pub struct LoginForm {
#[post("/login", data = "<form>")] #[post("/login", data = "<form>")]
pub fn create( pub fn create(
form: LenientForm<LoginForm>, form: LenientForm<LoginForm>,
mut cookies: Cookies<'_>, mut cookies: Cookies,
rockets: PlumeRocket, rockets: PlumeRocket,
) -> RespondOrRedirect { ) -> RespondOrRedirect {
let conn = &*rockets.conn; let conn = &*rockets.conn;
@@ -118,7 +118,7 @@ pub fn create(
} }
#[get("/logout")] #[get("/logout")]
pub fn delete(mut cookies: Cookies<'_>, intl: I18n) -> Flash<Redirect> { pub fn delete(mut cookies: Cookies, intl: I18n) -> Flash<Redirect> {
if let Some(cookie) = cookies.get_private(AUTH_COOKIE) { if let Some(cookie) = cookies.get_private(AUTH_COOKIE) {
cookies.remove_private(cookie); cookies.remove_private(cookie);
} }
@@ -158,8 +158,8 @@ pub struct ResetForm {
#[post("/password-reset", data = "<form>")] #[post("/password-reset", data = "<form>")]
pub fn password_reset_request( pub fn password_reset_request(
mail: State<'_, Arc<Mutex<Mailer>>>, mail: State<Arc<Mutex<Mailer>>>,
form: LenientForm<ResetForm>, form: Form<ResetForm>,
rockets: PlumeRocket, rockets: PlumeRocket,
) -> Ructe { ) -> Ructe {
if User::find_by_email(&*rockets.conn, &form.email).is_ok() { if User::find_by_email(&*rockets.conn, &form.email).is_ok() {
@@ -216,7 +216,7 @@ fn passwords_match(form: &NewPasswordForm) -> Result<(), ValidationError> {
#[post("/password-reset/<token>", data = "<form>")] #[post("/password-reset/<token>", data = "<form>")]
pub fn password_reset( pub fn password_reset(
token: String, token: String,
form: LenientForm<NewPasswordForm>, form: Form<NewPasswordForm>,
rockets: PlumeRocket, rockets: PlumeRocket,
) -> Result<Flash<Redirect>, Ructe> { ) -> Result<Flash<Redirect>, Ructe> {
form.validate() form.validate()
+2 -2
View File
@@ -1,6 +1,6 @@
use crate::routes::{errors::ErrorPage, Page};
use crate::template_utils::{IntoContext, Ructe};
use plume_models::{posts::Post, PlumeRocket}; use plume_models::{posts::Post, PlumeRocket};
use routes::{errors::ErrorPage, Page};
use template_utils::{IntoContext, Ructe};
#[get("/tag/<name>?<page>")] #[get("/tag/<name>?<page>")]
pub fn tag(name: String, page: Option<Page>, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> { pub fn tag(name: String, page: Option<Page>, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> {
+2 -2
View File
@@ -1,10 +1,10 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::routes::Page;
use crate::template_utils::IntoContext;
use crate::{routes::errors::ErrorPage, template_utils::Ructe}; use crate::{routes::errors::ErrorPage, template_utils::Ructe};
use plume_models::{timeline::*, PlumeRocket}; use plume_models::{timeline::*, PlumeRocket};
use rocket::response::Redirect; use rocket::response::Redirect;
use routes::Page;
use template_utils::IntoContext;
#[get("/timeline/<id>?<page>")] #[get("/timeline/<id>?<page>")]
pub fn details(id: i32, rockets: PlumeRocket, page: Option<Page>) -> Result<Ructe, ErrorPage> { pub fn details(id: i32, rockets: PlumeRocket, page: Option<Page>) -> Result<Ructe, ErrorPage> {
+28 -22
View File
@@ -2,6 +2,7 @@ use activitypub::{
activity::Create, activity::Create,
collection::{OrderedCollection, OrderedCollectionPage}, collection::{OrderedCollection, OrderedCollectionPage},
}; };
use atom_syndication::{Entry, FeedBuilder};
use diesel::SaveChangesDsl; use diesel::SaveChangesDsl;
use rocket::{ use rocket::{
http::{ContentType, Cookies}, http::{ContentType, Cookies},
@@ -13,9 +14,7 @@ use serde_json;
use std::{borrow::Cow, collections::HashMap}; use std::{borrow::Cow, collections::HashMap};
use validator::{Validate, ValidationError, ValidationErrors}; use validator::{Validate, ValidationError, ValidationErrors};
use crate::inbox; use inbox;
use crate::routes::{errors::ErrorPage, Page, RemoteForm, RespondOrRedirect};
use crate::template_utils::{IntoContext, Ructe};
use plume_common::activity_pub::{broadcast, inbox::FromId, ActivityStream, ApRequest, Id}; use plume_common::activity_pub::{broadcast, inbox::FromId, ActivityStream, ApRequest, Id};
use plume_common::utils; use plume_common::utils;
use plume_models::{ use plume_models::{
@@ -32,6 +31,8 @@ use plume_models::{
users::*, users::*,
Error, PlumeRocket, Error, PlumeRocket,
}; };
use routes::{errors::ErrorPage, Page, RemoteForm, RespondOrRedirect};
use template_utils::{IntoContext, Ructe};
#[get("/me")] #[get("/me")]
pub fn me(user: Option<User>) -> RespondOrRedirect { pub fn me(user: Option<User>) -> RespondOrRedirect {
@@ -201,14 +202,15 @@ pub fn follow_not_connected(
if let Some(uri) = User::fetch_remote_interact_uri(&remote_form) if let Some(uri) = User::fetch_remote_interact_uri(&remote_form)
.ok() .ok()
.and_then(|uri| { .and_then(|uri| {
Some(uri.replace( rt_format!(
"{uri}", uri,
&format!( uri = format!(
"{}@{}", "{}@{}",
target.fqn, target.fqn,
target.get_instance(&rockets.conn).ok()?.public_domain target.get_instance(&rockets.conn).ok()?.public_domain
), )
)) )
.ok()
}) })
{ {
Ok(Redirect::to(uri).into()) Ok(Redirect::to(uri).into())
@@ -353,7 +355,7 @@ pub fn edit(name: String, user: User, rockets: PlumeRocket) -> Result<Ructe, Err
ValidationErrors::default() ValidationErrors::default()
))) )))
} else { } else {
Err(Error::Unauthorized.into()) Err(Error::Unauthorized)?
} }
} }
@@ -397,10 +399,7 @@ pub fn update(
) )
.0, .0,
); );
user.preferred_theme = form user.preferred_theme = form.theme.clone();
.theme
.clone()
.and_then(|t| if &t == "" { None } else { Some(t) });
user.hide_custom_css = form.hide_custom_css; user.hide_custom_css = form.hide_custom_css;
let _: User = user.save_changes(&*conn).map_err(Error::from)?; let _: User = user.save_changes(&*conn).map_err(Error::from)?;
@@ -414,7 +413,7 @@ pub fn update(
pub fn delete( pub fn delete(
name: String, name: String,
user: User, user: User,
mut cookies: Cookies<'_>, mut cookies: Cookies,
rockets: PlumeRocket, rockets: PlumeRocket,
) -> Result<Flash<Redirect>, ErrorPage> { ) -> Result<Flash<Redirect>, ErrorPage> {
let account = User::find_by_fqn(&rockets, &name)?; let account = User::find_by_fqn(&rockets, &name)?;
@@ -581,7 +580,7 @@ pub fn outbox_page(
pub fn inbox( pub fn inbox(
name: String, name: String,
data: inbox::SignedJson<serde_json::Value>, data: inbox::SignedJson<serde_json::Value>,
headers: Headers<'_>, headers: Headers,
rockets: PlumeRocket, rockets: PlumeRocket,
) -> Result<String, status::BadRequest<&'static str>> { ) -> Result<String, status::BadRequest<&'static str>> {
User::find_by_fqn(&rockets, &name).map_err(|_| status::BadRequest(Some("User not found")))?; User::find_by_fqn(&rockets, &name).map_err(|_| status::BadRequest(Some("User not found")))?;
@@ -617,13 +616,20 @@ pub fn ap_followers(
pub fn atom_feed(name: String, rockets: PlumeRocket) -> Option<Content<String>> { pub fn atom_feed(name: String, rockets: PlumeRocket) -> Option<Content<String>> {
let conn = &*rockets.conn; let conn = &*rockets.conn;
let author = User::find_by_fqn(&rockets, &name).ok()?; let author = User::find_by_fqn(&rockets, &name).ok()?;
let entries = Post::get_recents_for_author(conn, &author, 15).ok()?; let feed = FeedBuilder::default()
let uri = Instance::get_local() .title(author.display_name.clone())
.ok()? .id(Instance::get_local()
.compute_box("@", &name, "atom.xml"); .unwrap()
let title = &author.display_name; .compute_box("@", &name, "atom.xml"))
let default_updated = &author.creation_date; .entries(
let feed = super::build_atom_feed(entries, &uri, title, default_updated, conn); Post::get_recents_for_author(conn, &author, 15)
.ok()?
.into_iter()
.map(|p| super::post_to_atom(p, conn))
.collect::<Vec<Entry>>(),
)
.build()
.expect("user::atom_feed: Error building Atom feed");
Some(Content( Some(Content(
ContentType::new("application", "atom+xml"), ContentType::new("application", "atom+xml"),
feed.to_string(), feed.to_string(),
+4 -4
View File
@@ -1,6 +1,5 @@
use plume_models::{notifications::*, users::User, Connection, PlumeRocket}; use plume_models::{notifications::*, users::User, Connection, PlumeRocket};
use crate::templates::Html;
use rocket::http::hyper::header::{ETag, EntityTag}; use rocket::http::hyper::header::{ETag, EntityTag};
use rocket::http::{Method, Status}; use rocket::http::{Method, Status};
use rocket::request::Request; use rocket::request::Request;
@@ -8,6 +7,7 @@ use rocket::response::{self, content::Html as HtmlCt, Responder, Response};
use rocket_i18n::Catalog; use rocket_i18n::Catalog;
use std::collections::{btree_map::BTreeMap, hash_map::DefaultHasher}; use std::collections::{btree_map::BTreeMap, hash_map::DefaultHasher};
use std::hash::Hasher; use std::hash::Hasher;
use templates::Html;
pub use askama_escape::escape; pub use askama_escape::escape;
@@ -53,7 +53,7 @@ impl IntoContext for PlumeRocket {
pub struct Ructe(pub Vec<u8>); pub struct Ructe(pub Vec<u8>);
impl<'r> Responder<'r> for Ructe { impl<'r> Responder<'r> for Ructe {
fn respond_to(self, r: &Request<'_>) -> response::Result<'r> { fn respond_to(self, r: &Request) -> response::Result<'r> {
//if method is not Get or page contain a form, no caching //if method is not Get or page contain a form, no caching
if r.method() != Method::Get || self.0.windows(6).any(|w| w == b"<form ") { if r.method() != Method::Get || self.0.windows(6).any(|w| w == b"<form ") {
return HtmlCt(self.0).respond_to(r); return HtmlCt(self.0).respond_to(r);
@@ -82,7 +82,7 @@ impl<'r> Responder<'r> for Ructe {
macro_rules! render { macro_rules! render {
($group:tt :: $page:tt ( $( $param:expr ),* ) ) => { ($group:tt :: $page:tt ( $( $param:expr ),* ) ) => {
{ {
use crate::templates; use templates;
let mut res = vec![]; let mut res = vec![];
templates::$group::$page( templates::$group::$page(
@@ -96,7 +96,7 @@ macro_rules! render {
} }
} }
pub fn translate_notification(ctx: BaseContext<'_>, notif: Notification) -> String { pub fn translate_notification(ctx: BaseContext, notif: Notification) -> String {
let name = notif.get_actor(ctx.0).unwrap().name(); let name = notif.get_actor(ctx.0).unwrap().name();
match notif.kind.as_ref() { match notif.kind.as_ref() {
notification_kind::COMMENT => i18n!(ctx.1, "{0} commented on your article."; &name), notification_kind::COMMENT => i18n!(ctx.1, "{0} commented on your article."; &name),
+2 -3
View File
@@ -1,9 +1,8 @@
@use plume_models::CONFIG; @use plume_models::CONFIG;
@use plume_models::instance::Instance; @use plume_models::instance::Instance;
@use template_utils::*;
@use routes::*;
@use std::path::Path; @use std::path::Path;
@use crate::template_utils::*;
@use crate::routes::*;
@(ctx: BaseContext, title: String, head: Content, header: Content, content: Content) @(ctx: BaseContext, title: String, head: Content, header: Content, content: Content)
<!DOCTYPE html> <!DOCTYPE html>
+3 -3
View File
@@ -2,10 +2,10 @@
@use plume_models::instance::Instance; @use plume_models::instance::Instance;
@use plume_models::posts::Post; @use plume_models::posts::Post;
@use plume_models::users::User; @use plume_models::users::User;
@use templates::{base, partials::post_card};
@use template_utils::*;
@use routes::*;
@use std::path::Path; @use std::path::Path;
@use crate::templates::{base, partials::post_card};
@use crate::template_utils::*;
@use crate::routes::*;
@(ctx: BaseContext, blog: Blog, authors: &[User], page: i32, n_pages: i32, posts: Vec<Post>) @(ctx: BaseContext, blog: Blog, authors: &[User], page: i32, n_pages: i32, posts: Vec<Post>)
+6 -6
View File
@@ -2,12 +2,12 @@
@use plume_models::blogs::Blog; @use plume_models::blogs::Blog;
@use plume_models::instance::Instance; @use plume_models::instance::Instance;
@use plume_models::medias::Media; @use plume_models::medias::Media;
@use crate::template_utils::*; @use routes::blogs;
@use crate::templates::base; @use routes::blogs::EditForm;
@use crate::templates::partials::image_select; @use routes::medias;
@use crate::routes::blogs; @use template_utils::*;
@use crate::routes::blogs::EditForm; @use templates::base;
@use crate::routes::medias; @use templates::partials::image_select;
@(ctx: BaseContext, blog: &Blog, medias: Vec<Media>, form: &EditForm, errors: ValidationErrors) @(ctx: BaseContext, blog: &Blog, medias: Vec<Media>, form: &EditForm, errors: ValidationErrors)
+4 -4
View File
@@ -1,8 +1,8 @@
@use validator::ValidationErrors; @use validator::ValidationErrors;
@use crate::templates::base; @use templates::base;
@use crate::template_utils::*; @use template_utils::*;
@use crate::routes::blogs::NewBlogForm; @use routes::blogs::NewBlogForm;
@use crate::routes::*; @use routes::*;
@(ctx: BaseContext, form: &NewBlogForm, errors: ValidationErrors) @(ctx: BaseContext, form: &NewBlogForm, errors: ValidationErrors)
+2 -2
View File
@@ -1,5 +1,5 @@
@use crate::templates::base as base_template; @use templates::base as base_template;
@use crate::template_utils::*; @use template_utils::*;
@(ctx: BaseContext, error_message: String, error: Content) @(ctx: BaseContext, error_message: String, error: Content)
+2 -2
View File
@@ -1,5 +1,5 @@
@use crate::templates::errors::base; @use templates::errors::base;
@use crate::template_utils::*; @use template_utils::*;
@(ctx: BaseContext) @(ctx: BaseContext)
+2 -2
View File
@@ -1,5 +1,5 @@
@use crate::templates::errors::base; @use templates::errors::base;
@use crate::template_utils::*; @use template_utils::*;
@(ctx: BaseContext, error_message: String) @(ctx: BaseContext, error_message: String)
+3 -2
View File
@@ -1,5 +1,5 @@
@use crate::templates::errors::base; @use templates::errors::base;
@use crate::template_utils::*; @use template_utils::*;
@(ctx: BaseContext) @(ctx: BaseContext)
@@ -7,3 +7,4 @@
<h1>@i18n!(ctx.1, "We couldn't find this page.")</h1> <h1>@i18n!(ctx.1, "We couldn't find this page.")</h1>
<p>@i18n!(ctx.1, "The link that led you here may be broken.")</p> <p>@i18n!(ctx.1, "The link that led you here may be broken.")</p>
}) })
+2 -2
View File
@@ -1,5 +1,5 @@
@use crate::templates::errors::base; @use templates::errors::base;
@use crate::template_utils::*; @use template_utils::*;
@(ctx: BaseContext) @(ctx: BaseContext)
@@ -1,5 +1,5 @@
@use crate::templates::errors::base; @use templates::errors::base;
@use crate::template_utils::*; @use template_utils::*;
@(ctx: BaseContext) @(ctx: BaseContext)
@@ -7,3 +7,4 @@
<h1>@i18n!(ctx.1, "The content you sent can't be processed.")</h1> <h1>@i18n!(ctx.1, "The content you sent can't be processed.")</h1>
<p>@i18n!(ctx.1, "Maybe it was too long.")</p> <p>@i18n!(ctx.1, "Maybe it was too long.")</p>
}) })
+3 -3
View File
@@ -1,7 +1,7 @@
@use plume_models::{instance::Instance, users::User}; @use plume_models::{instance::Instance, users::User};
@use crate::templates::base; @use templates::base;
@use crate::template_utils::*; @use template_utils::*;
@use crate::routes::*; @use routes::*;
@(ctx: BaseContext, instance: Instance, admin: User, n_users: i64, n_articles: i64, n_instances: i64) @(ctx: BaseContext, instance: Instance, admin: User, n_users: i64, n_articles: i64, n_instances: i64)
+4 -4
View File
@@ -1,9 +1,9 @@
@use plume_models::instance::Instance; @use plume_models::instance::Instance;
@use validator::ValidationErrors; @use validator::ValidationErrors;
@use crate::templates::base; @use templates::base;
@use crate::template_utils::*; @use template_utils::*;
@use crate::routes::instance::InstanceSettingsForm; @use routes::instance::InstanceSettingsForm;
@use crate::routes::*; @use routes::*;
@(ctx: BaseContext, instance: Instance, form: InstanceSettingsForm, errors: ValidationErrors) @(ctx: BaseContext, instance: Instance, form: InstanceSettingsForm, errors: ValidationErrors)
+3 -3
View File
@@ -1,6 +1,6 @@
@use crate::templates::base; @use templates::base;
@use crate::template_utils::*; @use template_utils::*;
@use crate::routes::*; @use routes::*;
@(ctx: BaseContext) @(ctx: BaseContext)
+5 -5
View File
@@ -1,7 +1,7 @@
@use templates::base;
@use plume_models::blocklisted_emails::BlocklistedEmail; @use plume_models::blocklisted_emails::BlocklistedEmail;
@use crate::templates::base; @use template_utils::*;
@use crate::template_utils::*; @use routes::*;
@use crate::routes::*;
@(ctx:BaseContext, emails: Vec<BlocklistedEmail>, page:i32, n_pages:i32) @(ctx:BaseContext, emails: Vec<BlocklistedEmail>, page:i32, n_pages:i32)
@:base(ctx, i18n!(ctx.1, "Blocklisted Emails"), {}, {}, { @:base(ctx, i18n!(ctx.1, "Blocklisted Emails"), {}, {}, {
@@ -32,9 +32,9 @@
<form method="post" action="@uri!(instance::delete_email_blocklist)"> <form method="post" action="@uri!(instance::delete_email_blocklist)">
<header> <header>
@if emails.is_empty() { @if emails.is_empty() {
<p class="center" >@i18n!(ctx.1, "There are no blocked emails on your instance")</p>
} else {
<input type="submit" class="destructive" value='@i18n!(ctx.1, "Delete selected emails")'> <input type="submit" class="destructive" value='@i18n!(ctx.1, "Delete selected emails")'>
} else {
<p class="center" >@i18n!(ctx.1, "There are no blocked emails on your instance")</p>
} }
</header> </header>
<div class="list"> <div class="list">
+3 -3
View File
@@ -1,9 +1,9 @@
@use templates::{base, partials::*};
@use template_utils::*;
@use plume_models::instance::Instance; @use plume_models::instance::Instance;
@use plume_models::posts::Post; @use plume_models::posts::Post;
@use plume_models::timeline::Timeline; @use plume_models::timeline::Timeline;
@use crate::templates::{base, partials::*}; @use routes::*;
@use crate::template_utils::*;
@use crate::routes::*;
@(ctx: BaseContext, instance: Instance, n_users: i64, n_articles: i64, all_tl: Vec<(Timeline, Vec<Post>)>) @(ctx: BaseContext, instance: Instance, n_users: i64, n_articles: i64, all_tl: Vec<(Timeline, Vec<Post>)>)
+4 -4
View File
@@ -1,11 +1,11 @@
@use plume_models::instance::Instance; @use plume_models::instance::Instance;
@use crate::templates::base; @use templates::base;
@use crate::template_utils::*; @use template_utils::*;
@use crate::routes::*; @use routes::*;
@(ctx: BaseContext, instance: Instance, instances: Vec<Instance>, page: i32, n_pages: i32) @(ctx: BaseContext, instance: Instance, instances: Vec<Instance>, page: i32, n_pages: i32)
@:base(ctx, i18n!(ctx.1, "Administration of {0}"; instance.name), {}, {}, { @:base(ctx, i18n!(ctx.1, "Administration of {0}"; instance.name.clone()), {}, {}, {
<h1>@i18n!(ctx.1, "Instances")</h1> <h1>@i18n!(ctx.1, "Instances")</h1>
@tabs(&[ @tabs(&[
+2 -2
View File
@@ -1,5 +1,5 @@
@use crate::templates::base; @use templates::base;
@use crate::template_utils::*; @use template_utils::*;
@(ctx: BaseContext) @(ctx: BaseContext)

Some files were not shown because too many files have changed in this diff Show More