Compare commits
38 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9ddba17d46 | |||
| b04426a330 | |||
| 925254983e | |||
| 4c6fb83793 | |||
| 7c456009be | |||
| db916039db | |||
| 06c625c686 | |||
| f2203710cb | |||
| 3c1617c4f9 | |||
| 2388a5846d | |||
| b102534136 | |||
| 072e32da30 | |||
| 5ea3e73727 | |||
| f340bd50c7 | |||
| 3de6b46465 | |||
| 3c6d5de314 | |||
| 2a4b98dce4 | |||
| d253fee523 | |||
| 07731d0b73 | |||
| 15cbd17003 | |||
| 5d3b3485fa | |||
| 8a2788bf6a | |||
| ecbd64efb1 | |||
| 9245320712 | |||
| 7cf3a4b37c | |||
| 3ddd6d0254 | |||
| 7edd0220b6 | |||
| b26e785277 | |||
| b2829908f1 | |||
| 60bb5b72f6 | |||
| 9e0bbf81ed | |||
| 28576c1fa3 | |||
| d99b42582d | |||
| 92a386277b | |||
| 297d9fcf40 | |||
| ef70cb93e6 | |||
| efb76a3c17 | |||
| 197f0d7ecd |
@@ -1,5 +1,5 @@
|
||||
localhost:443 {
|
||||
proxy / localhost:7878 {
|
||||
proxy / integration:7878 {
|
||||
transparent
|
||||
}
|
||||
tls self_signed
|
||||
|
||||
+233
@@ -0,0 +1,233 @@
|
||||
// This is the CI config for Plume.
|
||||
// It uses a Drone CI instance, on https://ci.joinplu.me
|
||||
|
||||
// First of all, we define a few useful constants
|
||||
|
||||
// This Docker image contains everything we need to build Plume.
|
||||
// Its Dockerfile can be found at https://git.joinplu.me/plume/buildenv
|
||||
local plumeEnv = "plumeorg/plume-buildenv:v0.2.0";
|
||||
|
||||
// Common cache config
|
||||
local cacheConfig(name, extra) = {
|
||||
name: name,
|
||||
image: "meltwater/drone-cache:dev",
|
||||
pull: true,
|
||||
environment: {
|
||||
AWS_ACCESS_KEY_ID: { from_secret: 'minio_key' },
|
||||
AWS_SECRET_ACCESS_KEY: { from_secret: 'minio_secret' },
|
||||
},
|
||||
settings: extra + {
|
||||
cache_key: 'v0-{{ checksum "Cargo.lock" }}-{{ .Commit.Branch }}',
|
||||
archive_format: "gzip",
|
||||
mount: [ "~/.cargo/", "./target" ],
|
||||
bucket: 'cache',
|
||||
path_style: true,
|
||||
endpoints: "127.0.0.1:9000",
|
||||
region: 'us-east-1',
|
||||
debug: true,
|
||||
},
|
||||
volumes: [ { name: "cache", path: "/tmp/cache" } ]
|
||||
};
|
||||
|
||||
|
||||
// A pipeline step that restores the cache.
|
||||
// The cache contains all the cargo build files.
|
||||
// Thus, we don't have to download and compile all of our dependencies for each
|
||||
// commit.
|
||||
// This cache is only "deleted" when the contents of Cargo.lock changes.
|
||||
//
|
||||
// We use this plugin for caching: https://github.com/meltwater/drone-cache/
|
||||
//
|
||||
// Potential TODO: use one cache per pipeline, as we used to do when we were
|
||||
// using CircleCI.
|
||||
local restoreCache = cacheConfig("restore-cache", { restore: true });
|
||||
// And a step that saves the cache.
|
||||
local saveCache = cacheConfig("save-cache", { rebuild: true });
|
||||
|
||||
// This step starts a PostgreSQL database if the db parameter is "postgres",
|
||||
// otherwise it does nothing.
|
||||
local startDb(db) = if db == "postgres" then {
|
||||
name: "start-db",
|
||||
image: "postgres:12.3-alpine",
|
||||
detach: true,
|
||||
environment: {
|
||||
POSTGRES_USER: "plume",
|
||||
POSTGRES_DB: "plume",
|
||||
POSTGRES_PASSWORD: "password",
|
||||
}
|
||||
} else {};
|
||||
|
||||
// A utility function to generate a new pipeline
|
||||
local basePipeline(name, steps) = {
|
||||
kind: "pipeline",
|
||||
name: name,
|
||||
type: "docker",
|
||||
environment: {
|
||||
RUST_TEST_THREADS: '1',
|
||||
},
|
||||
steps: steps
|
||||
};
|
||||
|
||||
// And this function creates a pipeline with caching
|
||||
local cachedPipeline(name, commands) = basePipeline(
|
||||
name,
|
||||
[
|
||||
restoreCache,
|
||||
{
|
||||
name: name,
|
||||
image: plumeEnv,
|
||||
commands: commands,
|
||||
},
|
||||
saveCache
|
||||
]
|
||||
);
|
||||
|
||||
// This function creates a step to upload artifacts to Minio
|
||||
local upload(name, source) = {
|
||||
name: name,
|
||||
image: 'plugins/s3',
|
||||
settings: {
|
||||
bucket: 'artifacts',
|
||||
source: source,
|
||||
target: '/${DRONE_BUILD_NUMBER}',
|
||||
path_style: true,
|
||||
endpoint: 'http://127.0.0.1:9000',
|
||||
access_key: { from_secret: 'minio_key' },
|
||||
secret_key: { from_secret: 'minio_secret' },
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
// Here starts the actual list of pipelines!
|
||||
|
||||
// PIPELINE 1: a pipeline that runs cargo fmt, and that fails if the style of
|
||||
// the code is not standard.
|
||||
local CargoFmt() = cachedPipeline(
|
||||
"cargo-fmt",
|
||||
[ "cargo fmt --all -- --check" ]
|
||||
);
|
||||
|
||||
// PIPELINE 2: runs clippy, a tool that helps
|
||||
// you writing idiomatic Rust.
|
||||
|
||||
// Helper function:
|
||||
local cmd(db, pkg, features=true) = if features then
|
||||
"cargo clippy --no-default-features --features " + db + " --release -p "
|
||||
+ pkg + " -- -D warnings"
|
||||
else
|
||||
"cargo clippy --no-default-features --release -p "
|
||||
+ pkg + " -- -D warnings";
|
||||
|
||||
// The actual pipeline:
|
||||
local Clippy(db) = cachedPipeline(
|
||||
"clippy-" + db,
|
||||
[
|
||||
cmd(db, "plume"),
|
||||
cmd(db, "plume-cli"),
|
||||
cmd(db, "plume-front", false)
|
||||
]
|
||||
);
|
||||
|
||||
// PIPELINE 3: runs unit tests
|
||||
local Unit(db) = cachedPipeline(
|
||||
"unit-" + db,
|
||||
[
|
||||
"cargo test --all --exclude plume-front --exclude plume-macro"
|
||||
+ " --no-run --no-default-features --features=" + db
|
||||
]
|
||||
);
|
||||
|
||||
// PIPELINE 4: runs integration tests
|
||||
// It installs a local instance an run integration test with Python scripts
|
||||
// that use Selenium (located in scripts/browser_test).
|
||||
local Integration(db) = basePipeline(
|
||||
"integration-" + db,
|
||||
[
|
||||
restoreCache,
|
||||
startDb(db),
|
||||
{
|
||||
name: 'selenium',
|
||||
image: 'elgalu/selenium:latest',
|
||||
detach: true,
|
||||
},
|
||||
{
|
||||
name: "integration",
|
||||
image: plumeEnv,
|
||||
environment: {
|
||||
BROWSER: "firefox",
|
||||
DATABASE_URL: if db == "postgres" then "postgres://plume:password@start-db/plume" else "plume.db",
|
||||
},
|
||||
commands: [
|
||||
// Install the front-end
|
||||
"cargo web deploy -p plume-front",
|
||||
// Install the server
|
||||
'cargo install --debug --no-default-features --features="'
|
||||
+ db + '",test --force --path .',
|
||||
// Install plm
|
||||
'cargo install --debug --no-default-features --features="'
|
||||
+ db + '" --force --path plume-cli',
|
||||
// Run the tests
|
||||
"./script/run_browser_test.sh"
|
||||
],
|
||||
},
|
||||
saveCache,
|
||||
]
|
||||
);
|
||||
|
||||
// PIPELINE 5: make a release build and save artifacts
|
||||
//
|
||||
// It should also deploy the SQlite build to a test instance
|
||||
// located at https://pr-XXX.joinplu.me (but this system is not very
|
||||
// stable, and often breaks).
|
||||
local Release(db) = basePipeline(
|
||||
"release-" + db,
|
||||
[
|
||||
restoreCache,
|
||||
{
|
||||
name: 'release-' + db,
|
||||
image: plumeEnv,
|
||||
commands: [
|
||||
"cargo web deploy -p plume-front --release",
|
||||
"cargo build --release --no-default-features --features=" + db + " -p plume",
|
||||
"cargo build --release --no-default-features --features=" + db + " -p plume-cli",
|
||||
"./script/generate_artifact.sh",
|
||||
] + if db == "sqlite" then
|
||||
[ "./script/upload_test_environment.sh" ] else
|
||||
[]
|
||||
},
|
||||
upload('artifacts-' + db, '*.tar.gz'),
|
||||
saveCache,
|
||||
]
|
||||
|
||||
);
|
||||
|
||||
// PIPELINE 6: upload the new PO templates (.pot) to Crowdin
|
||||
//
|
||||
// TODO: run only on master
|
||||
local PushTranslations() = basePipeline(
|
||||
"push-translations",
|
||||
[
|
||||
{
|
||||
name: "push-translations",
|
||||
image: plumeEnv,
|
||||
commands: [
|
||||
"cargo build",
|
||||
"crowdin upload -b master"
|
||||
]
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
// And finally, the list of all our pipelines:
|
||||
[
|
||||
CargoFmt(),
|
||||
Clippy("postgres"),
|
||||
Clippy("sqlite"),
|
||||
Unit("postgres"),
|
||||
Unit("sqlite"),
|
||||
Integration("postgres"),
|
||||
Integration("sqlite"),
|
||||
Release("postgres"),
|
||||
Release("sqlite"),
|
||||
PushTranslations()
|
||||
]
|
||||
@@ -18,4 +18,3 @@ tags.*
|
||||
search_index
|
||||
.buildconfig
|
||||
__pycache__
|
||||
.vscode/
|
||||
|
||||
Generated
+2239
-1758
File diff suppressed because it is too large
Load Diff
+10
-12
@@ -8,7 +8,6 @@ edition = "2018"
|
||||
[dependencies]
|
||||
activitypub = "0.1.3"
|
||||
askama_escape = "0.1"
|
||||
async-trait = "*"
|
||||
atom_syndication = "0.6"
|
||||
clap = "2.33"
|
||||
colored = "1.8"
|
||||
@@ -21,8 +20,9 @@ heck = "0.3.0"
|
||||
lettre = "0.9.2"
|
||||
lettre_email = "0.9.2"
|
||||
num_cpus = "1.10"
|
||||
rocket = { git = "https://github.com/SergioBenitez/Rocket", rev = "async" }
|
||||
rocket_contrib = { git = "https://github.com/SergioBenitez/Rocket", rev = "async" , features = ["json"] }
|
||||
rocket = "0.4.2"
|
||||
rocket_contrib = { version = "0.4.2", features = ["json"] }
|
||||
rocket_i18n = { git = "https://github.com/Plume-org/rocket_i18n", rev = "e922afa7c366038b3433278c03b1456b346074f2" }
|
||||
rpassword = "4.0"
|
||||
scheduled-thread-pool = "0.2.2"
|
||||
serde = "1.0"
|
||||
@@ -30,10 +30,9 @@ serde_json = "1.0"
|
||||
serde_qs = "0.5"
|
||||
shrinkwraprs = "0.2.1"
|
||||
syntect = "3.3"
|
||||
tokio = "0.2"
|
||||
validator = "0.10"
|
||||
validator_derive = "0.10"
|
||||
webfinger = { git = "https://github.com/Plume-org/webfinger", rev = "4e8f12810c4a7ba7a07bbcb722cd265fdff512b6", features = ["async"] }
|
||||
validator = "0.8"
|
||||
validator_derive = "0.8"
|
||||
webfinger = "0.4.1"
|
||||
|
||||
[[bin]]
|
||||
name = "plume"
|
||||
@@ -65,11 +64,9 @@ path = "plume-common"
|
||||
[dependencies.plume-models]
|
||||
path = "plume-models"
|
||||
|
||||
[dependencies.rocket_i18n]
|
||||
git = "https://github.com/Plume-org/rocket_i18n"
|
||||
branch = "go-async"
|
||||
default-features = false
|
||||
features = ["rocket"]
|
||||
[dependencies.rocket_csrf]
|
||||
git = "https://github.com/fdb-hiroshima/rocket_csrf"
|
||||
rev = "29910f2829e7e590a540da3804336577b48c7b31"
|
||||
|
||||
[build-dependencies]
|
||||
ructe = "0.9.0"
|
||||
@@ -81,6 +78,7 @@ postgres = ["plume-models/postgres", "diesel/postgres"]
|
||||
sqlite = ["plume-models/sqlite", "diesel/sqlite"]
|
||||
debug-mailer = []
|
||||
test = []
|
||||
search-lindera = ["plume-models/search-lindera"]
|
||||
|
||||
[workspace]
|
||||
members = ["plume-api", "plume-cli", "plume-models", "plume-common", "plume-front", "plume-macro"]
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/* Color Scheme */
|
||||
$gray: #F3F3F3;
|
||||
$gray: #f3f3f3;
|
||||
$black: #242424;
|
||||
$white: #F8F8F8;
|
||||
$purple: #7765E3;
|
||||
$white: #f8f8f8;
|
||||
$purple: #7765e3;
|
||||
$lightpurple: #c2bbee;
|
||||
$red: #E92F2F;
|
||||
$red: #e92f2f;
|
||||
$yellow: #ffe347;
|
||||
$green: #23f0c7;
|
||||
|
||||
@@ -24,9 +24,9 @@ $margin: 0 $horizontal-margin;
|
||||
|
||||
/* Fonts */
|
||||
|
||||
$route159: "Route159", serif;
|
||||
$playfair: "Playfair Display", serif;
|
||||
$lora: "Lora", serif;
|
||||
$route159: "Shabnam", "Route159", serif;
|
||||
$playfair: "Vazir", "Playfair Display", serif;
|
||||
$lora: "Vazir", "Lora", serif;
|
||||
|
||||
//Code Highlighting
|
||||
$code-keyword-color: #45244a;
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
/* color palette: https://coolors.co/23f0c7-ef767a-7765e3-6457a6-ffe347 */
|
||||
|
||||
@import url('./feather.css');
|
||||
@import url('./fonts/Route159/Route159.css');
|
||||
@import url('./fonts/Lora/Lora.css');
|
||||
@import url('./fonts/Playfair_Display/PlayfairDisplay.css');
|
||||
@import url("./feather.css");
|
||||
@import url("./fonts/Route159/Route159.css");
|
||||
@import url("./fonts/Lora/Lora.css");
|
||||
@import url("./fonts/Playfair_Display/PlayfairDisplay.css");
|
||||
@import url("./fonts/Vazir_WOL/Vazir_WOL.css");
|
||||
@import url("./fonts/Shabnam_WOL/Shabnam_WOL.css");
|
||||
|
||||
@import 'dark_variables';
|
||||
@import 'global';
|
||||
@import 'header';
|
||||
@import 'article';
|
||||
@import 'forms';
|
||||
@import "dark_variables";
|
||||
@import "global";
|
||||
@import "header";
|
||||
@import "article";
|
||||
@import "forms";
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
Copyright (c) 2015, Saber Rastikerdar (saber.rastikerdar@gmail.com),
|
||||
Glyphs and data from Roboto font are licensed under the Apache License, Version 2.0.
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,49 @@
|
||||
@font-face {
|
||||
font-family: Shabnam;
|
||||
src: url("Shabnam-WOL.eot");
|
||||
src: url("Shabnam-WOL.eot?#iefix") format("embedded-opentype"),
|
||||
url("Shabnam-WOL.woff2") format("woff2"),
|
||||
url("Shabnam-WOL.woff") format("woff"),
|
||||
url("Shabnam-WOL.ttf") format("truetype");
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: Shabnam;
|
||||
src: url("Shabnam-Bold-WOL.eot");
|
||||
src: url("Shabnam-Bold-WOL.eot?#iefix") format("embedded-opentype"),
|
||||
url("Shabnam-Bold-WOL.woff2") format("woff2"),
|
||||
url("Shabnam-Bold-WOL.woff") format("woff"),
|
||||
url("Shabnam-Bold-WOL.ttf") format("truetype");
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: Shabnam;
|
||||
src: url("Shabnam-Thin-WOL.eot");
|
||||
src: url("Shabnam-Thin-WOL.eot?#iefix") format("embedded-opentype"),
|
||||
url("Shabnam-Thin-WOL.woff2") format("woff2"),
|
||||
url("Shabnam-Thin-WOL.woff") format("woff"),
|
||||
url("Shabnam-Thin-WOL.ttf") format("truetype");
|
||||
font-weight: 100;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: Shabnam;
|
||||
src: url("Shabnam-Light-WOL.eot");
|
||||
src: url("Shabnam-Light-WOL.eot?#iefix") format("embedded-opentype"),
|
||||
url("Shabnam-Light-WOL.woff2") format("woff2"),
|
||||
url("Shabnam-Light-WOL.woff") format("woff"),
|
||||
url("Shabnam-Light-WOL.ttf") format("truetype");
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: Shabnam;
|
||||
src: url("Shabnam-Medium-WOL.eot");
|
||||
src: url("Shabnam-Medium-WOL.eot?#iefix") format("embedded-opentype"),
|
||||
url("Shabnam-Medium-WOL.woff2") format("woff2"),
|
||||
url("Shabnam-Medium-WOL.woff") format("woff"),
|
||||
url("Shabnam-Medium-WOL.ttf") format("truetype");
|
||||
font-weight: 500;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
Changes by Saber Rastikerdar (saber.rastikerdar@gmail.com) are in public domain.
|
||||
Glyphs and data from Roboto font are licensed under the Apache License, Version 2.0.
|
||||
|
||||
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
|
||||
|
||||
Bitstream Vera Fonts Copyright
|
||||
------------------------------
|
||||
|
||||
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is
|
||||
a trademark of Bitstream, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of the fonts accompanying this license ("Fonts") and associated
|
||||
documentation files (the "Font Software"), to reproduce and distribute the
|
||||
Font Software, including without limitation the rights to use, copy, merge,
|
||||
publish, distribute, and/or sell copies of the Font Software, and to permit
|
||||
persons to whom the Font Software is furnished to do so, subject to the
|
||||
following conditions:
|
||||
|
||||
The above copyright and trademark notices and this permission notice shall
|
||||
be included in all copies of one or more of the Font Software typefaces.
|
||||
|
||||
The Font Software may be modified, altered, or added to, and in particular
|
||||
the designs of glyphs or characters in the Fonts may be modified and
|
||||
additional glyphs or characters may be added to the Fonts, only if the fonts
|
||||
are renamed to names not containing either the words "Bitstream" or the word
|
||||
"Vera".
|
||||
|
||||
This License becomes null and void to the extent applicable to Fonts or Font
|
||||
Software that has been modified and is distributed under the "Bitstream
|
||||
Vera" names.
|
||||
|
||||
The Font Software may be sold as part of a larger software package but no
|
||||
copy of one or more of the Font Software typefaces may be sold by itself.
|
||||
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
|
||||
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
|
||||
FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING
|
||||
ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
||||
THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE
|
||||
FONT SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the names of Gnome, the Gnome
|
||||
Foundation, and Bitstream Inc., shall not be used in advertising or
|
||||
otherwise to promote the sale, use or other dealings in this Font Software
|
||||
without prior written authorization from the Gnome Foundation or Bitstream
|
||||
Inc., respectively. For further information, contact: fonts at gnome dot
|
||||
org.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,65 @@
|
||||
@font-face {
|
||||
font-family: Vazir;
|
||||
src: url('Vazir-WOL.eot');
|
||||
src: url('Vazir-WOL.eot?#iefix') format('embedded-opentype'),
|
||||
url('Vazir-WOL.woff2') format('woff2'),
|
||||
url('Vazir-WOL.woff') format('woff'),
|
||||
url('Vazir-WOL.ttf') format('truetype');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: Vazir;
|
||||
src: url('Vazir-Bold-WOL.eot');
|
||||
src: url('Vazir-Bold-WOL.eot?#iefix') format('embedded-opentype'),
|
||||
url('Vazir-Bold-WOL.woff2') format('woff2'),
|
||||
url('Vazir-Bold-WOL.woff') format('woff'),
|
||||
url('Vazir-Bold-WOL.ttf') format('truetype');
|
||||
font-weight: bold;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: Vazir;
|
||||
src: url('Vazir-Black-WOL.eot');
|
||||
src: url('Vazir-Black-WOL.eot?#iefix') format('embedded-opentype'),
|
||||
url('Vazir-Black-WOL.woff2') format('woff2'),
|
||||
url('Vazir-Black-WOL.woff') format('woff'),
|
||||
url('Vazir-Black-WOL.ttf') format('truetype');
|
||||
font-weight: 900;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: Vazir;
|
||||
src: url('Vazir-Medium-WOL.eot');
|
||||
src: url('Vazir-Medium-WOL.eot?#iefix') format('embedded-opentype'),
|
||||
url('Vazir-Medium-WOL.woff2') format('woff2'),
|
||||
url('Vazir-Medium-WOL.woff') format('woff'),
|
||||
url('Vazir-Medium-WOL.ttf') format('truetype');
|
||||
font-weight: 500;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: Vazir;
|
||||
src: url('Vazir-Light-WOL.eot');
|
||||
src: url('Vazir-Light-WOL.eot?#iefix') format('embedded-opentype'),
|
||||
url('Vazir-Light-WOL.woff2') format('woff2'),
|
||||
url('Vazir-Light-WOL.woff') format('woff'),
|
||||
url('Vazir-Light-WOL.ttf') format('truetype');
|
||||
font-weight: 300;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: Vazir;
|
||||
src: url('Vazir-Thin-WOL.eot');
|
||||
src: url('Vazir-Thin-WOL.eot?#iefix') format('embedded-opentype'),
|
||||
url('Vazir-Thin-WOL.woff2') format('woff2'),
|
||||
url('Vazir-Thin-WOL.woff') format('woff'),
|
||||
url('Vazir-Thin-WOL.ttf') format('truetype');
|
||||
font-weight: 100;
|
||||
font-style: normal;
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
/* color palette: https://coolors.co/23f0c7-ef767a-7765e3-6457a6-ffe347 */
|
||||
|
||||
@import url('./feather.css');
|
||||
@import url('./fonts/Route159/Route159.css');
|
||||
@import url('./fonts/Lora/Lora.css');
|
||||
@import url('./fonts/Playfair_Display/PlayfairDisplay.css');
|
||||
@import url("./feather.css");
|
||||
@import url("./fonts/Route159/Route159.css");
|
||||
@import url("./fonts/Lora/Lora.css");
|
||||
@import url("./fonts/Playfair_Display/PlayfairDisplay.css");
|
||||
@import url("./fonts/Vazir_WOL/Vazir_WOL.css");
|
||||
@import url("./fonts/Shabnam_WOL/Shabnam_WOL.css");
|
||||
|
||||
@import 'variables';
|
||||
@import 'global';
|
||||
@import 'header';
|
||||
@import 'article';
|
||||
@import 'forms';
|
||||
@import "variables";
|
||||
@import "global";
|
||||
@import "header";
|
||||
@import "article";
|
||||
@import "forms";
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use rsass;
|
||||
|
||||
use ructe::Ructe;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::{ffi::OsStr, fs::*, io::Write, path::*};
|
||||
|
||||
@@ -23,3 +23,4 @@ path = "../plume-models"
|
||||
[features]
|
||||
postgres = ["plume-models/postgres", "diesel/postgres"]
|
||||
sqlite = ["plume-models/sqlite", "diesel/sqlite"]
|
||||
search-lindera = ["plume-models/search-lindera"]
|
||||
|
||||
@@ -82,7 +82,7 @@ fn init<'a>(args: &ArgMatches<'a>, conn: &Connection) {
|
||||
}
|
||||
};
|
||||
if can_do || force {
|
||||
let searcher = Searcher::create(&path).unwrap();
|
||||
let searcher = Searcher::create(&path, &CONFIG.search_tokenizers).unwrap();
|
||||
refill(args, conn, Some(searcher));
|
||||
} else {
|
||||
eprintln!(
|
||||
@@ -98,7 +98,8 @@ fn refill<'a>(args: &ArgMatches<'a>, conn: &Connection, searcher: Option<Searche
|
||||
Some(path) => Path::new(path).join("search_index"),
|
||||
None => Path::new(&CONFIG.search_index).to_path_buf(),
|
||||
};
|
||||
let searcher = searcher.unwrap_or_else(|| Searcher::open(&path).unwrap());
|
||||
let searcher =
|
||||
searcher.unwrap_or_else(|| Searcher::open(&path, &CONFIG.search_tokenizers).unwrap());
|
||||
|
||||
searcher.fill(conn).expect("Couldn't import post");
|
||||
println!("Commiting result");
|
||||
|
||||
@@ -6,22 +6,22 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
activitypub = "0.1.1"
|
||||
activitystreams-derive = "0.2"
|
||||
activitystreams-derive = "0.1.1"
|
||||
activitystreams-traits = "0.1.0"
|
||||
array_tool = "1.0"
|
||||
base64 = "0.10"
|
||||
futures-util = "*"
|
||||
heck = "0.3.0"
|
||||
hex = "0.3"
|
||||
hyper = "0.13"
|
||||
hyper = "0.12.33"
|
||||
openssl = "0.10.22"
|
||||
rocket = { git = "https://github.com/SergioBenitez/Rocket", rev = "async" }
|
||||
rocket = "0.4.0"
|
||||
reqwest = "0.9"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
shrinkwraprs = "0.2.1"
|
||||
syntect = "3.3"
|
||||
tokio = "0.2"
|
||||
tokio = "0.1.22"
|
||||
regex-syntax = { version = "0.6.17", default-features = false, features = ["unicode-perl"] }
|
||||
|
||||
[dependencies.chrono]
|
||||
@@ -31,7 +31,3 @@ version = "0.4"
|
||||
[dependencies.pulldown-cmark]
|
||||
default-features = false
|
||||
version = "0.2.0"
|
||||
|
||||
[dependencies.reqwest]
|
||||
features = ["json", "blocking"]
|
||||
version = "0.10"
|
||||
|
||||
@@ -279,9 +279,8 @@ pub trait FromId<C>: Sized {
|
||||
|
||||
/// Dereferences an ID
|
||||
fn deref(id: &str) -> Result<Self::Object, (Option<serde_json::Value>, Self::Error)> {
|
||||
// Use blocking reqwest API here, since defer cannot be async (yet)
|
||||
reqwest::blocking::Client::builder()
|
||||
.connect_timeout(std::time::Duration::from_secs(5))
|
||||
reqwest::ClientBuilder::new()
|
||||
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
||||
.build()
|
||||
.map_err(|_| (None, InboxError::DerefError.into()))?
|
||||
.get(id)
|
||||
@@ -297,7 +296,7 @@ pub trait FromId<C>: Sized {
|
||||
)
|
||||
.send()
|
||||
.map_err(|_| (None, InboxError::DerefError))
|
||||
.and_then(|r| {
|
||||
.and_then(|mut r| {
|
||||
let json: serde_json::Value = r
|
||||
.json()
|
||||
.map_err(|_| (None, InboxError::InvalidObject(None)))?;
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
use activitypub::{Activity, Link, Object};
|
||||
use array_tool::vec::Uniq;
|
||||
use reqwest::ClientBuilder;
|
||||
use reqwest::r#async::ClientBuilder;
|
||||
use rocket::{
|
||||
http::Status,
|
||||
request::{FromRequest, Request},
|
||||
response::{Responder, Response, Result},
|
||||
response::{Responder, Response},
|
||||
Outcome,
|
||||
};
|
||||
use serde_json;
|
||||
use tokio::prelude::*;
|
||||
|
||||
use self::sign::Signable;
|
||||
|
||||
@@ -60,45 +62,39 @@ impl<T> ActivityStream<T> {
|
||||
ActivityStream(t)
|
||||
}
|
||||
}
|
||||
#[rocket::async_trait]
|
||||
impl<'r, O: Object + Send + 'r> Responder<'r> for ActivityStream<O> {
|
||||
async fn respond_to(self, request: &'r Request<'_>) -> Result<'r> {
|
||||
|
||||
impl<'r, O: Object> Responder<'r> for ActivityStream<O> {
|
||||
fn respond_to(self, request: &Request<'_>) -> Result<Response<'r>, Status> {
|
||||
let mut json = serde_json::to_value(&self.0).map_err(|_| Status::InternalServerError)?;
|
||||
json["@context"] = context();
|
||||
let result = serde_json::to_string(&json).map_err(rocket::response::Debug);
|
||||
match result.respond_to(request).await {
|
||||
Ok(r) => Response::build_from(r)
|
||||
serde_json::to_string(&json).respond_to(request).map(|r| {
|
||||
Response::build_from(r)
|
||||
.raw_header("Content-Type", "application/activity+json")
|
||||
.ok(),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
.finalize()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ApRequest;
|
||||
#[rocket::async_trait]
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for ApRequest {
|
||||
type Error = ();
|
||||
|
||||
async fn from_request(request: &'a Request<'r>) -> Outcome<Self, (Status, Self::Error), ()> {
|
||||
fn from_request(request: &'a Request<'r>) -> Outcome<Self, (Status, Self::Error), ()> {
|
||||
request
|
||||
.headers()
|
||||
.get_one("Accept")
|
||||
.map(|header| {
|
||||
header
|
||||
.split(',')
|
||||
.map(|ct| {
|
||||
match ct.trim() {
|
||||
// bool for Forward: true if found a valid Content-Type for Plume first (HTML),
|
||||
// false otherwise
|
||||
.map(|ct| match ct.trim() {
|
||||
// bool for Forward: true if found a valid Content-Type for Plume first (HTML), false otherwise
|
||||
"application/ld+json; profile=\"https://w3.org/ns/activitystreams\""
|
||||
| "application/ld+json;profile=\"https://w3.org/ns/activitystreams\""
|
||||
| "application/activity+json"
|
||||
| "application/ld+json" => Outcome::Success(ApRequest),
|
||||
"text/html" => Outcome::Forward(true),
|
||||
_ => Outcome::Forward(false),
|
||||
}
|
||||
})
|
||||
.fold(Outcome::Forward(false), |out, ct| {
|
||||
if out.clone().forwarded().unwrap_or_else(|| out.is_success()) {
|
||||
@@ -134,38 +130,36 @@ where
|
||||
.sign(sender)
|
||||
.expect("activity_pub::broadcast: signature error");
|
||||
|
||||
let rt = tokio::runtime::Builder::new()
|
||||
.threaded_scheduler()
|
||||
.build()
|
||||
let mut rt = tokio::runtime::current_thread::Runtime::new()
|
||||
.expect("Error while initializing tokio runtime for federation");
|
||||
for inbox in boxes {
|
||||
let body = signed.to_string();
|
||||
let mut headers = request::headers();
|
||||
headers.insert("Digest", request::Digest::digest(&body));
|
||||
let sig = request::signature(sender, &headers)
|
||||
.expect("activity_pub::broadcast: request signature error");
|
||||
let client = ClientBuilder::new()
|
||||
.connect_timeout(std::time::Duration::from_secs(5))
|
||||
.build()
|
||||
.expect("Can't build client");
|
||||
rt.spawn(async move {
|
||||
for inbox in boxes {
|
||||
let body = signed.to_string();
|
||||
let mut headers = request::headers();
|
||||
headers.insert("Digest", request::Digest::digest(&body));
|
||||
rt.spawn(
|
||||
client
|
||||
.post(&inbox)
|
||||
.headers(headers.clone())
|
||||
.header("Signature", sig)
|
||||
.header(
|
||||
"Signature",
|
||||
request::signature(sender, &headers)
|
||||
.expect("activity_pub::broadcast: request signature error"),
|
||||
)
|
||||
.body(body)
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
.text()
|
||||
.await
|
||||
.and_then(|r| r.into_body().concat2())
|
||||
.map(move |response| {
|
||||
println!("Successfully sent activity to inbox ({})", inbox);
|
||||
println!("Response: \"{:?}\"\n", response)
|
||||
})
|
||||
.map_err(|e| println!("Error while sending to inbox ({:?})", e))
|
||||
});
|
||||
.map_err(|e| println!("Error while sending to inbox ({:?})", e)),
|
||||
);
|
||||
}
|
||||
rt.run().unwrap();
|
||||
}
|
||||
|
||||
#[derive(Shrinkwrap, Clone, Serialize, Deserialize)]
|
||||
@@ -209,7 +203,8 @@ pub struct PublicKey {
|
||||
pub public_key_pem: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Default, UnitString)]
|
||||
#[activitystreams(Hashtag)]
|
||||
pub struct HashtagType;
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use base64;
|
||||
use chrono::{offset::Utc, DateTime};
|
||||
use openssl::hash::{Hasher, MessageDigest};
|
||||
use reqwest::header::{HeaderMap, HeaderValue, ACCEPT, CONTENT_TYPE, DATE, USER_AGENT};
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
use super::request;
|
||||
use base64;
|
||||
use chrono::{naive::NaiveDateTime, DateTime, Duration, Utc};
|
||||
use hex;
|
||||
use openssl::{pkey::PKey, rsa::Rsa, sha::sha256};
|
||||
use rocket::http::HeaderMap;
|
||||
use serde_json;
|
||||
|
||||
/// Returns (public key, private key)
|
||||
pub fn gen_keypair() -> (Vec<u8>, Vec<u8>) {
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
#[macro_use]
|
||||
extern crate activitystreams_derive;
|
||||
use activitystreams_traits;
|
||||
|
||||
use serde;
|
||||
#[macro_use]
|
||||
extern crate shrinkwraprs;
|
||||
#[macro_use]
|
||||
|
||||
@@ -442,6 +442,7 @@ mod tests {
|
||||
("not_a#hashtag", vec![]),
|
||||
("#نرمافزار_آزاد", vec!["نرمافزار_آزاد"]),
|
||||
("[#hash in link](https://example.org/)", vec![]),
|
||||
("#zwsp\u{200b}inhash", vec!["zwsp"]),
|
||||
];
|
||||
|
||||
for (md, mentions) in tests {
|
||||
|
||||
@@ -19,6 +19,7 @@ init_i18n!(
|
||||
en,
|
||||
eo,
|
||||
es,
|
||||
fa,
|
||||
fr,
|
||||
gl,
|
||||
hi,
|
||||
|
||||
+9
-18
@@ -10,26 +10,27 @@ ammonia = "2.1.1"
|
||||
askama_escape = "0.1"
|
||||
bcrypt = "0.5"
|
||||
guid-create = "0.1"
|
||||
futures = "0.3"
|
||||
heck = "0.3.0"
|
||||
itertools = "0.8.0"
|
||||
lazy_static = "1.0"
|
||||
migrations_internals= "1.4.0"
|
||||
openssl = "0.10.22"
|
||||
rocket = { git = "https://github.com/SergioBenitez/Rocket", rev = "async" }
|
||||
rocket = "0.4.0"
|
||||
rocket_i18n = { git = "https://github.com/Plume-org/rocket_i18n", rev = "e922afa7c366038b3433278c03b1456b346074f2" }
|
||||
reqwest = "0.9"
|
||||
scheduled-thread-pool = "0.2.2"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
tantivy = "0.10.1"
|
||||
tokio = "0.2"
|
||||
tantivy = "0.12.0"
|
||||
url = "2.1"
|
||||
walkdir = "2.2"
|
||||
webfinger = { git = "https://github.com/Plume-org/webfinger", rev = "4e8f12810c4a7ba7a07bbcb722cd265fdff512b6", features = ["async"] }
|
||||
webfinger = "0.4.1"
|
||||
whatlang = "0.7.1"
|
||||
shrinkwraprs = "0.3"
|
||||
shrinkwraprs = "0.2.1"
|
||||
diesel-derive-newtype = "0.1.2"
|
||||
glob = "0.3.0"
|
||||
lindera-tantivy = { version = "0.1.2", optional = true }
|
||||
|
||||
[dependencies.chrono]
|
||||
features = ["serde"]
|
||||
@@ -48,20 +49,10 @@ path = "../plume-common"
|
||||
[dependencies.plume-macro]
|
||||
path = "../plume-macro"
|
||||
|
||||
[dependencies.reqwest]
|
||||
features = ["json", "blocking"]
|
||||
version = "0.10"
|
||||
|
||||
|
||||
[dependencies.rocket_i18n]
|
||||
git = "https://github.com/Plume-org/rocket_i18n"
|
||||
branch = "go-async"
|
||||
default-features = false
|
||||
features = ["rocket"]
|
||||
|
||||
[dev-dependencies]
|
||||
diesel_migrations = "1.4.0"
|
||||
diesel_migrations = "1.3.0"
|
||||
|
||||
[features]
|
||||
postgres = ["diesel/postgres", "plume-macro/postgres" ]
|
||||
sqlite = ["diesel/sqlite", "plume-macro/sqlite" ]
|
||||
search-lindera = ["lindera-tantivy"]
|
||||
|
||||
@@ -8,12 +8,11 @@ use rocket::{
|
||||
/// Wrapper around User to use as a request guard on pages reserved to admins.
|
||||
pub struct Admin(pub User);
|
||||
|
||||
#[rocket::async_trait]
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for Admin {
|
||||
type Error = ();
|
||||
|
||||
async fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
|
||||
let user = try_outcome!(User::from_request(request).await);
|
||||
fn from_request(request: &'a Request<'r>) -> request::Outcome<Admin, ()> {
|
||||
let user = request.guard::<User>()?;
|
||||
if user.is_admin() {
|
||||
Outcome::Success(Admin(user))
|
||||
} else {
|
||||
@@ -25,12 +24,11 @@ impl<'a, 'r> FromRequest<'a, 'r> for Admin {
|
||||
/// Same as `Admin` but for moderators.
|
||||
pub struct Moderator(pub User);
|
||||
|
||||
#[rocket::async_trait]
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for Moderator {
|
||||
type Error = ();
|
||||
|
||||
async fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
|
||||
let user = try_outcome!(User::from_request(request).await);
|
||||
fn from_request(request: &'a Request<'r>) -> request::Outcome<Moderator, ()> {
|
||||
let user = request.guard::<User>()?;
|
||||
if user.is_moderator() {
|
||||
Outcome::Success(Moderator(user))
|
||||
} else {
|
||||
|
||||
@@ -76,36 +76,32 @@ pub enum TokenError {
|
||||
DbError,
|
||||
}
|
||||
|
||||
#[rocket::async_trait]
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for ApiToken {
|
||||
type Error = TokenError;
|
||||
|
||||
async fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
|
||||
fn from_request(request: &'a Request<'r>) -> request::Outcome<ApiToken, TokenError> {
|
||||
let headers: Vec<_> = request.headers().get("Authorization").collect();
|
||||
if headers.len() != 1 {
|
||||
return Outcome::Failure((Status::BadRequest, TokenError::NoHeader));
|
||||
}
|
||||
|
||||
let mut parsed_header = headers[0].split(' ');
|
||||
if let Some(auth_type) = parsed_header.next() {
|
||||
if let Some(val) = parsed_header.next() {
|
||||
let auth_type = parsed_header.next().map_or_else(
|
||||
|| Outcome::Failure((Status::BadRequest, TokenError::NoType)),
|
||||
Outcome::Success,
|
||||
)?;
|
||||
let val = parsed_header.next().map_or_else(
|
||||
|| Outcome::Failure((Status::BadRequest, TokenError::NoValue)),
|
||||
Outcome::Success,
|
||||
)?;
|
||||
|
||||
if auth_type == "Bearer" {
|
||||
if let Outcome::Success(conn) = DbConn::from_request(request).await {
|
||||
let conn = request
|
||||
.guard::<DbConn>()
|
||||
.map_failure(|_| (Status::InternalServerError, TokenError::DbError))?;
|
||||
if let Ok(token) = ApiToken::find_by_value(&*conn, val) {
|
||||
return Outcome::Success(token);
|
||||
}
|
||||
} else {
|
||||
return Outcome::Failure((
|
||||
Status::InternalServerError,
|
||||
TokenError::DbError,
|
||||
));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Outcome::Failure((Status::BadRequest, TokenError::NoValue));
|
||||
}
|
||||
} else {
|
||||
return Outcome::Failure((Status::BadRequest, TokenError::NoType));
|
||||
}
|
||||
|
||||
Outcome::Forward(())
|
||||
|
||||
@@ -20,6 +20,7 @@ use plume_common::activity_pub::{
|
||||
inbox::{AsActor, FromId},
|
||||
sign, ActivityStream, ApSignature, Id, IntoId, PublicKey, Source,
|
||||
};
|
||||
use serde_json;
|
||||
use url::Url;
|
||||
use webfinger::*;
|
||||
|
||||
@@ -70,8 +71,7 @@ impl Blog {
|
||||
insert!(blogs, NewBlog, |inserted, conn| {
|
||||
let instance = inserted.get_instance(conn)?;
|
||||
if inserted.outbox_url.is_empty() {
|
||||
inserted.outbox_url =
|
||||
instance.compute_box(BLOG_PREFIX, &inserted.actor_id, r#"outbox"#);
|
||||
inserted.outbox_url = instance.compute_box(BLOG_PREFIX, &inserted.actor_id, "outbox");
|
||||
}
|
||||
|
||||
if inserted.inbox_url.is_empty() {
|
||||
@@ -132,7 +132,7 @@ impl Blog {
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
pub async fn find_by_fqn(c: &PlumeRocket, fqn: &str) -> Result<Blog> {
|
||||
pub fn find_by_fqn(c: &PlumeRocket, fqn: &str) -> Result<Blog> {
|
||||
let from_db = blogs::table
|
||||
.filter(blogs::fqn.eq(fqn))
|
||||
.first(&*c.conn)
|
||||
@@ -140,13 +140,12 @@ impl Blog {
|
||||
if let Some(from_db) = from_db {
|
||||
Ok(from_db)
|
||||
} else {
|
||||
Blog::fetch_from_webfinger(c, fqn).await
|
||||
Blog::fetch_from_webfinger(c, fqn)
|
||||
}
|
||||
}
|
||||
|
||||
async fn fetch_from_webfinger(c: &PlumeRocket, acct: &str) -> Result<Blog> {
|
||||
resolve_with_prefix(Prefix::Group, acct.to_owned(), true)
|
||||
.await?
|
||||
fn fetch_from_webfinger(c: &PlumeRocket, acct: &str) -> Result<Blog> {
|
||||
resolve_with_prefix(Prefix::Group, acct.to_owned(), true)?
|
||||
.links
|
||||
.into_iter()
|
||||
.find(|l| l.mime_type == Some(String::from("application/activity+json")))
|
||||
@@ -499,6 +498,7 @@ pub(crate) mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
blog_authors::*,
|
||||
config::CONFIG,
|
||||
instance::tests as instance_tests,
|
||||
medias::NewMedia,
|
||||
search::tests::get_searcher,
|
||||
@@ -768,7 +768,9 @@ pub(crate) mod tests {
|
||||
conn.test_transaction::<_, (), _>(|| {
|
||||
let (_, blogs) = fill_database(conn);
|
||||
|
||||
blogs[0].delete(conn, &get_searcher()).unwrap();
|
||||
blogs[0]
|
||||
.delete(conn, &get_searcher(&CONFIG.search_tokenizers))
|
||||
.unwrap();
|
||||
assert!(Blog::get(conn, blogs[0].id).is_err());
|
||||
Ok(())
|
||||
})
|
||||
@@ -778,7 +780,7 @@ pub(crate) mod tests {
|
||||
fn delete_via_user() {
|
||||
let conn = &db();
|
||||
conn.test_transaction::<_, (), _>(|| {
|
||||
let searcher = get_searcher();
|
||||
let searcher = get_searcher(&CONFIG.search_tokenizers);
|
||||
let (user, _) = fill_database(conn);
|
||||
|
||||
let b1 = Blog::insert(
|
||||
|
||||
@@ -17,7 +17,6 @@ use activitypub::{
|
||||
};
|
||||
use chrono::{self, NaiveDateTime};
|
||||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl};
|
||||
use futures::stream::{self, StreamExt};
|
||||
use plume_common::{
|
||||
activity_pub::{
|
||||
inbox::{AsActor, AsObject, FromId},
|
||||
@@ -25,6 +24,7 @@ use plume_common::{
|
||||
},
|
||||
utils,
|
||||
};
|
||||
use serde_json;
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[derive(Queryable, Identifiable, Clone, AsChangeset)]
|
||||
@@ -105,7 +105,7 @@ impl Comment {
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub async fn to_activity(&self, c: &PlumeRocket) -> Result<Note> {
|
||||
pub fn to_activity(&self, c: &PlumeRocket) -> Result<Note> {
|
||||
let author = User::get(&c.conn, self.author_id)?;
|
||||
let (html, mentions, _hashtags) = utils::md_to_html(
|
||||
self.content.get().as_ref(),
|
||||
@@ -132,18 +132,18 @@ impl Comment {
|
||||
note.object_props.set_attributed_to_link(author.into_id())?;
|
||||
note.object_props.set_to_link_vec(to)?;
|
||||
note.object_props.set_tag_link_vec(
|
||||
stream::iter(mentions)
|
||||
.filter_map(|m| async move { Mention::build_activity(c, &m).await.ok() })
|
||||
.collect::<Vec<link::Mention>>()
|
||||
.await,
|
||||
mentions
|
||||
.into_iter()
|
||||
.filter_map(|m| Mention::build_activity(c, &m).ok())
|
||||
.collect::<Vec<link::Mention>>(),
|
||||
)?;
|
||||
Ok(note)
|
||||
}
|
||||
|
||||
pub async fn create_activity(&self, c: &PlumeRocket) -> Result<Create> {
|
||||
pub fn create_activity(&self, c: &PlumeRocket) -> Result<Create> {
|
||||
let author = User::get(&c.conn, self.author_id)?;
|
||||
|
||||
let note = self.to_activity(c).await?;
|
||||
let note = self.to_activity(c)?;
|
||||
let mut act = Create::default();
|
||||
act.create_props.set_actor_link(author.into_id())?;
|
||||
act.create_props.set_object_object(note.clone())?;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::search::TokenizerKind as SearchTokenizer;
|
||||
use rocket::config::Limits;
|
||||
use rocket::Config as RocketConfig;
|
||||
use std::env::{self, var};
|
||||
@@ -14,6 +15,7 @@ pub struct Config {
|
||||
pub db_max_size: Option<u32>,
|
||||
pub db_min_idle: Option<u32>,
|
||||
pub search_index: String,
|
||||
pub search_tokenizers: SearchTokenizerConfig,
|
||||
pub rocket: Result<RocketConfig, RocketError>,
|
||||
pub logo: LogoConfig,
|
||||
pub default_theme: String,
|
||||
@@ -188,6 +190,56 @@ 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! {
|
||||
pub static ref CONFIG: Config = Config {
|
||||
base_url: var("BASE_URL").unwrap_or_else(|_| format!(
|
||||
@@ -209,6 +261,7 @@ lazy_static! {
|
||||
#[cfg(feature = "sqlite")]
|
||||
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_tokenizers: SearchTokenizerConfig::init(),
|
||||
rocket: get_rocket_config(),
|
||||
logo: LogoConfig::default(),
|
||||
default_theme: var("DEFAULT_THEME").unwrap_or_else(|_| "default-light".to_owned()),
|
||||
|
||||
@@ -7,7 +7,7 @@ use diesel::{dsl::sql_query, ConnectionError, RunQueryDsl};
|
||||
use rocket::{
|
||||
http::Status,
|
||||
request::{self, FromRequest},
|
||||
Outcome, Request,
|
||||
Outcome, Request, State,
|
||||
};
|
||||
use std::ops::Deref;
|
||||
|
||||
@@ -21,14 +21,14 @@ pub struct DbConn(pub PooledConnection<ConnectionManager<Connection>>);
|
||||
/// Attempts to retrieve a single connection from the managed database pool. If
|
||||
/// no pool is currently managed, fails with an `InternalServerError` status. If
|
||||
/// no connections are available, fails with a `ServiceUnavailable` status.
|
||||
#[rocket::async_trait]
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for DbConn {
|
||||
type Error = ();
|
||||
|
||||
async fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
|
||||
match DbConn::from_request(request).await {
|
||||
Outcome::Success(a) => Outcome::Success(a),
|
||||
_ => Outcome::Failure((Status::ServiceUnavailable, ())),
|
||||
fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
|
||||
let pool = request.guard::<State<'_, DbPool>>()?;
|
||||
match pool.get() {
|
||||
Ok(conn) => Outcome::Success(DbConn(conn)),
|
||||
Err(_) => Outcome::Failure((Status::ServiceUnavailable, ())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,10 @@ use rocket::{
|
||||
|
||||
pub struct Headers<'r>(pub HeaderMap<'r>);
|
||||
|
||||
#[rocket::async_trait]
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for Headers<'r> {
|
||||
type Error = ();
|
||||
|
||||
async fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, ()> {
|
||||
fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, ()> {
|
||||
let mut headers = HeaderMap::new();
|
||||
for header in request.headers().clone().into_iter() {
|
||||
headers.add(header);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use activitypub::activity::*;
|
||||
use serde_json;
|
||||
|
||||
use crate::{
|
||||
comments::Comment,
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#[macro_use]
|
||||
extern crate diesel;
|
||||
extern crate futures;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
#[macro_use]
|
||||
@@ -76,12 +75,6 @@ impl From<std::option::NoneError> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Error> for std::option::NoneError {
|
||||
fn from(_: Error) -> Self {
|
||||
std::option::NoneError
|
||||
}
|
||||
}
|
||||
|
||||
impl From<url::ParseError> for Error {
|
||||
fn from(_: url::ParseError) -> Self {
|
||||
Error::Url
|
||||
@@ -327,7 +320,7 @@ mod tests {
|
||||
pub fn rockets() -> super::PlumeRocket {
|
||||
super::PlumeRocket {
|
||||
conn: db_conn::DbConn((*DB_POOL).get().unwrap()),
|
||||
searcher: Arc::new(search::tests::get_searcher()),
|
||||
searcher: Arc::new(search::tests::get_searcher(&CONFIG.search_tokenizers)),
|
||||
worker: Arc::new(ScheduledThreadPool::new(2)),
|
||||
user: None,
|
||||
}
|
||||
|
||||
+14
-54
@@ -7,8 +7,8 @@ use crate::{
|
||||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
/// Represent what a list is supposed to store. Represented in database as an integer
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum ListType {
|
||||
User,
|
||||
Blog,
|
||||
@@ -58,11 +58,7 @@ struct NewList<'a> {
|
||||
}
|
||||
|
||||
macro_rules! func {
|
||||
(
|
||||
$(#[$outer:meta])*
|
||||
@elem User $id:expr, $value:expr
|
||||
) => {
|
||||
$(#[$outer])*
|
||||
(@elem User $id:expr, $value:expr) => {
|
||||
NewListElem {
|
||||
list_id: $id,
|
||||
user_id: Some(*$value),
|
||||
@@ -70,11 +66,7 @@ macro_rules! func {
|
||||
word: None,
|
||||
}
|
||||
};
|
||||
(
|
||||
$(#[$outer:meta])*
|
||||
@elem Blog $id:expr, $value:expr
|
||||
) => {
|
||||
$(#[$outer])*
|
||||
(@elem Blog $id:expr, $value:expr) => {
|
||||
NewListElem {
|
||||
list_id: $id,
|
||||
user_id: None,
|
||||
@@ -82,11 +74,7 @@ macro_rules! func {
|
||||
word: None,
|
||||
}
|
||||
};
|
||||
(
|
||||
$(#[$outer:meta])*
|
||||
@elem Word $id:expr, $value:expr
|
||||
) => {
|
||||
$(#[$outer])*
|
||||
(@elem Word $id:expr, $value:expr) => {
|
||||
NewListElem {
|
||||
list_id: $id,
|
||||
user_id: None,
|
||||
@@ -94,11 +82,7 @@ macro_rules! func {
|
||||
word: Some($value),
|
||||
}
|
||||
};
|
||||
(
|
||||
$(#[$outer:meta])*
|
||||
@elem Prefix $id:expr, $value:expr
|
||||
) => {
|
||||
$(#[$outer])*
|
||||
(@elem Prefix $id:expr, $value:expr) => {
|
||||
NewListElem {
|
||||
list_id: $id,
|
||||
user_id: None,
|
||||
@@ -115,11 +99,7 @@ macro_rules! func {
|
||||
(@out_type Word) => { String };
|
||||
(@out_type Prefix) => { String };
|
||||
|
||||
(
|
||||
$(#[$outer:meta])*
|
||||
add: $fn:ident, $kind:ident
|
||||
) => {
|
||||
$(#[$outer])*
|
||||
(add: $fn:ident, $kind:ident) => {
|
||||
pub fn $fn(&self, conn: &Connection, vals: &[func!(@in_type $kind)]) -> Result<()> {
|
||||
if self.kind() != ListType::$kind {
|
||||
return Err(Error::InvalidValue);
|
||||
@@ -136,11 +116,7 @@ macro_rules! func {
|
||||
}
|
||||
};
|
||||
|
||||
(
|
||||
$(#[$outer:meta])*
|
||||
list: $fn:ident, $kind:ident, $table:ident
|
||||
) => {
|
||||
$(#[$outer])*
|
||||
(list: $fn:ident, $kind:ident, $table:ident) => {
|
||||
pub fn $fn(&self, conn: &Connection) -> Result<Vec<func!(@out_type $kind)>> {
|
||||
if self.kind() != ListType::$kind {
|
||||
return Err(Error::InvalidValue);
|
||||
@@ -156,11 +132,7 @@ macro_rules! func {
|
||||
|
||||
|
||||
|
||||
(
|
||||
$(#[$outer:meta])*
|
||||
set: $fn:ident, $kind:ident, $add:ident
|
||||
) => {
|
||||
$(#[$outer])*
|
||||
(set: $fn:ident, $kind:ident, $add:ident) => {
|
||||
pub fn $fn(&self, conn: &Connection, val: &[func!(@in_type $kind)]) -> Result<()> {
|
||||
if self.kind() != ListType::$kind {
|
||||
return Err(Error::InvalidValue);
|
||||
@@ -274,35 +246,23 @@ impl List {
|
||||
private::ListElem::prefix_in_list(conn, self, word)
|
||||
}
|
||||
|
||||
func! {
|
||||
/// Insert new users in a list
|
||||
add: add_users, User
|
||||
}
|
||||
func! {add: add_users, User}
|
||||
|
||||
func! {
|
||||
/// Insert new blogs in a list
|
||||
add: add_blogs, Blog
|
||||
}
|
||||
func! {add: add_blogs, Blog}
|
||||
|
||||
func! {
|
||||
/// Insert new words in a list
|
||||
add: add_words, Word
|
||||
}
|
||||
func! {add: add_words, Word}
|
||||
|
||||
func! {
|
||||
/// Insert new prefixes in a list
|
||||
add: add_prefixes, Prefix
|
||||
}
|
||||
func! {add: add_prefixes, Prefix}
|
||||
|
||||
func! {
|
||||
/// Get all users in the list
|
||||
list: list_users, User, users
|
||||
}
|
||||
func! {list: list_users, User, users}
|
||||
|
||||
func! {
|
||||
/// Get all blogs in the list
|
||||
list: list_blogs, Blog, blogs
|
||||
}
|
||||
func! {list: list_blogs, Blog, blogs}
|
||||
|
||||
/// Get all words in the list
|
||||
pub fn list_words(&self, conn: &Connection) -> Result<Vec<String>> {
|
||||
|
||||
@@ -10,8 +10,8 @@ use plume_common::{
|
||||
activity_pub::{inbox::FromId, Id},
|
||||
utils::MediaProcessor,
|
||||
};
|
||||
use reqwest;
|
||||
use std::{fs, path::Path};
|
||||
use tokio::prelude::*;
|
||||
|
||||
#[derive(Clone, Identifiable, Queryable)]
|
||||
pub struct Media {
|
||||
@@ -197,7 +197,7 @@ impl Media {
|
||||
}
|
||||
|
||||
// TODO: merge with save_remote?
|
||||
pub async fn from_activity(c: &PlumeRocket, image: &Image) -> Result<Media> {
|
||||
pub fn from_activity(c: &PlumeRocket, image: &Image) -> Result<Media> {
|
||||
let conn = &*c.conn;
|
||||
let remote_url = image.object_props.url_string().ok()?;
|
||||
let ext = remote_url
|
||||
@@ -211,9 +211,11 @@ impl Media {
|
||||
ext
|
||||
));
|
||||
|
||||
let mut dest = tokio::fs::File::create(path.clone()).await?;
|
||||
let contents = reqwest::get(remote_url.as_str()).await?.bytes().await?;
|
||||
dest.write_all(&contents).await?;
|
||||
let mut dest = fs::File::create(path.clone()).ok()?;
|
||||
reqwest::get(remote_url.as_str())
|
||||
.ok()?
|
||||
.copy_to(&mut dest)
|
||||
.ok()?;
|
||||
|
||||
Media::insert(
|
||||
conn,
|
||||
|
||||
@@ -52,8 +52,8 @@ impl Mention {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn build_activity(c: &PlumeRocket, ment: &str) -> Result<link::Mention> {
|
||||
let user = User::find_by_fqn(c, ment).await?;
|
||||
pub fn build_activity(c: &PlumeRocket, ment: &str) -> Result<link::Mention> {
|
||||
let user = User::find_by_fqn(c, ment)?;
|
||||
let mut mention = link::Mention::default();
|
||||
mention.link_props.set_href_string(user.ap_url)?;
|
||||
mention.link_props.set_name_string(format!("@{}", ment))?;
|
||||
|
||||
@@ -20,35 +20,20 @@ mod module {
|
||||
pub flash_msg: Option<(String, String)>,
|
||||
}
|
||||
|
||||
#[rocket::async_trait]
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for PlumeRocket {
|
||||
type Error = ();
|
||||
|
||||
async fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
|
||||
let conn = DbConn::from_request(request).await.succeeded().unwrap();
|
||||
let intl = rocket_i18n::I18n::from_request(request)
|
||||
.await
|
||||
.succeeded()
|
||||
.unwrap();
|
||||
let user = users::User::from_request(request)
|
||||
.await
|
||||
.succeeded()
|
||||
.unwrap();
|
||||
let worker = request
|
||||
.guard::<State<'_, Arc<ScheduledThreadPool>>>()
|
||||
.await
|
||||
.succeeded()
|
||||
.unwrap();
|
||||
let searcher = request
|
||||
.guard::<State<'_, Arc<search::Searcher>>>()
|
||||
.await
|
||||
.succeeded()
|
||||
.unwrap();
|
||||
let flash_msg = request.guard::<FlashMessage<'_, '_>>().await.succeeded();
|
||||
fn from_request(request: &'a Request<'r>) -> request::Outcome<PlumeRocket, ()> {
|
||||
let conn = request.guard::<DbConn>()?;
|
||||
let intl = request.guard::<rocket_i18n::I18n>()?;
|
||||
let user = request.guard::<users::User>().succeeded();
|
||||
let worker = request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>()?;
|
||||
let searcher = request.guard::<'_, State<'_, Arc<search::Searcher>>>()?;
|
||||
let flash_msg = request.guard::<FlashMessage<'_, '_>>().succeeded();
|
||||
Outcome::Success(PlumeRocket {
|
||||
conn,
|
||||
intl,
|
||||
user: Some(user),
|
||||
user,
|
||||
flash_msg: flash_msg.map(|f| (f.name().into(), f.msg().into())),
|
||||
worker: worker.clone(),
|
||||
searcher: searcher.clone(),
|
||||
@@ -75,18 +60,17 @@ mod module {
|
||||
pub worker: Arc<ScheduledThreadPool>,
|
||||
}
|
||||
|
||||
#[rocket::async_trait]
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for PlumeRocket {
|
||||
type Error = ();
|
||||
|
||||
async fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
|
||||
let conn = try_outcome!(DbConn::from_request(request).await);
|
||||
let user = try_outcome!(users::User::from_request(request).await);
|
||||
let worker = try_outcome!(request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>());
|
||||
let searcher = try_outcome!(request.guard::<'_, State<'_, Arc<search::Searcher>>>());
|
||||
fn from_request(request: &'a Request<'r>) -> request::Outcome<PlumeRocket, ()> {
|
||||
let conn = request.guard::<DbConn>()?;
|
||||
let user = request.guard::<users::User>().succeeded();
|
||||
let worker = request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>()?;
|
||||
let searcher = request.guard::<'_, State<'_, Arc<search::Searcher>>>()?;
|
||||
Outcome::Success(PlumeRocket {
|
||||
conn,
|
||||
user: Some(user),
|
||||
user,
|
||||
worker: worker.clone(),
|
||||
searcher: searcher.clone(),
|
||||
})
|
||||
|
||||
+12
-17
@@ -19,8 +19,8 @@ use plume_common::{
|
||||
},
|
||||
utils::md_to_html,
|
||||
};
|
||||
use serde_json;
|
||||
use std::collections::HashSet;
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
pub type LicensedArticle = CustomObject<Licensed, Article>;
|
||||
|
||||
@@ -579,11 +579,11 @@ impl FromId<PlumeRocket> for Post {
|
||||
}
|
||||
});
|
||||
|
||||
let image = article.object_props.icon_object::<Image>().ok().unwrap();
|
||||
|
||||
let mut r = Runtime::new().unwrap();
|
||||
let cover =
|
||||
Some(r.block_on(async { Media::from_activity(&c, &image).await.ok().unwrap().id }));
|
||||
let cover = article
|
||||
.object_props
|
||||
.icon_object::<Image>()
|
||||
.ok()
|
||||
.and_then(|img| Media::from_activity(&c, &img).ok().map(|m| m.id));
|
||||
|
||||
let title = article.object_props.name_string()?;
|
||||
let post = Post::insert(
|
||||
@@ -699,22 +699,17 @@ impl FromId<PlumeRocket> for PostUpdate {
|
||||
}
|
||||
|
||||
fn from_activity(c: &PlumeRocket, updated: LicensedArticle) -> Result<Self> {
|
||||
let image = updated
|
||||
.object
|
||||
.object_props
|
||||
.icon_object::<Image>()
|
||||
.ok()
|
||||
.unwrap();
|
||||
let mut r = Runtime::new().unwrap();
|
||||
let cover =
|
||||
Some(r.block_on(async { Media::from_activity(&c, &image).await.ok().unwrap().id }));
|
||||
|
||||
Ok(PostUpdate {
|
||||
ap_url: updated.object.object_props.id_string()?,
|
||||
title: updated.object.object_props.name_string().ok(),
|
||||
subtitle: updated.object.object_props.summary_string().ok(),
|
||||
content: updated.object.object_props.content_string().ok(),
|
||||
cover,
|
||||
cover: updated
|
||||
.object
|
||||
.object_props
|
||||
.icon_object::<Image>()
|
||||
.ok()
|
||||
.and_then(|img| Media::from_activity(&c, &img).ok().map(|m| m.id)),
|
||||
source: updated
|
||||
.object
|
||||
.ap_object_props
|
||||
|
||||
@@ -3,10 +3,11 @@ mod searcher;
|
||||
mod tokenizer;
|
||||
pub use self::query::PlumeQuery as Query;
|
||||
pub use self::searcher::*;
|
||||
pub use self::tokenizer::TokenizerKind;
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod tests {
|
||||
use super::{Query, Searcher};
|
||||
use super::{Query, Searcher, TokenizerKind};
|
||||
use diesel::Connection;
|
||||
use plume_common::utils::random_hex;
|
||||
use std::env::temp_dir;
|
||||
@@ -14,18 +15,20 @@ pub(crate) mod tests {
|
||||
|
||||
use crate::{
|
||||
blogs::tests::fill_database,
|
||||
config::SearchTokenizerConfig,
|
||||
post_authors::*,
|
||||
posts::{NewPost, Post},
|
||||
safe_string::SafeString,
|
||||
tests::db,
|
||||
CONFIG,
|
||||
};
|
||||
|
||||
pub(crate) fn get_searcher() -> Searcher {
|
||||
pub(crate) fn get_searcher(tokenizers: &SearchTokenizerConfig) -> Searcher {
|
||||
let dir = temp_dir().join(&format!("plume-test-{}", random_hex()));
|
||||
if dir.exists() {
|
||||
Searcher::open(&dir)
|
||||
Searcher::open(&dir, tokenizers)
|
||||
} else {
|
||||
Searcher::create(&dir)
|
||||
Searcher::create(&dir, tokenizers)
|
||||
}
|
||||
.unwrap()
|
||||
}
|
||||
@@ -100,27 +103,27 @@ pub(crate) mod tests {
|
||||
fn open() {
|
||||
let dir = temp_dir().join(format!("plume-test-{}", random_hex()));
|
||||
{
|
||||
Searcher::create(&dir).unwrap();
|
||||
Searcher::create(&dir, &CONFIG.search_tokenizers).unwrap();
|
||||
}
|
||||
Searcher::open(&dir).unwrap();
|
||||
Searcher::open(&dir, &CONFIG.search_tokenizers).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create() {
|
||||
let dir = temp_dir().join(format!("plume-test-{}", random_hex()));
|
||||
|
||||
assert!(Searcher::open(&dir).is_err());
|
||||
assert!(Searcher::open(&dir, &CONFIG.search_tokenizers).is_err());
|
||||
{
|
||||
Searcher::create(&dir).unwrap();
|
||||
Searcher::create(&dir, &CONFIG.search_tokenizers).unwrap();
|
||||
}
|
||||
Searcher::open(&dir).unwrap(); //verify it's well created
|
||||
Searcher::open(&dir, &CONFIG.search_tokenizers).unwrap(); //verify it's well created
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn search() {
|
||||
let conn = &db();
|
||||
conn.test_transaction::<_, (), _>(|| {
|
||||
let searcher = get_searcher();
|
||||
let searcher = get_searcher(&CONFIG.search_tokenizers);
|
||||
let blog = &fill_database(conn).1[0];
|
||||
let author = &blog.list_authors(conn).unwrap()[0];
|
||||
|
||||
@@ -180,10 +183,69 @@ 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]
|
||||
fn drop_writer() {
|
||||
let searcher = get_searcher();
|
||||
let searcher = get_searcher(&CONFIG.search_tokenizers);
|
||||
searcher.drop_writer();
|
||||
get_searcher();
|
||||
get_searcher(&CONFIG.search_tokenizers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
use crate::{
|
||||
instance::Instance,
|
||||
posts::Post,
|
||||
schema::posts,
|
||||
search::{query::PlumeQuery, tokenizer},
|
||||
tags::Tag,
|
||||
Connection, Result,
|
||||
config::SearchTokenizerConfig, instance::Instance, posts::Post, schema::posts,
|
||||
search::query::PlumeQuery, tags::Tag, Connection, Result,
|
||||
};
|
||||
use chrono::Datelike;
|
||||
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||
use itertools::Itertools;
|
||||
use std::{cmp, fs::create_dir_all, path::Path, sync::Mutex};
|
||||
use tantivy::{
|
||||
collector::TopDocs, directory::MmapDirectory, schema::*, tokenizer::*, Index, IndexReader,
|
||||
IndexWriter, ReloadPolicy, Term,
|
||||
collector::TopDocs, directory::MmapDirectory, schema::*, Index, IndexReader, IndexWriter,
|
||||
ReloadPolicy, Term,
|
||||
};
|
||||
use whatlang::{detect as detect_lang, Lang};
|
||||
|
||||
@@ -34,7 +30,7 @@ impl Searcher {
|
||||
pub fn schema() -> Schema {
|
||||
let tag_indexing = TextOptions::default().set_indexing_options(
|
||||
TextFieldIndexing::default()
|
||||
.set_tokenizer("whitespace_tokenizer")
|
||||
.set_tokenizer("tag_tokenizer")
|
||||
.set_index_option(IndexRecordOption::Basic),
|
||||
);
|
||||
|
||||
@@ -70,15 +66,7 @@ impl Searcher {
|
||||
schema_builder.build()
|
||||
}
|
||||
|
||||
pub fn create(path: &dyn 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);
|
||||
|
||||
pub fn create(path: &dyn AsRef<Path>, tokenizers: &SearchTokenizerConfig) -> Result<Self> {
|
||||
let schema = Self::schema();
|
||||
|
||||
create_dir_all(path).map_err(|_| SearcherError::IndexCreationError)?;
|
||||
@@ -90,9 +78,9 @@ impl Searcher {
|
||||
|
||||
{
|
||||
let tokenizer_manager = index.tokenizers();
|
||||
tokenizer_manager.register("whitespace_tokenizer", whitespace_tokenizer);
|
||||
tokenizer_manager.register("content_tokenizer", content_tokenizer);
|
||||
tokenizer_manager.register("property_tokenizer", property_tokenizer);
|
||||
tokenizer_manager.register("tag_tokenizer", tokenizers.tag_tokenizer);
|
||||
tokenizer_manager.register("content_tokenizer", tokenizers.content_tokenizer);
|
||||
tokenizer_manager.register("property_tokenizer", tokenizers.property_tokenizer);
|
||||
} //to please the borrow checker
|
||||
Ok(Self {
|
||||
writer: Mutex::new(Some(
|
||||
@@ -109,31 +97,38 @@ impl Searcher {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn open(path: &dyn 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 index =
|
||||
pub fn open(path: &dyn AsRef<Path>, tokenizers: &SearchTokenizerConfig) -> Result<Self> {
|
||||
let mut index =
|
||||
Index::open(MmapDirectory::open(path).map_err(|_| SearcherError::IndexOpeningError)?)
|
||||
.map_err(|_| SearcherError::IndexOpeningError)?;
|
||||
|
||||
{
|
||||
let tokenizer_manager = index.tokenizers();
|
||||
tokenizer_manager.register("whitespace_tokenizer", whitespace_tokenizer);
|
||||
tokenizer_manager.register("content_tokenizer", content_tokenizer);
|
||||
tokenizer_manager.register("property_tokenizer", property_tokenizer);
|
||||
tokenizer_manager.register("tag_tokenizer", tokenizers.tag_tokenizer);
|
||||
tokenizer_manager.register("content_tokenizer", tokenizers.content_tokenizer);
|
||||
tokenizer_manager.register("property_tokenizer", tokenizers.property_tokenizer);
|
||||
} //to please the borrow checker
|
||||
let mut writer = index
|
||||
let writer = index
|
||||
.writer(50_000_000)
|
||||
.map_err(|_| SearcherError::WriteLockAcquisitionError)?;
|
||||
writer
|
||||
.garbage_collect_files()
|
||||
|
||||
// Since Tantivy v0.12.0, IndexWriter::garbage_collect_files() returns Future.
|
||||
// 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)?;
|
||||
|
||||
Ok(Self {
|
||||
writer: Mutex::new(Some(writer)),
|
||||
reader: index
|
||||
|
||||
@@ -1,5 +1,34 @@
|
||||
#[cfg(feature = "search-lindera")]
|
||||
use lindera_tantivy::tokenizer::LinderaTokenizer;
|
||||
use std::str::CharIndices;
|
||||
use tantivy::tokenizer::{Token, TokenStream, Tokenizer};
|
||||
use tantivy::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,
|
||||
/// but not splitting on punctuation
|
||||
@@ -12,15 +41,13 @@ pub struct WhitespaceTokenStream<'a> {
|
||||
token: Token,
|
||||
}
|
||||
|
||||
impl<'a> Tokenizer<'a> for WhitespaceTokenizer {
|
||||
type TokenStreamImpl = WhitespaceTokenStream<'a>;
|
||||
|
||||
fn token_stream(&self, text: &'a str) -> Self::TokenStreamImpl {
|
||||
WhitespaceTokenStream {
|
||||
impl Tokenizer for WhitespaceTokenizer {
|
||||
fn token_stream<'a>(&self, text: &'a str) -> BoxTokenStream<'a> {
|
||||
BoxTokenStream::from(WhitespaceTokenStream {
|
||||
text,
|
||||
chars: text.char_indices(),
|
||||
token: Token::default(),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
impl<'a> WhitespaceTokenStream<'a> {
|
||||
|
||||
@@ -7,9 +7,7 @@ use crate::{
|
||||
users::User,
|
||||
PlumeRocket, Result,
|
||||
};
|
||||
use futures::stream::{self, StreamExt};
|
||||
use plume_common::activity_pub::inbox::AsActor;
|
||||
use tokio::runtime::Runtime;
|
||||
use whatlang::{self, Lang};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
@@ -297,33 +295,15 @@ impl WithList {
|
||||
}
|
||||
}
|
||||
List::Array(list) => match self {
|
||||
WithList::Blog => {
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
rt.block_on(async move {
|
||||
Ok(stream::iter(list)
|
||||
.filter_map(|b| async move {
|
||||
Some(Blog::find_by_fqn(rocket, b).await.ok().unwrap())
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.await
|
||||
.into_iter()
|
||||
.any(|b| b.id == post.blog_id))
|
||||
})
|
||||
}
|
||||
WithList::Blog => Ok(list
|
||||
.iter()
|
||||
.filter_map(|b| Blog::find_by_fqn(rocket, b).ok())
|
||||
.any(|b| b.id == post.blog_id)),
|
||||
WithList::Author { boosts, likes } => match kind {
|
||||
Kind::Original => {
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
rt.block_on(async move {
|
||||
Ok(stream::iter(list)
|
||||
.filter_map(|a| async move {
|
||||
Some(User::find_by_fqn(rocket, a).await.ok().unwrap())
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.await
|
||||
.into_iter()
|
||||
.any(|a| post.is_author(&rocket.conn, a.id).unwrap_or(false)))
|
||||
})
|
||||
}
|
||||
Kind::Original => Ok(list
|
||||
.iter()
|
||||
.filter_map(|a| User::find_by_fqn(rocket, a).ok())
|
||||
.any(|a| post.is_author(&rocket.conn, a.id).unwrap_or(false))),
|
||||
Kind::Reshare(u) => {
|
||||
if *boosts {
|
||||
Ok(list.iter().any(|user| &u.fqn == user))
|
||||
@@ -426,8 +406,8 @@ impl Bool {
|
||||
}
|
||||
}
|
||||
Bool::HasCover => Ok(post.cover_id.is_some()),
|
||||
Bool::Local => Ok(post.get_blog(&rocket.conn)?.is_local()),
|
||||
Bool::All => Ok(true),
|
||||
Bool::Local => Ok(post.get_blog(&rocket.conn)?.is_local() && kind == Kind::Original),
|
||||
Bool::All => Ok(kind == Kind::Original),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+40
-43
@@ -11,6 +11,7 @@ use activitypub::{
|
||||
object::{Image, Tombstone},
|
||||
Activity, CustomObject, Endpoint,
|
||||
};
|
||||
use bcrypt;
|
||||
use chrono::{NaiveDateTime, Utc};
|
||||
use diesel::{self, BelongingToDsl, ExpressionMethods, OptionalExtension, QueryDsl, RunQueryDsl};
|
||||
use openssl::{
|
||||
@@ -36,6 +37,7 @@ use rocket::{
|
||||
outcome::IntoOutcome,
|
||||
request::{self, FromRequest, Request},
|
||||
};
|
||||
use serde_json;
|
||||
use std::{
|
||||
cmp::PartialEq,
|
||||
hash::{Hash, Hasher},
|
||||
@@ -189,7 +191,7 @@ impl User {
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
pub async fn find_by_fqn(c: &PlumeRocket, fqn: &str) -> Result<User> {
|
||||
pub fn find_by_fqn(c: &PlumeRocket, fqn: &str) -> Result<User> {
|
||||
let from_db = users::table
|
||||
.filter(users::fqn.eq(fqn))
|
||||
.first(&*c.conn)
|
||||
@@ -197,13 +199,12 @@ impl User {
|
||||
if let Some(from_db) = from_db {
|
||||
Ok(from_db)
|
||||
} else {
|
||||
User::fetch_from_webfinger(c, fqn).await
|
||||
User::fetch_from_webfinger(c, fqn)
|
||||
}
|
||||
}
|
||||
|
||||
async fn fetch_from_webfinger(c: &PlumeRocket, acct: &str) -> Result<User> {
|
||||
let link = resolve(acct.to_owned(), true)
|
||||
.await?
|
||||
fn fetch_from_webfinger(c: &PlumeRocket, acct: &str) -> Result<User> {
|
||||
let link = resolve(acct.to_owned(), true)?
|
||||
.links
|
||||
.into_iter()
|
||||
.find(|l| l.mime_type == Some(String::from("application/activity+json")))
|
||||
@@ -211,9 +212,8 @@ impl User {
|
||||
User::from_id(c, link.href.as_ref()?, None).map_err(|(_, e)| e)
|
||||
}
|
||||
|
||||
pub async fn fetch_remote_interact_uri(acct: &str) -> Result<String> {
|
||||
resolve(acct.to_owned(), true)
|
||||
.await?
|
||||
pub fn fetch_remote_interact_uri(acct: &str) -> Result<String> {
|
||||
resolve(acct.to_owned(), true)?
|
||||
.links
|
||||
.into_iter()
|
||||
.find(|l| l.rel == "http://ostatus.org/schema/1.0/subscribe")
|
||||
@@ -221,9 +221,9 @@ impl User {
|
||||
.ok_or(Error::Webfinger)
|
||||
}
|
||||
|
||||
async fn fetch(url: &str) -> Result<CustomPerson> {
|
||||
let res = ClientBuilder::new()
|
||||
.connect_timeout(std::time::Duration::from_secs(5))
|
||||
fn fetch(url: &str) -> Result<CustomPerson> {
|
||||
let mut res = ClientBuilder::new()
|
||||
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
||||
.build()?
|
||||
.get(url)
|
||||
.header(
|
||||
@@ -235,9 +235,8 @@ impl User {
|
||||
.join(", "),
|
||||
)?,
|
||||
)
|
||||
.send()
|
||||
.await?;
|
||||
let text = &res.text().await?;
|
||||
.send()?;
|
||||
let text = &res.text()?;
|
||||
// without this workaround, publicKey is not correctly deserialized
|
||||
let ap_sign = serde_json::from_str::<ApSignature>(text)?;
|
||||
let mut json = serde_json::from_str::<CustomPerson>(text)?;
|
||||
@@ -245,13 +244,12 @@ impl User {
|
||||
Ok(json)
|
||||
}
|
||||
|
||||
pub async fn fetch_from_url(c: &PlumeRocket, url: &str) -> Result<User> {
|
||||
let json = User::fetch(url).await?;
|
||||
User::from_activity(c, json)
|
||||
pub fn fetch_from_url(c: &PlumeRocket, url: &str) -> Result<User> {
|
||||
User::fetch(url).and_then(|json| User::from_activity(c, json))
|
||||
}
|
||||
|
||||
pub async fn refetch(&self, conn: &Connection) -> Result<()> {
|
||||
let json = User::fetch(&self.ap_url.clone()).await?;
|
||||
pub fn refetch(&self, conn: &Connection) -> Result<()> {
|
||||
User::fetch(&self.ap_url.clone()).and_then(|json| {
|
||||
let avatar = Media::save_remote(
|
||||
conn,
|
||||
json.object
|
||||
@@ -287,6 +285,7 @@ impl User {
|
||||
.execute(conn)
|
||||
.map(|_| ())
|
||||
.map_err(Error::from)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn hash_pass(pass: &str) -> Result<String> {
|
||||
@@ -357,10 +356,9 @@ impl User {
|
||||
.set_part_of_link(Id::new(&self.outbox_url))?;
|
||||
Ok(ActivityStream::new(coll))
|
||||
}
|
||||
|
||||
async fn fetch_outbox_page<T: Activity>(&self, url: &str) -> Result<(Vec<T>, Option<String>)> {
|
||||
let res = ClientBuilder::new()
|
||||
.connect_timeout(std::time::Duration::from_secs(5))
|
||||
fn fetch_outbox_page<T: Activity>(&self, url: &str) -> Result<(Vec<T>, Option<String>)> {
|
||||
let mut res = ClientBuilder::new()
|
||||
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
||||
.build()?
|
||||
.get(url)
|
||||
.header(
|
||||
@@ -372,9 +370,8 @@ impl User {
|
||||
.join(", "),
|
||||
)?,
|
||||
)
|
||||
.send()
|
||||
.await?;
|
||||
let text = &res.text().await?;
|
||||
.send()?;
|
||||
let text = &res.text()?;
|
||||
let json: serde_json::Value = serde_json::from_str(text)?;
|
||||
let items = json["items"]
|
||||
.as_array()
|
||||
@@ -389,9 +386,9 @@ impl User {
|
||||
};
|
||||
Ok((items, next))
|
||||
}
|
||||
pub async fn fetch_outbox<T: Activity>(&self) -> Result<Vec<T>> {
|
||||
let res = ClientBuilder::new()
|
||||
.connect_timeout(std::time::Duration::from_secs(5))
|
||||
pub fn fetch_outbox<T: Activity>(&self) -> Result<Vec<T>> {
|
||||
let mut res = ClientBuilder::new()
|
||||
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
||||
.build()?
|
||||
.get(&self.outbox_url[..])
|
||||
.header(
|
||||
@@ -403,14 +400,13 @@ impl User {
|
||||
.join(", "),
|
||||
)?,
|
||||
)
|
||||
.send()
|
||||
.await?;
|
||||
let text = &res.text().await?;
|
||||
.send()?;
|
||||
let text = &res.text()?;
|
||||
let json: serde_json::Value = serde_json::from_str(text)?;
|
||||
if let Some(first) = json.get("first") {
|
||||
let mut items: Vec<T> = Vec::new();
|
||||
let mut next = first.as_str().unwrap().to_owned();
|
||||
while let Ok((mut page, nxt)) = self.fetch_outbox_page(&next).await {
|
||||
while let Ok((mut page, nxt)) = self.fetch_outbox_page(&next) {
|
||||
if page.is_empty() {
|
||||
break;
|
||||
}
|
||||
@@ -435,9 +431,9 @@ impl User {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn fetch_followers_ids(&self) -> Result<Vec<String>> {
|
||||
let res = ClientBuilder::new()
|
||||
.connect_timeout(std::time::Duration::from_secs(5))
|
||||
pub fn fetch_followers_ids(&self) -> Result<Vec<String>> {
|
||||
let mut res = ClientBuilder::new()
|
||||
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
||||
.build()?
|
||||
.get(&self.followers_endpoint[..])
|
||||
.header(
|
||||
@@ -449,9 +445,8 @@ impl User {
|
||||
.join(", "),
|
||||
)?,
|
||||
)
|
||||
.send()
|
||||
.await?;
|
||||
let text = &res.text().await?;
|
||||
.send()?;
|
||||
let text = &res.text()?;
|
||||
let json: serde_json::Value = serde_json::from_str(text)?;
|
||||
Ok(json["items"]
|
||||
.as_array()
|
||||
@@ -794,12 +789,11 @@ impl User {
|
||||
}
|
||||
}
|
||||
|
||||
#[rocket::async_trait]
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for User {
|
||||
type Error = ();
|
||||
|
||||
async fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
|
||||
let conn = try_outcome!(DbConn::from_request(request).await);
|
||||
fn from_request(request: &'a Request<'r>) -> request::Outcome<User, ()> {
|
||||
let conn = request.guard::<DbConn>()?;
|
||||
request
|
||||
.cookies()
|
||||
.get_private(AUTH_COOKIE)
|
||||
@@ -1032,6 +1026,7 @@ impl NewUser {
|
||||
pub(crate) mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
config::CONFIG,
|
||||
instance::{tests as instance_tests, Instance},
|
||||
search::tests::get_searcher,
|
||||
tests::{db, rockets},
|
||||
@@ -1128,7 +1123,9 @@ pub(crate) mod tests {
|
||||
let inserted = fill_database(conn);
|
||||
|
||||
assert!(User::get(conn, inserted[0].id).is_ok());
|
||||
inserted[0].delete(conn, &get_searcher()).unwrap();
|
||||
inserted[0]
|
||||
.delete(conn, &get_searcher(&CONFIG.search_tokenizers))
|
||||
.unwrap();
|
||||
assert!(User::get(conn, inserted[0].id).is_err());
|
||||
Ok(())
|
||||
});
|
||||
|
||||
+1
-2
@@ -10,8 +10,7 @@ msgstr ""
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=6; plural=(n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 "
|
||||
"&& n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5);\n"
|
||||
"Plural-Forms: nplurals=6; plural=(n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5);\n"
|
||||
"X-Crowdin-Project: plume\n"
|
||||
"X-Crowdin-Language: ar\n"
|
||||
"X-Crowdin-File: /master/po/plume/plume.pot\n"
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
nightly-2020-05-05
|
||||
nightly-2020-01-15
|
||||
|
||||
@@ -13,10 +13,12 @@ class Browser(unittest.TestCase):
|
||||
raise Exception("No browser was requested")
|
||||
capabilities['acceptSslCerts'] = True
|
||||
self.driver = webdriver.Remote(
|
||||
command_executor='http://localhost:24444/wd/hub',
|
||||
# The "selenium" address is set up by Drone CI and "points" to the container running selenium
|
||||
command_executor='http://selenium:24444/wd/hub',
|
||||
desired_capabilities=capabilities)
|
||||
def tearDown(self):
|
||||
self.driver.close()
|
||||
|
||||
def get(self, url):
|
||||
# Like "selenium", integration is mapped to the container that runs the plume instance
|
||||
return self.driver.get("https://localhost" + url)
|
||||
|
||||
@@ -12,7 +12,7 @@ plm users new -n admin -N 'Admin' -e 'email@exemple.com' -p 'password'
|
||||
plume &
|
||||
caddy -conf /Caddyfile &
|
||||
|
||||
until curl http://localhost:7878/test/health -f; do sleep 1; done 2>/dev/null >/dev/null
|
||||
until curl http://localhost:7878/test/health -f; do sleep 1; done #2>/dev/null >/dev/null
|
||||
|
||||
cd $(dirname $0)/browser_test/
|
||||
python3 -m unittest *.py
|
||||
|
||||
@@ -35,7 +35,6 @@ impl Scope for plume_models::posts::Post {
|
||||
|
||||
pub struct Authorization<A, S>(pub ApiToken, PhantomData<(A, S)>);
|
||||
|
||||
#[rocket::async_trait]
|
||||
impl<'a, 'r, A, S> FromRequest<'a, 'r> for Authorization<A, S>
|
||||
where
|
||||
A: Action,
|
||||
@@ -43,10 +42,9 @@ where
|
||||
{
|
||||
type Error = ();
|
||||
|
||||
async fn from_request(request: &'a Request<'r>) -> request::Outcome<Authorization<A, S>, ()> {
|
||||
fn from_request(request: &'a Request<'r>) -> request::Outcome<Authorization<A, S>, ()> {
|
||||
request
|
||||
.guard::<ApiToken>()
|
||||
.await
|
||||
.map_failure(|_| (Status::Unauthorized, ()))
|
||||
.and_then(|token| {
|
||||
if token.can(A::to_str(), S::to_str()) {
|
||||
|
||||
+10
-19
@@ -4,6 +4,7 @@ use rocket::{
|
||||
response::{self, Responder},
|
||||
};
|
||||
use rocket_contrib::json::Json;
|
||||
use serde_json;
|
||||
|
||||
use plume_common::utils::random_hex;
|
||||
use plume_models::{api_tokens::*, apps::App, users::User, Error, PlumeRocket};
|
||||
@@ -25,31 +26,21 @@ impl From<std::option::NoneError> for ApiError {
|
||||
}
|
||||
}
|
||||
|
||||
#[rocket::async_trait]
|
||||
impl<'r> Responder<'r> for ApiError {
|
||||
async fn respond_to(self, req: &'r Request<'_>) -> response::Result<'r> {
|
||||
fn respond_to(self, req: &Request<'_>) -> response::Result<'r> {
|
||||
match self.0 {
|
||||
Error::NotFound => {
|
||||
Json(json!({
|
||||
Error::NotFound => Json(json!({
|
||||
"error": "Not found"
|
||||
}))
|
||||
.respond_to(req)
|
||||
.await
|
||||
}
|
||||
Error::Unauthorized => {
|
||||
Json(json!({
|
||||
.respond_to(req),
|
||||
Error::Unauthorized => Json(json!({
|
||||
"error": "You are not authorized to access this resource"
|
||||
}))
|
||||
.respond_to(req)
|
||||
.await
|
||||
}
|
||||
_ => {
|
||||
Json(json!({
|
||||
.respond_to(req),
|
||||
_ => Json(json!({
|
||||
"error": "Server error"
|
||||
}))
|
||||
.respond_to(req)
|
||||
.await
|
||||
}
|
||||
.respond_to(req),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,14 +55,14 @@ pub struct OAuthRequest {
|
||||
}
|
||||
|
||||
#[get("/oauth2?<query..>")]
|
||||
pub async fn oauth(
|
||||
pub fn oauth(
|
||||
query: Form<OAuthRequest>,
|
||||
rockets: PlumeRocket,
|
||||
) -> Result<Json<serde_json::Value>, ApiError> {
|
||||
let conn = &*rockets.conn;
|
||||
let app = App::find_by_client_id(conn, &query.client_id)?;
|
||||
if app.client_secret == query.client_secret {
|
||||
if let Ok(user) = User::find_by_fqn(&rockets, &query.username).await {
|
||||
if let Ok(user) = User::find_by_fqn(&rockets, &query.username) {
|
||||
if user.auth(&query.password) {
|
||||
let token = ApiToken::insert(
|
||||
conn,
|
||||
|
||||
+2
-2
@@ -98,7 +98,7 @@ pub fn list(
|
||||
}
|
||||
|
||||
#[post("/posts", data = "<payload>")]
|
||||
pub async fn create(
|
||||
pub fn create(
|
||||
auth: Authorization<Write, Post>,
|
||||
payload: Json<NewPostData>,
|
||||
rockets: PlumeRocket,
|
||||
@@ -192,7 +192,7 @@ pub async fn create(
|
||||
for m in mentions.into_iter() {
|
||||
Mention::from_activity(
|
||||
&*conn,
|
||||
&Mention::build_activity(&rockets, &m).await?,
|
||||
&Mention::build_activity(&rockets, &m)?,
|
||||
post.id,
|
||||
true,
|
||||
true,
|
||||
|
||||
+20
-20
@@ -9,9 +9,9 @@ use plume_models::{
|
||||
use rocket::{data::*, http::Status, response::status, Outcome::*, Request};
|
||||
use rocket_contrib::json::*;
|
||||
use serde::Deserialize;
|
||||
use tokio::io::AsyncReadExt;
|
||||
use std::io::Read;
|
||||
|
||||
pub async fn handle_incoming(
|
||||
pub fn handle_incoming(
|
||||
rockets: PlumeRocket,
|
||||
data: SignedJson<serde_json::Value>,
|
||||
headers: Headers<'_>,
|
||||
@@ -32,7 +32,6 @@ pub async fn handle_incoming(
|
||||
// maybe we just know an old key?
|
||||
actor
|
||||
.refetch(conn)
|
||||
.await
|
||||
.and_then(|_| User::get(conn, actor.id))
|
||||
.and_then(|u| {
|
||||
if verify_http_headers(&u, &headers.0, &sig).is_secure() || act.clone().verify(&u) {
|
||||
@@ -74,31 +73,32 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for SignedJson<T> {
|
||||
type Owned = String;
|
||||
type Borrowed = str;
|
||||
|
||||
fn transform<'r>(r: &'r Request, d: Data) -> TransformFuture<'r, Self::Owned, Self::Error> {
|
||||
Box::pin(async move {
|
||||
fn transform(
|
||||
r: &Request<'_>,
|
||||
d: Data,
|
||||
) -> Transform<rocket::data::Outcome<Self::Owned, Self::Error>> {
|
||||
let size_limit = r.limits().get("json").unwrap_or(JSON_LIMIT);
|
||||
let mut s = String::with_capacity(512);
|
||||
let outcome = match d.open().take(size_limit).read_to_string(&mut s).await {
|
||||
Ok(_) => Success(s),
|
||||
Err(e) => Failure((Status::BadRequest, JsonError::Io(e))),
|
||||
};
|
||||
Transform::Borrowed(outcome)
|
||||
})
|
||||
match d.open().take(size_limit).read_to_string(&mut s) {
|
||||
Ok(_) => Transform::Borrowed(Success(s)),
|
||||
Err(e) => Transform::Borrowed(Failure((Status::BadRequest, JsonError::Io(e)))),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_data(
|
||||
_: &Request<'_>,
|
||||
o: Transformed<'a, Self>,
|
||||
) -> FromDataFuture<'a, Self, Self::Error> {
|
||||
Box::pin(async move {
|
||||
let string = try_outcome!(o.borrowed());
|
||||
) -> rocket::data::Outcome<Self, Self::Error> {
|
||||
let string = o.borrowed()?;
|
||||
match serde_json::from_str(&string) {
|
||||
Ok(v) => Success(SignedJson(Digest::from_body(&string), Json(v))),
|
||||
Err(e) if e.is_data() => {
|
||||
return Failure((Status::UnprocessableEntity, JsonError::Parse(string, e)))
|
||||
}
|
||||
Err(e) => Failure((Status::BadRequest, JsonError::Parse(string, e))),
|
||||
}
|
||||
})
|
||||
Err(e) => {
|
||||
if e.is_data() {
|
||||
Failure((Status::UnprocessableEntity, JsonError::Parse(string, e)))
|
||||
} else {
|
||||
Failure((Status::BadRequest, JsonError::Parse(string, e)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+24
-5
@@ -1,5 +1,5 @@
|
||||
#![allow(clippy::too_many_arguments)]
|
||||
#![feature(proc_macro_hygiene, try_trait)]
|
||||
#![feature(decl_macro, proc_macro_hygiene, try_trait)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate gettext_macros;
|
||||
@@ -9,7 +9,6 @@ extern crate rocket;
|
||||
extern crate serde_json;
|
||||
#[macro_use]
|
||||
extern crate validator_derive;
|
||||
extern crate validator;
|
||||
|
||||
use clap::App;
|
||||
use diesel::r2d2::ConnectionManager;
|
||||
@@ -20,13 +19,15 @@ use plume_models::{
|
||||
search::{Searcher as UnmanagedSearcher, SearcherError},
|
||||
Connection, Error, CONFIG,
|
||||
};
|
||||
use rocket_csrf::CsrfFairingBuilder;
|
||||
use scheduled_thread_pool::ScheduledThreadPool;
|
||||
use std::process::exit;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
|
||||
init_i18n!(
|
||||
"plume", ar, bg, ca, cs, de, en, eo, es, fr, gl, hi, hr, it, ja, nb, pl, pt, ro, ru, sr, sk, sv
|
||||
"plume", ar, bg, ca, cs, de, en, eo, es, fa, fr, gl, hi, hr, it, ja, nb, pl, pt, ro, ru, sr,
|
||||
sk, sv
|
||||
);
|
||||
|
||||
mod api;
|
||||
@@ -98,7 +99,7 @@ Then try to restart Plume.
|
||||
let workpool = ScheduledThreadPool::with_name("worker {}", num_cpus::get());
|
||||
// we want a fast exit here, so
|
||||
#[allow(clippy::match_wild_err_arm)]
|
||||
let searcher = match UnmanagedSearcher::open(&CONFIG.search_index) {
|
||||
let searcher = match UnmanagedSearcher::open(&CONFIG.search_index, &CONFIG.search_tokenizers) {
|
||||
Err(Error::Search(e)) => match e {
|
||||
SearcherError::WriteLockAcquisitionError => panic!(
|
||||
r#"
|
||||
@@ -273,7 +274,25 @@ Then try to restart Plume
|
||||
.manage(dbpool)
|
||||
.manage(Arc::new(workpool))
|
||||
.manage(searcher)
|
||||
.manage(include_i18n!());
|
||||
.manage(include_i18n!())
|
||||
.attach(
|
||||
CsrfFairingBuilder::new()
|
||||
.set_default_target(
|
||||
"/csrf-violation?target=<uri>".to_owned(),
|
||||
rocket::http::Method::Post,
|
||||
)
|
||||
.add_exceptions(vec![
|
||||
("/inbox".to_owned(), "/inbox".to_owned(), None),
|
||||
(
|
||||
"/@/<name>/inbox".to_owned(),
|
||||
"/@/<name>/inbox".to_owned(),
|
||||
None,
|
||||
),
|
||||
("/api/<path..>".to_owned(), "/api/<path..>".to_owned(), None),
|
||||
])
|
||||
.finalize()
|
||||
.expect("main: csrf fairing creation error"),
|
||||
);
|
||||
|
||||
#[cfg(feature = "test")]
|
||||
let rocket = rocket.mount("/test", routes![test_routes::health,]);
|
||||
|
||||
+18
-31
@@ -19,14 +19,10 @@ use plume_models::{
|
||||
};
|
||||
|
||||
#[get("/~/<name>?<page>", rank = 2)]
|
||||
pub async 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> {
|
||||
let page = page.unwrap_or_default();
|
||||
let conn = &*rockets.conn;
|
||||
let blog = Blog::find_by_fqn(&rockets, &name).await?;
|
||||
let blog = Blog::find_by_fqn(&rockets, &name)?;
|
||||
let posts = Post::blog_page(conn, &blog, page.limits())?;
|
||||
let articles_count = Post::count_for_blog(conn, &blog)?;
|
||||
let authors = &blog.list_authors(conn)?;
|
||||
@@ -42,12 +38,12 @@ pub async fn details(
|
||||
}
|
||||
|
||||
#[get("/~/<name>", rank = 1)]
|
||||
pub async fn activity_details(
|
||||
pub fn activity_details(
|
||||
name: String,
|
||||
rockets: PlumeRocket,
|
||||
_ap: ApRequest,
|
||||
) -> Option<ActivityStream<CustomGroup>> {
|
||||
let blog = Blog::find_by_fqn(&rockets, &name).await?;
|
||||
let blog = Blog::find_by_fqn(&rockets, &name).ok()?;
|
||||
Some(ActivityStream::new(blog.to_activity(&*rockets.conn).ok()?))
|
||||
}
|
||||
|
||||
@@ -87,7 +83,7 @@ fn valid_slug(title: &str) -> Result<(), ValidationError> {
|
||||
}
|
||||
|
||||
#[post("/blogs/new", data = "<form>")]
|
||||
pub async fn create(form: LenientForm<NewBlogForm>, rockets: PlumeRocket) -> RespondOrRedirect {
|
||||
pub fn create(form: LenientForm<NewBlogForm>, rockets: PlumeRocket) -> RespondOrRedirect {
|
||||
let slug = utils::make_actor_id(&form.title);
|
||||
let conn = &*rockets.conn;
|
||||
let intl = &rockets.intl.catalog;
|
||||
@@ -97,7 +93,7 @@ pub async fn create(form: LenientForm<NewBlogForm>, rockets: PlumeRocket) -> Res
|
||||
Ok(_) => ValidationErrors::new(),
|
||||
Err(e) => e,
|
||||
};
|
||||
if Blog::find_by_fqn(&rockets, &slug).await.is_ok() {
|
||||
if Blog::find_by_fqn(&rockets, &slug).is_ok() {
|
||||
errors.add(
|
||||
"title",
|
||||
ValidationError {
|
||||
@@ -147,11 +143,9 @@ pub async fn create(form: LenientForm<NewBlogForm>, rockets: PlumeRocket) -> Res
|
||||
}
|
||||
|
||||
#[post("/~/<name>/delete")]
|
||||
pub async fn delete(name: String, rockets: PlumeRocket) -> RespondOrRedirect {
|
||||
pub fn delete(name: String, rockets: PlumeRocket) -> RespondOrRedirect {
|
||||
let conn = &*rockets.conn;
|
||||
let blog = Blog::find_by_fqn(&rockets, &name)
|
||||
.await
|
||||
.expect("blog::delete: blog not found");
|
||||
let blog = Blog::find_by_fqn(&rockets, &name).expect("blog::delete: blog not found");
|
||||
|
||||
if rockets
|
||||
.user
|
||||
@@ -190,9 +184,9 @@ pub struct EditForm {
|
||||
}
|
||||
|
||||
#[get("/~/<name>/edit")]
|
||||
pub async fn edit(name: String, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> {
|
||||
pub fn edit(name: String, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> {
|
||||
let conn = &*rockets.conn;
|
||||
let blog = Blog::find_by_fqn(&rockets, &name).await?;
|
||||
let blog = Blog::find_by_fqn(&rockets, &name)?;
|
||||
if rockets
|
||||
.user
|
||||
.clone()
|
||||
@@ -239,16 +233,14 @@ fn check_media(conn: &Connection, id: i32, user: &User) -> bool {
|
||||
}
|
||||
|
||||
#[put("/~/<name>/edit", data = "<form>")]
|
||||
pub async fn update(
|
||||
pub fn update(
|
||||
name: String,
|
||||
form: LenientForm<EditForm>,
|
||||
rockets: PlumeRocket,
|
||||
) -> RespondOrRedirect {
|
||||
let conn = &*rockets.conn;
|
||||
let intl = &rockets.intl.catalog;
|
||||
let mut blog = Blog::find_by_fqn(&rockets, &name)
|
||||
.await
|
||||
.expect("blog::update: blog not found");
|
||||
let mut blog = Blog::find_by_fqn(&rockets, &name).expect("blog::update: blog not found");
|
||||
if !rockets
|
||||
.user
|
||||
.clone()
|
||||
@@ -350,28 +342,23 @@ pub async fn update(
|
||||
}
|
||||
|
||||
#[get("/~/<name>/outbox")]
|
||||
pub async fn outbox(
|
||||
name: String,
|
||||
rockets: PlumeRocket,
|
||||
) -> Option<ActivityStream<OrderedCollection>> {
|
||||
let blog = Blog::find_by_fqn(&rockets, &name).await?;
|
||||
pub fn outbox(name: String, rockets: PlumeRocket) -> Option<ActivityStream<OrderedCollection>> {
|
||||
let blog = Blog::find_by_fqn(&rockets, &name).ok()?;
|
||||
Some(blog.outbox(&*rockets.conn).ok()?)
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
#[get("/~/<name>/outbox?<page>")]
|
||||
pub async fn outbox_page(
|
||||
pub fn outbox_page(
|
||||
name: String,
|
||||
page: Page,
|
||||
rockets: PlumeRocket,
|
||||
) -> Option<ActivityStream<OrderedCollectionPage>> {
|
||||
let blog = Blog::find_by_fqn(&rockets, &name).await?;
|
||||
let blog = Blog::find_by_fqn(&rockets, &name).ok()?;
|
||||
Some(blog.outbox_page(&*rockets.conn, page.limits()).ok()?)
|
||||
}
|
||||
|
||||
#[get("/~/<name>/atom.xml")]
|
||||
pub async fn atom_feed(name: String, rockets: PlumeRocket) -> Option<Content<String>> {
|
||||
let blog = Blog::find_by_fqn(&rockets, &name).await?;
|
||||
pub fn atom_feed(name: String, rockets: PlumeRocket) -> Option<Content<String>> {
|
||||
let blog = Blog::find_by_fqn(&rockets, &name).ok()?;
|
||||
let conn = &*rockets.conn;
|
||||
let entries = Post::get_recents_for_blog(&*conn, &blog, 15).ok()?;
|
||||
let uri = Instance::get_local()
|
||||
|
||||
+17
-23
@@ -22,13 +22,13 @@ use plume_models::{
|
||||
#[derive(Default, FromForm, Debug, Validate)]
|
||||
pub struct NewCommentForm {
|
||||
pub responding_to: Option<i32>,
|
||||
#[validate(length(min = 1, message = "Your comment can't be empty"))]
|
||||
#[validate(length(min = "1", message = "Your comment can't be empty"))]
|
||||
pub content: String,
|
||||
pub warning: String,
|
||||
}
|
||||
|
||||
#[post("/~/<blog_name>/<slug>/comment", data = "<form>")]
|
||||
pub async fn create(
|
||||
pub fn create(
|
||||
blog_name: String,
|
||||
slug: String,
|
||||
form: LenientForm<NewCommentForm>,
|
||||
@@ -36,12 +36,10 @@ pub async fn create(
|
||||
rockets: PlumeRocket,
|
||||
) -> Result<Flash<Redirect>, Ructe> {
|
||||
let conn = &*rockets.conn;
|
||||
let blog = Blog::find_by_fqn(&rockets, &blog_name)
|
||||
.await
|
||||
.expect("comments::create: blog error");
|
||||
let blog = Blog::find_by_fqn(&rockets, &blog_name).expect("comments::create: blog error");
|
||||
let post = Post::find_by_slug(&*conn, &slug, blog.id).expect("comments::create: post error");
|
||||
match form.validate() {
|
||||
Ok(_ok) => {
|
||||
form.validate()
|
||||
.map(|_| {
|
||||
let (html, mentions, _hashtags) = utils::md_to_html(
|
||||
form.content.as_ref(),
|
||||
Some(
|
||||
@@ -68,7 +66,6 @@ pub async fn create(
|
||||
.expect("comments::create: insert error");
|
||||
let new_comment = comm
|
||||
.create_activity(&rockets)
|
||||
.await
|
||||
.expect("comments::create: activity error");
|
||||
|
||||
// save mentions
|
||||
@@ -76,7 +73,6 @@ pub async fn create(
|
||||
Mention::from_activity(
|
||||
&*conn,
|
||||
&Mention::build_activity(&rockets, &ment)
|
||||
.await
|
||||
.expect("comments::create: build mention error"),
|
||||
comm.id,
|
||||
false,
|
||||
@@ -94,14 +90,14 @@ pub async fn create(
|
||||
.worker
|
||||
.execute(move || broadcast(&user_clone, new_comment, dest));
|
||||
|
||||
Ok(Flash::success(
|
||||
Flash::success(
|
||||
Redirect::to(
|
||||
uri!(super::posts::details: blog = blog_name, slug = slug, responding_to = _),
|
||||
),
|
||||
i18n!(&rockets.intl.catalog, "Your comment has been posted."),
|
||||
))
|
||||
}
|
||||
Err(errors) => {
|
||||
)
|
||||
})
|
||||
.map_err(|errors| {
|
||||
// TODO: de-duplicate this code
|
||||
let comments = CommentTree::from_post(&*conn, &post, Some(&user))
|
||||
.expect("comments::create: comments error");
|
||||
@@ -110,7 +106,7 @@ pub async fn create(
|
||||
.responding_to
|
||||
.and_then(|r| Comment::get(&*conn, r).ok());
|
||||
|
||||
Err(render!(posts::details(
|
||||
render!(posts::details(
|
||||
&rockets.to_context(),
|
||||
post.clone(),
|
||||
blog,
|
||||
@@ -137,9 +133,8 @@ pub async fn create(
|
||||
post.get_authors(&*conn)
|
||||
.expect("comments::create: authors error")[0]
|
||||
.clone()
|
||||
)))
|
||||
}
|
||||
}
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
#[post("/~/<blog>/<slug>/comment/<id>/delete")]
|
||||
@@ -179,16 +174,15 @@ pub fn delete(
|
||||
}
|
||||
|
||||
#[get("/~/<_blog>/<_slug>/comment/<id>")]
|
||||
pub async fn activity_pub(
|
||||
pub fn activity_pub(
|
||||
_blog: String,
|
||||
_slug: String,
|
||||
id: i32,
|
||||
_ap: ApRequest,
|
||||
rockets: PlumeRocket,
|
||||
) -> Option<ActivityStream<Note>> {
|
||||
let c = match Comment::get(&*rockets.conn, id) {
|
||||
Ok(c) => c.to_activity(&rockets).await.ok(),
|
||||
Err(_) => None,
|
||||
};
|
||||
c.map(ActivityStream::new)
|
||||
Comment::get(&*rockets.conn, id)
|
||||
.and_then(|c| c.to_activity(&rockets))
|
||||
.ok()
|
||||
.map(ActivityStream::new)
|
||||
}
|
||||
|
||||
+11
-23
@@ -1,7 +1,6 @@
|
||||
use crate::template_utils::{IntoContext, Ructe};
|
||||
use plume_models::{Error, PlumeRocket};
|
||||
use rocket::{
|
||||
request::FromRequest,
|
||||
response::{self, Responder},
|
||||
Request,
|
||||
};
|
||||
@@ -15,46 +14,35 @@ impl From<Error> for ErrorPage {
|
||||
}
|
||||
}
|
||||
|
||||
#[rocket::async_trait]
|
||||
impl<'r> Responder<'r> for ErrorPage {
|
||||
async fn respond_to(self, req: &'r Request<'_>) -> response::Result<'r> {
|
||||
let rockets = PlumeRocket::from_request(req).await.unwrap();
|
||||
fn respond_to(self, req: &Request<'_>) -> response::Result<'r> {
|
||||
let rockets = req.guard::<PlumeRocket>().unwrap();
|
||||
|
||||
match self.0 {
|
||||
Error::NotFound => {
|
||||
render!(errors::not_found(&rockets.to_context()))
|
||||
.respond_to(req)
|
||||
.await
|
||||
}
|
||||
Error::NotFound => render!(errors::not_found(&rockets.to_context())).respond_to(req),
|
||||
Error::Unauthorized => {
|
||||
render!(errors::not_found(&rockets.to_context()))
|
||||
.respond_to(req)
|
||||
.await
|
||||
}
|
||||
_ => {
|
||||
render!(errors::not_found(&rockets.to_context()))
|
||||
.respond_to(req)
|
||||
.await
|
||||
render!(errors::not_found(&rockets.to_context())).respond_to(req)
|
||||
}
|
||||
_ => render!(errors::not_found(&rockets.to_context())).respond_to(req),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[catch(404)]
|
||||
pub async fn not_found(req: &Request<'_>) -> Ructe {
|
||||
let rockets = req.guard::<PlumeRocket>().await.unwrap();
|
||||
pub fn not_found(req: &Request<'_>) -> Ructe {
|
||||
let rockets = req.guard::<PlumeRocket>().unwrap();
|
||||
render!(errors::not_found(&rockets.to_context()))
|
||||
}
|
||||
|
||||
#[catch(422)]
|
||||
pub async fn unprocessable_entity(req: &Request<'_>) -> Ructe {
|
||||
let rockets = req.guard::<PlumeRocket>().await.unwrap();
|
||||
pub fn unprocessable_entity(req: &Request<'_>) -> Ructe {
|
||||
let rockets = req.guard::<PlumeRocket>().unwrap();
|
||||
render!(errors::unprocessable_entity(&rockets.to_context()))
|
||||
}
|
||||
|
||||
#[catch(500)]
|
||||
pub async fn server_error(req: &Request<'_>) -> Ructe {
|
||||
let rockets = req.guard::<PlumeRocket>().await.unwrap();
|
||||
pub fn server_error(req: &Request<'_>) -> Ructe {
|
||||
let rockets = req.guard::<PlumeRocket>().unwrap();
|
||||
render!(errors::server_error(&rockets.to_context()))
|
||||
}
|
||||
|
||||
|
||||
+7
-11
@@ -5,7 +5,7 @@ use rocket::{
|
||||
use rocket_contrib::json::Json;
|
||||
use rocket_i18n::I18n;
|
||||
use scheduled_thread_pool::ScheduledThreadPool;
|
||||
use std::path::PathBuf;
|
||||
use serde_json;
|
||||
use std::str::FromStr;
|
||||
use validator::{Validate, ValidationErrors};
|
||||
|
||||
@@ -76,12 +76,12 @@ pub fn admin_mod(_mod: Moderator, rockets: PlumeRocket) -> Ructe {
|
||||
|
||||
#[derive(Clone, FromForm, Validate)]
|
||||
pub struct InstanceSettingsForm {
|
||||
#[validate(length(min = 1))]
|
||||
#[validate(length(min = "1"))]
|
||||
pub name: String,
|
||||
pub open_registrations: bool,
|
||||
pub short_description: SafeString,
|
||||
pub long_description: SafeString,
|
||||
#[validate(length(min = 1))]
|
||||
#[validate(length(min = "1"))]
|
||||
pub default_license: String,
|
||||
}
|
||||
|
||||
@@ -386,21 +386,17 @@ fn ban(
|
||||
}
|
||||
|
||||
#[post("/inbox", data = "<data>")]
|
||||
pub async fn shared_inbox(
|
||||
pub fn shared_inbox(
|
||||
rockets: PlumeRocket,
|
||||
data: inbox::SignedJson<serde_json::Value>,
|
||||
headers: Headers<'_>,
|
||||
) -> Result<String, status::BadRequest<&'static str>> {
|
||||
inbox::handle_incoming(rockets, data, headers).await
|
||||
inbox::handle_incoming(rockets, data, headers)
|
||||
}
|
||||
|
||||
#[get("/remote_interact?<target>")]
|
||||
pub async fn interact(
|
||||
rockets: PlumeRocket,
|
||||
user: Option<User>,
|
||||
target: String,
|
||||
) -> Option<Redirect> {
|
||||
if User::find_by_fqn(&rockets, &target).await.is_ok() {
|
||||
pub fn interact(rockets: PlumeRocket, user: Option<User>, target: String) -> Option<Redirect> {
|
||||
if User::find_by_fqn(&rockets, &target).is_ok() {
|
||||
return Some(Redirect::to(uri!(super::user::details: name = target)));
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user