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 {
|
localhost:443 {
|
||||||
proxy / localhost:7878 {
|
proxy / integration:7878 {
|
||||||
transparent
|
transparent
|
||||||
}
|
}
|
||||||
tls self_signed
|
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
|
search_index
|
||||||
.buildconfig
|
.buildconfig
|
||||||
__pycache__
|
__pycache__
|
||||||
.vscode/
|
|
||||||
|
|||||||
Generated
+2239
-1758
File diff suppressed because it is too large
Load Diff
+10
-12
@@ -8,7 +8,6 @@ edition = "2018"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
activitypub = "0.1.3"
|
activitypub = "0.1.3"
|
||||||
askama_escape = "0.1"
|
askama_escape = "0.1"
|
||||||
async-trait = "*"
|
|
||||||
atom_syndication = "0.6"
|
atom_syndication = "0.6"
|
||||||
clap = "2.33"
|
clap = "2.33"
|
||||||
colored = "1.8"
|
colored = "1.8"
|
||||||
@@ -21,8 +20,9 @@ heck = "0.3.0"
|
|||||||
lettre = "0.9.2"
|
lettre = "0.9.2"
|
||||||
lettre_email = "0.9.2"
|
lettre_email = "0.9.2"
|
||||||
num_cpus = "1.10"
|
num_cpus = "1.10"
|
||||||
rocket = { git = "https://github.com/SergioBenitez/Rocket", rev = "async" }
|
rocket = "0.4.2"
|
||||||
rocket_contrib = { git = "https://github.com/SergioBenitez/Rocket", rev = "async" , features = ["json"] }
|
rocket_contrib = { version = "0.4.2", features = ["json"] }
|
||||||
|
rocket_i18n = { git = "https://github.com/Plume-org/rocket_i18n", rev = "e922afa7c366038b3433278c03b1456b346074f2" }
|
||||||
rpassword = "4.0"
|
rpassword = "4.0"
|
||||||
scheduled-thread-pool = "0.2.2"
|
scheduled-thread-pool = "0.2.2"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
@@ -30,10 +30,9 @@ serde_json = "1.0"
|
|||||||
serde_qs = "0.5"
|
serde_qs = "0.5"
|
||||||
shrinkwraprs = "0.2.1"
|
shrinkwraprs = "0.2.1"
|
||||||
syntect = "3.3"
|
syntect = "3.3"
|
||||||
tokio = "0.2"
|
validator = "0.8"
|
||||||
validator = "0.10"
|
validator_derive = "0.8"
|
||||||
validator_derive = "0.10"
|
webfinger = "0.4.1"
|
||||||
webfinger = { git = "https://github.com/Plume-org/webfinger", rev = "4e8f12810c4a7ba7a07bbcb722cd265fdff512b6", features = ["async"] }
|
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "plume"
|
name = "plume"
|
||||||
@@ -65,11 +64,9 @@ path = "plume-common"
|
|||||||
[dependencies.plume-models]
|
[dependencies.plume-models]
|
||||||
path = "plume-models"
|
path = "plume-models"
|
||||||
|
|
||||||
[dependencies.rocket_i18n]
|
[dependencies.rocket_csrf]
|
||||||
git = "https://github.com/Plume-org/rocket_i18n"
|
git = "https://github.com/fdb-hiroshima/rocket_csrf"
|
||||||
branch = "go-async"
|
rev = "29910f2829e7e590a540da3804336577b48c7b31"
|
||||||
default-features = false
|
|
||||||
features = ["rocket"]
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
ructe = "0.9.0"
|
ructe = "0.9.0"
|
||||||
@@ -81,6 +78,7 @@ postgres = ["plume-models/postgres", "diesel/postgres"]
|
|||||||
sqlite = ["plume-models/sqlite", "diesel/sqlite"]
|
sqlite = ["plume-models/sqlite", "diesel/sqlite"]
|
||||||
debug-mailer = []
|
debug-mailer = []
|
||||||
test = []
|
test = []
|
||||||
|
search-lindera = ["plume-models/search-lindera"]
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["plume-api", "plume-cli", "plume-models", "plume-common", "plume-front", "plume-macro"]
|
members = ["plume-api", "plume-cli", "plume-models", "plume-common", "plume-front", "plume-macro"]
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
/* Color Scheme */
|
/* Color Scheme */
|
||||||
$gray: #F3F3F3;
|
$gray: #f3f3f3;
|
||||||
$black: #242424;
|
$black: #242424;
|
||||||
$white: #F8F8F8;
|
$white: #f8f8f8;
|
||||||
$purple: #7765E3;
|
$purple: #7765e3;
|
||||||
$lightpurple: #c2bbee;
|
$lightpurple: #c2bbee;
|
||||||
$red: #E92F2F;
|
$red: #e92f2f;
|
||||||
$yellow: #ffe347;
|
$yellow: #ffe347;
|
||||||
$green: #23f0c7;
|
$green: #23f0c7;
|
||||||
|
|
||||||
@@ -24,9 +24,9 @@ $margin: 0 $horizontal-margin;
|
|||||||
|
|
||||||
/* Fonts */
|
/* Fonts */
|
||||||
|
|
||||||
$route159: "Route159", serif;
|
$route159: "Shabnam", "Route159", serif;
|
||||||
$playfair: "Playfair Display", serif;
|
$playfair: "Vazir", "Playfair Display", serif;
|
||||||
$lora: "Lora", serif;
|
$lora: "Vazir", "Lora", serif;
|
||||||
|
|
||||||
//Code Highlighting
|
//Code Highlighting
|
||||||
$code-keyword-color: #45244a;
|
$code-keyword-color: #45244a;
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
/* color palette: https://coolors.co/23f0c7-ef767a-7765e3-6457a6-ffe347 */
|
/* color palette: https://coolors.co/23f0c7-ef767a-7765e3-6457a6-ffe347 */
|
||||||
|
|
||||||
@import url('./feather.css');
|
@import url("./feather.css");
|
||||||
@import url('./fonts/Route159/Route159.css');
|
@import url("./fonts/Route159/Route159.css");
|
||||||
@import url('./fonts/Lora/Lora.css');
|
@import url("./fonts/Lora/Lora.css");
|
||||||
@import url('./fonts/Playfair_Display/PlayfairDisplay.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 "dark_variables";
|
||||||
@import 'global';
|
@import "global";
|
||||||
@import 'header';
|
@import "header";
|
||||||
@import 'article';
|
@import "article";
|
||||||
@import 'forms';
|
@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 */
|
/* color palette: https://coolors.co/23f0c7-ef767a-7765e3-6457a6-ffe347 */
|
||||||
|
|
||||||
@import url('./feather.css');
|
@import url("./feather.css");
|
||||||
@import url('./fonts/Route159/Route159.css');
|
@import url("./fonts/Route159/Route159.css");
|
||||||
@import url('./fonts/Lora/Lora.css');
|
@import url("./fonts/Lora/Lora.css");
|
||||||
@import url('./fonts/Playfair_Display/PlayfairDisplay.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 "variables";
|
||||||
@import 'global';
|
@import "global";
|
||||||
@import 'header';
|
@import "header";
|
||||||
@import 'article';
|
@import "article";
|
||||||
@import 'forms';
|
@import "forms";
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use rsass;
|
||||||
|
|
||||||
use ructe::Ructe;
|
use ructe::Ructe;
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
use std::{ffi::OsStr, fs::*, io::Write, path::*};
|
use std::{ffi::OsStr, fs::*, io::Write, path::*};
|
||||||
|
|||||||
@@ -23,3 +23,4 @@ path = "../plume-models"
|
|||||||
[features]
|
[features]
|
||||||
postgres = ["plume-models/postgres", "diesel/postgres"]
|
postgres = ["plume-models/postgres", "diesel/postgres"]
|
||||||
sqlite = ["plume-models/sqlite", "diesel/sqlite"]
|
sqlite = ["plume-models/sqlite", "diesel/sqlite"]
|
||||||
|
search-lindera = ["plume-models/search-lindera"]
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ fn init<'a>(args: &ArgMatches<'a>, conn: &Connection) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
if can_do || force {
|
if can_do || force {
|
||||||
let searcher = Searcher::create(&path).unwrap();
|
let searcher = Searcher::create(&path, &CONFIG.search_tokenizers).unwrap();
|
||||||
refill(args, conn, Some(searcher));
|
refill(args, conn, Some(searcher));
|
||||||
} else {
|
} else {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
@@ -98,7 +98,8 @@ fn refill<'a>(args: &ArgMatches<'a>, conn: &Connection, searcher: Option<Searche
|
|||||||
Some(path) => Path::new(path).join("search_index"),
|
Some(path) => Path::new(path).join("search_index"),
|
||||||
None => Path::new(&CONFIG.search_index).to_path_buf(),
|
None => Path::new(&CONFIG.search_index).to_path_buf(),
|
||||||
};
|
};
|
||||||
let searcher = 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");
|
searcher.fill(conn).expect("Couldn't import post");
|
||||||
println!("Commiting result");
|
println!("Commiting result");
|
||||||
|
|||||||
@@ -6,22 +6,22 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
activitypub = "0.1.1"
|
activitypub = "0.1.1"
|
||||||
activitystreams-derive = "0.2"
|
activitystreams-derive = "0.1.1"
|
||||||
activitystreams-traits = "0.1.0"
|
activitystreams-traits = "0.1.0"
|
||||||
array_tool = "1.0"
|
array_tool = "1.0"
|
||||||
base64 = "0.10"
|
base64 = "0.10"
|
||||||
futures-util = "*"
|
|
||||||
heck = "0.3.0"
|
heck = "0.3.0"
|
||||||
hex = "0.3"
|
hex = "0.3"
|
||||||
hyper = "0.13"
|
hyper = "0.12.33"
|
||||||
openssl = "0.10.22"
|
openssl = "0.10.22"
|
||||||
rocket = { git = "https://github.com/SergioBenitez/Rocket", rev = "async" }
|
rocket = "0.4.0"
|
||||||
|
reqwest = "0.9"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
shrinkwraprs = "0.2.1"
|
shrinkwraprs = "0.2.1"
|
||||||
syntect = "3.3"
|
syntect = "3.3"
|
||||||
tokio = "0.2"
|
tokio = "0.1.22"
|
||||||
regex-syntax = { version = "0.6.17", default-features = false, features = ["unicode-perl"] }
|
regex-syntax = { version = "0.6.17", default-features = false, features = ["unicode-perl"] }
|
||||||
|
|
||||||
[dependencies.chrono]
|
[dependencies.chrono]
|
||||||
@@ -31,7 +31,3 @@ version = "0.4"
|
|||||||
[dependencies.pulldown-cmark]
|
[dependencies.pulldown-cmark]
|
||||||
default-features = false
|
default-features = false
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
|
||||||
[dependencies.reqwest]
|
|
||||||
features = ["json", "blocking"]
|
|
||||||
version = "0.10"
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ where
|
|||||||
/// - the context to be passed to each handler.
|
/// - the context to be passed to each handler.
|
||||||
/// - the activity
|
/// - the activity
|
||||||
/// - the reason it has not been handled yet
|
/// - the reason it has not been handled yet
|
||||||
NotHandled(&'a mut C, serde_json::Value, InboxError<E>),
|
NotHandled(&'a C, serde_json::Value, InboxError<E>),
|
||||||
|
|
||||||
/// A matching handler have been found but failed
|
/// A matching handler have been found but failed
|
||||||
///
|
///
|
||||||
@@ -139,16 +139,16 @@ where
|
|||||||
///
|
///
|
||||||
/// - `ctx`: the context to pass to each handler
|
/// - `ctx`: the context to pass to each handler
|
||||||
/// - `json`: the JSON representation of the incoming activity
|
/// - `json`: the JSON representation of the incoming activity
|
||||||
pub fn handle(ctx: &'a mut C, json: serde_json::Value) -> Inbox<'a, C, E, R> {
|
pub fn handle(ctx: &'a C, json: serde_json::Value) -> Inbox<'a, C, E, R> {
|
||||||
Inbox::NotHandled(ctx, json, InboxError::NoMatch)
|
Inbox::NotHandled(ctx, json, InboxError::NoMatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Registers an handler on this Inbox.
|
/// Registers an handler on this Inbox.
|
||||||
pub fn with<A, V, M>(self) -> Inbox<'a, C, E, R>
|
pub fn with<A, V, M>(self) -> Inbox<'a, C, E, R>
|
||||||
where
|
where
|
||||||
A: AsActor<&'a mut C> + FromId<C, Error = E>,
|
A: AsActor<&'a C> + FromId<C, Error = E>,
|
||||||
V: activitypub::Activity,
|
V: activitypub::Activity,
|
||||||
M: AsObject<A, V, &'a mut C, Error = E> + FromId<C, Error = E>,
|
M: AsObject<A, V, &'a C, Error = E> + FromId<C, Error = E>,
|
||||||
M::Output: Into<R>,
|
M::Output: Into<R>,
|
||||||
{
|
{
|
||||||
if let Inbox::NotHandled(ctx, mut act, e) = self {
|
if let Inbox::NotHandled(ctx, mut act, e) = self {
|
||||||
@@ -264,7 +264,7 @@ pub trait FromId<C>: Sized {
|
|||||||
/// - `object`: optional object that will be used if the object was not found in the database
|
/// - `object`: optional object that will be used if the object was not found in the database
|
||||||
/// If absent, the ID will be dereferenced.
|
/// If absent, the ID will be dereferenced.
|
||||||
fn from_id(
|
fn from_id(
|
||||||
ctx: &mut C,
|
ctx: &C,
|
||||||
id: &str,
|
id: &str,
|
||||||
object: Option<Self::Object>,
|
object: Option<Self::Object>,
|
||||||
) -> Result<Self, (Option<serde_json::Value>, Self::Error)> {
|
) -> Result<Self, (Option<serde_json::Value>, Self::Error)> {
|
||||||
@@ -279,9 +279,8 @@ pub trait FromId<C>: Sized {
|
|||||||
|
|
||||||
/// Dereferences an ID
|
/// Dereferences an ID
|
||||||
fn deref(id: &str) -> Result<Self::Object, (Option<serde_json::Value>, Self::Error)> {
|
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::ClientBuilder::new()
|
||||||
reqwest::blocking::Client::builder()
|
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
||||||
.connect_timeout(std::time::Duration::from_secs(5))
|
|
||||||
.build()
|
.build()
|
||||||
.map_err(|_| (None, InboxError::DerefError.into()))?
|
.map_err(|_| (None, InboxError::DerefError.into()))?
|
||||||
.get(id)
|
.get(id)
|
||||||
@@ -297,7 +296,7 @@ pub trait FromId<C>: Sized {
|
|||||||
)
|
)
|
||||||
.send()
|
.send()
|
||||||
.map_err(|_| (None, InboxError::DerefError))
|
.map_err(|_| (None, InboxError::DerefError))
|
||||||
.and_then(|r| {
|
.and_then(|mut r| {
|
||||||
let json: serde_json::Value = r
|
let json: serde_json::Value = r
|
||||||
.json()
|
.json()
|
||||||
.map_err(|_| (None, InboxError::InvalidObject(None)))?;
|
.map_err(|_| (None, InboxError::InvalidObject(None)))?;
|
||||||
@@ -308,10 +307,10 @@ pub trait FromId<C>: Sized {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Builds a `Self` from its ActivityPub representation
|
/// Builds a `Self` from its ActivityPub representation
|
||||||
fn from_activity(ctx: &mut C, activity: Self::Object) -> Result<Self, Self::Error>;
|
fn from_activity(ctx: &C, activity: Self::Object) -> Result<Self, Self::Error>;
|
||||||
|
|
||||||
/// Tries to find a `Self` with a given ID (`id`), using `ctx` (a database)
|
/// Tries to find a `Self` with a given ID (`id`), using `ctx` (a database)
|
||||||
fn from_db(ctx: &mut C, id: &str) -> Result<Self, Self::Error>;
|
fn from_db(ctx: &C, id: &str) -> Result<Self, Self::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Should be implemented by anything representing an ActivityPub actor.
|
/// Should be implemented by anything representing an ActivityPub actor.
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
use activitypub::{Activity, Link, Object};
|
use activitypub::{Activity, Link, Object};
|
||||||
use array_tool::vec::Uniq;
|
use array_tool::vec::Uniq;
|
||||||
use reqwest::ClientBuilder;
|
use reqwest::r#async::ClientBuilder;
|
||||||
use rocket::{
|
use rocket::{
|
||||||
http::Status,
|
http::Status,
|
||||||
request::{FromRequest, Request},
|
request::{FromRequest, Request},
|
||||||
response::{Responder, Response, Result},
|
response::{Responder, Response},
|
||||||
Outcome,
|
Outcome,
|
||||||
};
|
};
|
||||||
|
use serde_json;
|
||||||
|
use tokio::prelude::*;
|
||||||
|
|
||||||
use self::sign::Signable;
|
use self::sign::Signable;
|
||||||
|
|
||||||
@@ -60,45 +62,39 @@ impl<T> ActivityStream<T> {
|
|||||||
ActivityStream(t)
|
ActivityStream(t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[rocket::async_trait]
|
|
||||||
impl<'r, O: Object + Send + 'r> Responder<'r> for ActivityStream<O> {
|
impl<'r, O: Object> Responder<'r> for ActivityStream<O> {
|
||||||
async fn respond_to(self, request: &'r Request<'_>) -> Result<'r> {
|
fn respond_to(self, request: &Request<'_>) -> Result<Response<'r>, Status> {
|
||||||
let mut json = serde_json::to_value(&self.0).map_err(|_| Status::InternalServerError)?;
|
let mut json = serde_json::to_value(&self.0).map_err(|_| Status::InternalServerError)?;
|
||||||
json["@context"] = context();
|
json["@context"] = context();
|
||||||
let result = serde_json::to_string(&json).map_err(rocket::response::Debug);
|
serde_json::to_string(&json).respond_to(request).map(|r| {
|
||||||
match result.respond_to(request).await {
|
Response::build_from(r)
|
||||||
Ok(r) => Response::build_from(r)
|
|
||||||
.raw_header("Content-Type", "application/activity+json")
|
.raw_header("Content-Type", "application/activity+json")
|
||||||
.ok(),
|
.finalize()
|
||||||
Err(e) => Err(e),
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ApRequest;
|
pub struct ApRequest;
|
||||||
#[rocket::async_trait]
|
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for ApRequest {
|
impl<'a, 'r> FromRequest<'a, 'r> for ApRequest {
|
||||||
type Error = ();
|
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
|
request
|
||||||
.headers()
|
.headers()
|
||||||
.get_one("Accept")
|
.get_one("Accept")
|
||||||
.map(|header| {
|
.map(|header| {
|
||||||
header
|
header
|
||||||
.split(',')
|
.split(',')
|
||||||
.map(|ct| {
|
.map(|ct| match ct.trim() {
|
||||||
match ct.trim() {
|
// bool for Forward: true if found a valid Content-Type for Plume first (HTML), false otherwise
|
||||||
// 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/ld+json;profile=\"https://w3.org/ns/activitystreams\""
|
| "application/ld+json;profile=\"https://w3.org/ns/activitystreams\""
|
||||||
| "application/activity+json"
|
| "application/activity+json"
|
||||||
| "application/ld+json" => Outcome::Success(ApRequest),
|
| "application/ld+json" => Outcome::Success(ApRequest),
|
||||||
"text/html" => Outcome::Forward(true),
|
"text/html" => Outcome::Forward(true),
|
||||||
_ => Outcome::Forward(false),
|
_ => Outcome::Forward(false),
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.fold(Outcome::Forward(false), |out, ct| {
|
.fold(Outcome::Forward(false), |out, ct| {
|
||||||
if out.clone().forwarded().unwrap_or_else(|| out.is_success()) {
|
if out.clone().forwarded().unwrap_or_else(|| out.is_success()) {
|
||||||
@@ -134,38 +130,36 @@ where
|
|||||||
.sign(sender)
|
.sign(sender)
|
||||||
.expect("activity_pub::broadcast: signature error");
|
.expect("activity_pub::broadcast: signature error");
|
||||||
|
|
||||||
let rt = tokio::runtime::Builder::new()
|
let mut rt = tokio::runtime::current_thread::Runtime::new()
|
||||||
.threaded_scheduler()
|
|
||||||
.build()
|
|
||||||
.expect("Error while initializing tokio runtime for federation");
|
.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()
|
let client = ClientBuilder::new()
|
||||||
.connect_timeout(std::time::Duration::from_secs(5))
|
.connect_timeout(std::time::Duration::from_secs(5))
|
||||||
.build()
|
.build()
|
||||||
.expect("Can't build client");
|
.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
|
client
|
||||||
.post(&inbox)
|
.post(&inbox)
|
||||||
.headers(headers.clone())
|
.headers(headers.clone())
|
||||||
.header("Signature", sig)
|
.header(
|
||||||
|
"Signature",
|
||||||
|
request::signature(sender, &headers)
|
||||||
|
.expect("activity_pub::broadcast: request signature error"),
|
||||||
|
)
|
||||||
.body(body)
|
.body(body)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.and_then(|r| r.into_body().concat2())
|
||||||
.unwrap()
|
|
||||||
.text()
|
|
||||||
.await
|
|
||||||
.map(move |response| {
|
.map(move |response| {
|
||||||
println!("Successfully sent activity to inbox ({})", inbox);
|
println!("Successfully sent activity to inbox ({})", inbox);
|
||||||
println!("Response: \"{:?}\"\n", response)
|
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)]
|
#[derive(Shrinkwrap, Clone, Serialize, Deserialize)]
|
||||||
@@ -209,7 +203,8 @@ pub struct PublicKey {
|
|||||||
pub public_key_pem: Option<serde_json::Value>,
|
pub public_key_pem: Option<serde_json::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, UnitString)]
|
||||||
|
#[activitystreams(Hashtag)]
|
||||||
pub struct HashtagType;
|
pub struct HashtagType;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use base64;
|
||||||
use chrono::{offset::Utc, DateTime};
|
use chrono::{offset::Utc, DateTime};
|
||||||
use openssl::hash::{Hasher, MessageDigest};
|
use openssl::hash::{Hasher, MessageDigest};
|
||||||
use reqwest::header::{HeaderMap, HeaderValue, ACCEPT, CONTENT_TYPE, DATE, USER_AGENT};
|
use reqwest::header::{HeaderMap, HeaderValue, ACCEPT, CONTENT_TYPE, DATE, USER_AGENT};
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
use super::request;
|
use super::request;
|
||||||
|
use base64;
|
||||||
use chrono::{naive::NaiveDateTime, DateTime, Duration, Utc};
|
use chrono::{naive::NaiveDateTime, DateTime, Duration, Utc};
|
||||||
|
use hex;
|
||||||
use openssl::{pkey::PKey, rsa::Rsa, sha::sha256};
|
use openssl::{pkey::PKey, rsa::Rsa, sha::sha256};
|
||||||
use rocket::http::HeaderMap;
|
use rocket::http::HeaderMap;
|
||||||
|
use serde_json;
|
||||||
|
|
||||||
/// Returns (public key, private key)
|
/// Returns (public key, private key)
|
||||||
pub fn gen_keypair() -> (Vec<u8>, Vec<u8>) {
|
pub fn gen_keypair() -> (Vec<u8>, Vec<u8>) {
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate activitystreams_derive;
|
extern crate activitystreams_derive;
|
||||||
|
use activitystreams_traits;
|
||||||
|
|
||||||
|
use serde;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate shrinkwraprs;
|
extern crate shrinkwraprs;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|||||||
@@ -442,6 +442,7 @@ mod tests {
|
|||||||
("not_a#hashtag", vec![]),
|
("not_a#hashtag", vec![]),
|
||||||
("#نرمافزار_آزاد", vec!["نرمافزار_آزاد"]),
|
("#نرمافزار_آزاد", vec!["نرمافزار_آزاد"]),
|
||||||
("[#hash in link](https://example.org/)", vec![]),
|
("[#hash in link](https://example.org/)", vec![]),
|
||||||
|
("#zwsp\u{200b}inhash", vec!["zwsp"]),
|
||||||
];
|
];
|
||||||
|
|
||||||
for (md, mentions) in tests {
|
for (md, mentions) in tests {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ init_i18n!(
|
|||||||
en,
|
en,
|
||||||
eo,
|
eo,
|
||||||
es,
|
es,
|
||||||
|
fa,
|
||||||
fr,
|
fr,
|
||||||
gl,
|
gl,
|
||||||
hi,
|
hi,
|
||||||
|
|||||||
+9
-18
@@ -10,26 +10,27 @@ ammonia = "2.1.1"
|
|||||||
askama_escape = "0.1"
|
askama_escape = "0.1"
|
||||||
bcrypt = "0.5"
|
bcrypt = "0.5"
|
||||||
guid-create = "0.1"
|
guid-create = "0.1"
|
||||||
futures = "0.3"
|
|
||||||
heck = "0.3.0"
|
heck = "0.3.0"
|
||||||
itertools = "0.8.0"
|
itertools = "0.8.0"
|
||||||
lazy_static = "1.0"
|
lazy_static = "1.0"
|
||||||
migrations_internals= "1.4.0"
|
migrations_internals= "1.4.0"
|
||||||
openssl = "0.10.22"
|
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"
|
scheduled-thread-pool = "0.2.2"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
tantivy = "0.10.1"
|
tantivy = "0.12.0"
|
||||||
tokio = "0.2"
|
|
||||||
url = "2.1"
|
url = "2.1"
|
||||||
walkdir = "2.2"
|
walkdir = "2.2"
|
||||||
webfinger = { git = "https://github.com/Plume-org/webfinger", rev = "4e8f12810c4a7ba7a07bbcb722cd265fdff512b6", features = ["async"] }
|
webfinger = "0.4.1"
|
||||||
whatlang = "0.7.1"
|
whatlang = "0.7.1"
|
||||||
shrinkwraprs = "0.3"
|
shrinkwraprs = "0.2.1"
|
||||||
diesel-derive-newtype = "0.1.2"
|
diesel-derive-newtype = "0.1.2"
|
||||||
glob = "0.3.0"
|
glob = "0.3.0"
|
||||||
|
lindera-tantivy = { version = "0.1.2", optional = true }
|
||||||
|
|
||||||
[dependencies.chrono]
|
[dependencies.chrono]
|
||||||
features = ["serde"]
|
features = ["serde"]
|
||||||
@@ -48,20 +49,10 @@ path = "../plume-common"
|
|||||||
[dependencies.plume-macro]
|
[dependencies.plume-macro]
|
||||||
path = "../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]
|
[dev-dependencies]
|
||||||
diesel_migrations = "1.4.0"
|
diesel_migrations = "1.3.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
postgres = ["diesel/postgres", "plume-macro/postgres" ]
|
postgres = ["diesel/postgres", "plume-macro/postgres" ]
|
||||||
sqlite = ["diesel/sqlite", "plume-macro/sqlite" ]
|
sqlite = ["diesel/sqlite", "plume-macro/sqlite" ]
|
||||||
|
search-lindera = ["lindera-tantivy"]
|
||||||
|
|||||||
@@ -8,12 +8,11 @@ use rocket::{
|
|||||||
/// Wrapper around User to use as a request guard on pages reserved to admins.
|
/// Wrapper around User to use as a request guard on pages reserved to admins.
|
||||||
pub struct Admin(pub User);
|
pub struct Admin(pub User);
|
||||||
|
|
||||||
#[rocket::async_trait]
|
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for Admin {
|
impl<'a, 'r> FromRequest<'a, 'r> for Admin {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
async fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
|
fn from_request(request: &'a Request<'r>) -> request::Outcome<Admin, ()> {
|
||||||
let user = try_outcome!(User::from_request(request).await);
|
let user = request.guard::<User>()?;
|
||||||
if user.is_admin() {
|
if user.is_admin() {
|
||||||
Outcome::Success(Admin(user))
|
Outcome::Success(Admin(user))
|
||||||
} else {
|
} else {
|
||||||
@@ -25,12 +24,11 @@ impl<'a, 'r> FromRequest<'a, 'r> for Admin {
|
|||||||
/// Same as `Admin` but for moderators.
|
/// Same as `Admin` but for moderators.
|
||||||
pub struct Moderator(pub User);
|
pub struct Moderator(pub User);
|
||||||
|
|
||||||
#[rocket::async_trait]
|
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for Moderator {
|
impl<'a, 'r> FromRequest<'a, 'r> for Moderator {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
async fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
|
fn from_request(request: &'a Request<'r>) -> request::Outcome<Moderator, ()> {
|
||||||
let user = try_outcome!(User::from_request(request).await);
|
let user = request.guard::<User>()?;
|
||||||
if user.is_moderator() {
|
if user.is_moderator() {
|
||||||
Outcome::Success(Moderator(user))
|
Outcome::Success(Moderator(user))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -76,36 +76,32 @@ pub enum TokenError {
|
|||||||
DbError,
|
DbError,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::async_trait]
|
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for ApiToken {
|
impl<'a, 'r> FromRequest<'a, 'r> for ApiToken {
|
||||||
type Error = TokenError;
|
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();
|
let headers: Vec<_> = request.headers().get("Authorization").collect();
|
||||||
if headers.len() != 1 {
|
if headers.len() != 1 {
|
||||||
return Outcome::Failure((Status::BadRequest, TokenError::NoHeader));
|
return Outcome::Failure((Status::BadRequest, TokenError::NoHeader));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut parsed_header = headers[0].split(' ');
|
let mut parsed_header = headers[0].split(' ');
|
||||||
if let Some(auth_type) = parsed_header.next() {
|
let auth_type = parsed_header.next().map_or_else(
|
||||||
if let Some(val) = parsed_header.next() {
|
|| 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 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) {
|
if let Ok(token) = ApiToken::find_by_value(&*conn, val) {
|
||||||
return Outcome::Success(token);
|
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(())
|
Outcome::Forward(())
|
||||||
|
|||||||
+14
-12
@@ -20,6 +20,7 @@ use plume_common::activity_pub::{
|
|||||||
inbox::{AsActor, FromId},
|
inbox::{AsActor, FromId},
|
||||||
sign, ActivityStream, ApSignature, Id, IntoId, PublicKey, Source,
|
sign, ActivityStream, ApSignature, Id, IntoId, PublicKey, Source,
|
||||||
};
|
};
|
||||||
|
use serde_json;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use webfinger::*;
|
use webfinger::*;
|
||||||
|
|
||||||
@@ -70,8 +71,7 @@ impl Blog {
|
|||||||
insert!(blogs, NewBlog, |inserted, conn| {
|
insert!(blogs, NewBlog, |inserted, conn| {
|
||||||
let instance = inserted.get_instance(conn)?;
|
let instance = inserted.get_instance(conn)?;
|
||||||
if inserted.outbox_url.is_empty() {
|
if inserted.outbox_url.is_empty() {
|
||||||
inserted.outbox_url =
|
inserted.outbox_url = instance.compute_box(BLOG_PREFIX, &inserted.actor_id, "outbox");
|
||||||
instance.compute_box(BLOG_PREFIX, &inserted.actor_id, r#"outbox"#);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if inserted.inbox_url.is_empty() {
|
if inserted.inbox_url.is_empty() {
|
||||||
@@ -132,7 +132,7 @@ impl Blog {
|
|||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn find_by_fqn(c: &mut PlumeRocket, fqn: &str) -> Result<Blog> {
|
pub fn find_by_fqn(c: &PlumeRocket, fqn: &str) -> Result<Blog> {
|
||||||
let from_db = blogs::table
|
let from_db = blogs::table
|
||||||
.filter(blogs::fqn.eq(fqn))
|
.filter(blogs::fqn.eq(fqn))
|
||||||
.first(&*c.conn)
|
.first(&*c.conn)
|
||||||
@@ -140,13 +140,12 @@ impl Blog {
|
|||||||
if let Some(from_db) = from_db {
|
if let Some(from_db) = from_db {
|
||||||
Ok(from_db)
|
Ok(from_db)
|
||||||
} else {
|
} else {
|
||||||
Blog::fetch_from_webfinger(c, fqn).await
|
Blog::fetch_from_webfinger(c, fqn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fetch_from_webfinger(c: &mut PlumeRocket, acct: &str) -> Result<Blog> {
|
fn fetch_from_webfinger(c: &PlumeRocket, acct: &str) -> Result<Blog> {
|
||||||
resolve_with_prefix(Prefix::Group, acct.to_owned(), true)
|
resolve_with_prefix(Prefix::Group, acct.to_owned(), true)?
|
||||||
.await?
|
|
||||||
.links
|
.links
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|l| l.mime_type == Some(String::from("application/activity+json")))
|
.find(|l| l.mime_type == Some(String::from("application/activity+json")))
|
||||||
@@ -340,11 +339,11 @@ impl FromId<PlumeRocket> for Blog {
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Object = CustomGroup;
|
type Object = CustomGroup;
|
||||||
|
|
||||||
fn from_db(c: &mut PlumeRocket, id: &str) -> Result<Self> {
|
fn from_db(c: &PlumeRocket, id: &str) -> Result<Self> {
|
||||||
Self::find_by_ap_url(&c.conn, id)
|
Self::find_by_ap_url(&c.conn, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity(c: &mut PlumeRocket, acct: CustomGroup) -> Result<Self> {
|
fn from_activity(c: &PlumeRocket, acct: CustomGroup) -> Result<Self> {
|
||||||
let url = Url::parse(&acct.object.object_props.id_string()?)?;
|
let url = Url::parse(&acct.object.object_props.id_string()?)?;
|
||||||
let inst = url.host_str()?;
|
let inst = url.host_str()?;
|
||||||
let instance = Instance::find_by_domain(&c.conn, inst).or_else(|_| {
|
let instance = Instance::find_by_domain(&c.conn, inst).or_else(|_| {
|
||||||
@@ -436,7 +435,7 @@ impl FromId<PlumeRocket> for Blog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsActor<&mut PlumeRocket> for Blog {
|
impl AsActor<&PlumeRocket> for Blog {
|
||||||
fn get_inbox_url(&self) -> String {
|
fn get_inbox_url(&self) -> String {
|
||||||
self.inbox_url.clone()
|
self.inbox_url.clone()
|
||||||
}
|
}
|
||||||
@@ -499,6 +498,7 @@ pub(crate) mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
blog_authors::*,
|
blog_authors::*,
|
||||||
|
config::CONFIG,
|
||||||
instance::tests as instance_tests,
|
instance::tests as instance_tests,
|
||||||
medias::NewMedia,
|
medias::NewMedia,
|
||||||
search::tests::get_searcher,
|
search::tests::get_searcher,
|
||||||
@@ -768,7 +768,9 @@ pub(crate) mod tests {
|
|||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
let (_, blogs) = fill_database(conn);
|
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());
|
assert!(Blog::get(conn, blogs[0].id).is_err());
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
@@ -778,7 +780,7 @@ pub(crate) mod tests {
|
|||||||
fn delete_via_user() {
|
fn delete_via_user() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
let searcher = get_searcher();
|
let searcher = get_searcher(&CONFIG.search_tokenizers);
|
||||||
let (user, _) = fill_database(conn);
|
let (user, _) = fill_database(conn);
|
||||||
|
|
||||||
let b1 = Blog::insert(
|
let b1 = Blog::insert(
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ use plume_common::{
|
|||||||
},
|
},
|
||||||
utils,
|
utils,
|
||||||
};
|
};
|
||||||
|
use serde_json;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable, Clone, AsChangeset)]
|
#[derive(Queryable, Identifiable, Clone, AsChangeset)]
|
||||||
@@ -104,7 +105,7 @@ impl Comment {
|
|||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn to_activity(&self, c: &mut PlumeRocket) -> Result<Note> {
|
pub fn to_activity(&self, c: &PlumeRocket) -> Result<Note> {
|
||||||
let author = User::get(&c.conn, self.author_id)?;
|
let author = User::get(&c.conn, self.author_id)?;
|
||||||
let (html, mentions, _hashtags) = utils::md_to_html(
|
let (html, mentions, _hashtags) = utils::md_to_html(
|
||||||
self.content.get().as_ref(),
|
self.content.get().as_ref(),
|
||||||
@@ -130,23 +131,19 @@ impl Comment {
|
|||||||
.set_published_string(chrono::Utc::now().to_rfc3339())?;
|
.set_published_string(chrono::Utc::now().to_rfc3339())?;
|
||||||
note.object_props.set_attributed_to_link(author.into_id())?;
|
note.object_props.set_attributed_to_link(author.into_id())?;
|
||||||
note.object_props.set_to_link_vec(to)?;
|
note.object_props.set_to_link_vec(to)?;
|
||||||
|
note.object_props.set_tag_link_vec(
|
||||||
let mut tag_link_vec = vec![];
|
mentions
|
||||||
let mut iter = mentions.into_iter();
|
.into_iter()
|
||||||
while let Some(m) = iter.next() {
|
.filter_map(|m| Mention::build_activity(c, &m).ok())
|
||||||
if let Ok(a) = Mention::build_activity(c, &m).await {
|
.collect::<Vec<link::Mention>>(),
|
||||||
tag_link_vec.push(a);
|
)?;
|
||||||
}
|
|
||||||
}
|
|
||||||
note.object_props.set_tag_link_vec(tag_link_vec)?;
|
|
||||||
|
|
||||||
Ok(note)
|
Ok(note)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_activity(&self, c: &mut PlumeRocket) -> Result<Create> {
|
pub fn create_activity(&self, c: &PlumeRocket) -> Result<Create> {
|
||||||
let author = User::get(&c.conn, self.author_id)?;
|
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();
|
let mut act = Create::default();
|
||||||
act.create_props.set_actor_link(author.into_id())?;
|
act.create_props.set_actor_link(author.into_id())?;
|
||||||
act.create_props.set_object_object(note.clone())?;
|
act.create_props.set_object_object(note.clone())?;
|
||||||
@@ -201,11 +198,11 @@ impl FromId<PlumeRocket> for Comment {
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Object = Note;
|
type Object = Note;
|
||||||
|
|
||||||
fn from_db(c: &mut PlumeRocket, id: &str) -> Result<Self> {
|
fn from_db(c: &PlumeRocket, id: &str) -> Result<Self> {
|
||||||
Self::find_by_ap_url(&c.conn, id)
|
Self::find_by_ap_url(&c.conn, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity(c: &mut PlumeRocket, note: Note) -> Result<Self> {
|
fn from_activity(c: &PlumeRocket, note: Note) -> Result<Self> {
|
||||||
let conn = &*c.conn;
|
let conn = &*c.conn;
|
||||||
let comm = {
|
let comm = {
|
||||||
let previous_url = note.object_props.in_reply_to.as_ref()?.as_str()?;
|
let previous_url = note.object_props.in_reply_to.as_ref()?.as_str()?;
|
||||||
@@ -325,21 +322,21 @@ impl FromId<PlumeRocket> for Comment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, Create, &mut PlumeRocket> for Comment {
|
impl AsObject<User, Create, &PlumeRocket> for Comment {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
fn activity(self, _c: &mut PlumeRocket, _actor: User, _id: &str) -> Result<Self> {
|
fn activity(self, _c: &PlumeRocket, _actor: User, _id: &str) -> Result<Self> {
|
||||||
// The actual creation takes place in the FromId impl
|
// The actual creation takes place in the FromId impl
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, Delete, &mut PlumeRocket> for Comment {
|
impl AsObject<User, Delete, &PlumeRocket> for Comment {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
fn activity(self, c: &mut PlumeRocket, actor: User, _id: &str) -> Result<()> {
|
fn activity(self, c: &PlumeRocket, actor: User, _id: &str) -> Result<()> {
|
||||||
if self.author_id != actor.id {
|
if self.author_id != actor.id {
|
||||||
return Err(Error::Unauthorized);
|
return Err(Error::Unauthorized);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::search::TokenizerKind as SearchTokenizer;
|
||||||
use rocket::config::Limits;
|
use rocket::config::Limits;
|
||||||
use rocket::Config as RocketConfig;
|
use rocket::Config as RocketConfig;
|
||||||
use std::env::{self, var};
|
use std::env::{self, var};
|
||||||
@@ -14,6 +15,7 @@ pub struct Config {
|
|||||||
pub db_max_size: Option<u32>,
|
pub db_max_size: Option<u32>,
|
||||||
pub db_min_idle: Option<u32>,
|
pub db_min_idle: Option<u32>,
|
||||||
pub search_index: String,
|
pub search_index: String,
|
||||||
|
pub search_tokenizers: SearchTokenizerConfig,
|
||||||
pub rocket: Result<RocketConfig, RocketError>,
|
pub rocket: Result<RocketConfig, RocketError>,
|
||||||
pub logo: LogoConfig,
|
pub logo: LogoConfig,
|
||||||
pub default_theme: String,
|
pub default_theme: String,
|
||||||
@@ -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! {
|
lazy_static! {
|
||||||
pub static ref CONFIG: Config = Config {
|
pub static ref CONFIG: Config = Config {
|
||||||
base_url: var("BASE_URL").unwrap_or_else(|_| format!(
|
base_url: var("BASE_URL").unwrap_or_else(|_| format!(
|
||||||
@@ -209,6 +261,7 @@ lazy_static! {
|
|||||||
#[cfg(feature = "sqlite")]
|
#[cfg(feature = "sqlite")]
|
||||||
database_url: var("DATABASE_URL").unwrap_or_else(|_| format!("{}.sqlite", DB_NAME)),
|
database_url: var("DATABASE_URL").unwrap_or_else(|_| format!("{}.sqlite", DB_NAME)),
|
||||||
search_index: var("SEARCH_INDEX").unwrap_or_else(|_| "search_index".to_owned()),
|
search_index: var("SEARCH_INDEX").unwrap_or_else(|_| "search_index".to_owned()),
|
||||||
|
search_tokenizers: SearchTokenizerConfig::init(),
|
||||||
rocket: get_rocket_config(),
|
rocket: get_rocket_config(),
|
||||||
logo: LogoConfig::default(),
|
logo: LogoConfig::default(),
|
||||||
default_theme: var("DEFAULT_THEME").unwrap_or_else(|_| "default-light".to_owned()),
|
default_theme: var("DEFAULT_THEME").unwrap_or_else(|_| "default-light".to_owned()),
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use diesel::{dsl::sql_query, ConnectionError, RunQueryDsl};
|
|||||||
use rocket::{
|
use rocket::{
|
||||||
http::Status,
|
http::Status,
|
||||||
request::{self, FromRequest},
|
request::{self, FromRequest},
|
||||||
Outcome, Request,
|
Outcome, Request, State,
|
||||||
};
|
};
|
||||||
use std::ops::Deref;
|
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
|
/// Attempts to retrieve a single connection from the managed database pool. If
|
||||||
/// no pool is currently managed, fails with an `InternalServerError` status. If
|
/// no pool is currently managed, fails with an `InternalServerError` status. If
|
||||||
/// no connections are available, fails with a `ServiceUnavailable` status.
|
/// no connections are available, fails with a `ServiceUnavailable` status.
|
||||||
#[rocket::async_trait]
|
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for DbConn {
|
impl<'a, 'r> FromRequest<'a, 'r> for DbConn {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
async fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
|
fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
|
||||||
match DbConn::from_request(request).await {
|
let pool = request.guard::<State<'_, DbPool>>()?;
|
||||||
Outcome::Success(a) => Outcome::Success(a),
|
match pool.get() {
|
||||||
_ => Outcome::Failure((Status::ServiceUnavailable, ())),
|
Ok(conn) => Outcome::Success(DbConn(conn)),
|
||||||
|
Err(_) => Outcome::Failure((Status::ServiceUnavailable, ())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,11 +136,11 @@ impl Follow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, FollowAct, &mut PlumeRocket> for User {
|
impl AsObject<User, FollowAct, &PlumeRocket> for User {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = Follow;
|
type Output = Follow;
|
||||||
|
|
||||||
fn activity(self, c: &mut PlumeRocket, actor: User, id: &str) -> Result<Follow> {
|
fn activity(self, c: &PlumeRocket, actor: User, id: &str) -> Result<Follow> {
|
||||||
// Mastodon (at least) requires the full Follow object when accepting it,
|
// Mastodon (at least) requires the full Follow object when accepting it,
|
||||||
// so we rebuilt it here
|
// so we rebuilt it here
|
||||||
let mut follow = FollowAct::default();
|
let mut follow = FollowAct::default();
|
||||||
@@ -156,11 +156,11 @@ impl FromId<PlumeRocket> for Follow {
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Object = FollowAct;
|
type Object = FollowAct;
|
||||||
|
|
||||||
fn from_db(c: &mut PlumeRocket, id: &str) -> Result<Self> {
|
fn from_db(c: &PlumeRocket, id: &str) -> Result<Self> {
|
||||||
Follow::find_by_ap_url(&c.conn, id)
|
Follow::find_by_ap_url(&c.conn, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity(c: &mut PlumeRocket, follow: FollowAct) -> Result<Self> {
|
fn from_activity(c: &PlumeRocket, follow: FollowAct) -> Result<Self> {
|
||||||
let actor =
|
let actor =
|
||||||
User::from_id(c, &follow.follow_props.actor_link::<Id>()?, None).map_err(|(_, e)| e)?;
|
User::from_id(c, &follow.follow_props.actor_link::<Id>()?, None).map_err(|(_, e)| e)?;
|
||||||
|
|
||||||
@@ -170,11 +170,11 @@ impl FromId<PlumeRocket> for Follow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, Undo, &mut PlumeRocket> for Follow {
|
impl AsObject<User, Undo, &PlumeRocket> for Follow {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
fn activity(self, c: &mut PlumeRocket, actor: User, _id: &str) -> Result<()> {
|
fn activity(self, c: &PlumeRocket, actor: User, _id: &str) -> Result<()> {
|
||||||
let conn = &*c.conn;
|
let conn = &*c.conn;
|
||||||
if self.follower_id == actor.id {
|
if self.follower_id == actor.id {
|
||||||
diesel::delete(&self).execute(conn)?;
|
diesel::delete(&self).execute(conn)?;
|
||||||
|
|||||||
@@ -6,11 +6,10 @@ use rocket::{
|
|||||||
|
|
||||||
pub struct Headers<'r>(pub HeaderMap<'r>);
|
pub struct Headers<'r>(pub HeaderMap<'r>);
|
||||||
|
|
||||||
#[rocket::async_trait]
|
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for Headers<'r> {
|
impl<'a, 'r> FromRequest<'a, 'r> for Headers<'r> {
|
||||||
type Error = ();
|
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();
|
let mut headers = HeaderMap::new();
|
||||||
for header in request.headers().clone().into_iter() {
|
for header in request.headers().clone().into_iter() {
|
||||||
headers.add(header);
|
headers.add(header);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use activitypub::activity::*;
|
use activitypub::activity::*;
|
||||||
|
use serde_json;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
comments::Comment,
|
comments::Comment,
|
||||||
@@ -45,7 +46,7 @@ impl_into_inbox_result! {
|
|||||||
Reshare => Reshared
|
Reshare => Reshared
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn inbox(ctx: &mut PlumeRocket, act: serde_json::Value) -> Result<InboxResult, Error> {
|
pub fn inbox(ctx: &PlumeRocket, act: serde_json::Value) -> Result<InboxResult, Error> {
|
||||||
Inbox::handle(ctx, act)
|
Inbox::handle(ctx, act)
|
||||||
.with::<User, Announce, Post>()
|
.with::<User, Announce, Post>()
|
||||||
.with::<User, Create, Comment>()
|
.with::<User, Create, Comment>()
|
||||||
@@ -72,7 +73,7 @@ pub(crate) mod tests {
|
|||||||
use diesel::Connection;
|
use diesel::Connection;
|
||||||
|
|
||||||
pub fn fill_database(
|
pub fn fill_database(
|
||||||
rockets: &mut PlumeRocket,
|
rockets: &PlumeRocket,
|
||||||
) -> (
|
) -> (
|
||||||
Vec<crate::posts::Post>,
|
Vec<crate::posts::Post>,
|
||||||
Vec<crate::users::User>,
|
Vec<crate::users::User>,
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
extern crate futures;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
#[macro_use]
|
#[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 {
|
impl From<url::ParseError> for Error {
|
||||||
fn from(_: url::ParseError) -> Self {
|
fn from(_: url::ParseError) -> Self {
|
||||||
Error::Url
|
Error::Url
|
||||||
@@ -327,7 +320,7 @@ mod tests {
|
|||||||
pub fn rockets() -> super::PlumeRocket {
|
pub fn rockets() -> super::PlumeRocket {
|
||||||
super::PlumeRocket {
|
super::PlumeRocket {
|
||||||
conn: db_conn::DbConn((*DB_POOL).get().unwrap()),
|
conn: db_conn::DbConn((*DB_POOL).get().unwrap()),
|
||||||
searcher: Arc::new(search::tests::get_searcher()),
|
searcher: Arc::new(search::tests::get_searcher(&CONFIG.search_tokenizers)),
|
||||||
worker: Arc::new(ScheduledThreadPool::new(2)),
|
worker: Arc::new(ScheduledThreadPool::new(2)),
|
||||||
user: None,
|
user: None,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,11 +83,11 @@ impl Like {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, activity::Like, &mut PlumeRocket> for Post {
|
impl AsObject<User, activity::Like, &PlumeRocket> for Post {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = Like;
|
type Output = Like;
|
||||||
|
|
||||||
fn activity(self, c: &mut PlumeRocket, actor: User, id: &str) -> Result<Like> {
|
fn activity(self, c: &PlumeRocket, actor: User, id: &str) -> Result<Like> {
|
||||||
let res = Like::insert(
|
let res = Like::insert(
|
||||||
&c.conn,
|
&c.conn,
|
||||||
NewLike {
|
NewLike {
|
||||||
@@ -107,11 +107,11 @@ impl FromId<PlumeRocket> for Like {
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Object = activity::Like;
|
type Object = activity::Like;
|
||||||
|
|
||||||
fn from_db(c: &mut PlumeRocket, id: &str) -> Result<Self> {
|
fn from_db(c: &PlumeRocket, id: &str) -> Result<Self> {
|
||||||
Like::find_by_ap_url(&c.conn, id)
|
Like::find_by_ap_url(&c.conn, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity(c: &mut PlumeRocket, act: activity::Like) -> Result<Self> {
|
fn from_activity(c: &PlumeRocket, act: activity::Like) -> Result<Self> {
|
||||||
let res = Like::insert(
|
let res = Like::insert(
|
||||||
&c.conn,
|
&c.conn,
|
||||||
NewLike {
|
NewLike {
|
||||||
@@ -129,11 +129,11 @@ impl FromId<PlumeRocket> for Like {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, activity::Undo, &mut PlumeRocket> for Like {
|
impl AsObject<User, activity::Undo, &PlumeRocket> for Like {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
fn activity(self, c: &mut PlumeRocket, actor: User, _id: &str) -> Result<()> {
|
fn activity(self, c: &PlumeRocket, actor: User, _id: &str) -> Result<()> {
|
||||||
let conn = &*c.conn;
|
let conn = &*c.conn;
|
||||||
if actor.id == self.user_id {
|
if actor.id == self.user_id {
|
||||||
diesel::delete(&self).execute(conn)?;
|
diesel::delete(&self).execute(conn)?;
|
||||||
|
|||||||
+14
-54
@@ -7,8 +7,8 @@ use crate::{
|
|||||||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||||
use std::convert::{TryFrom, TryInto};
|
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
|
/// Represent what a list is supposed to store. Represented in database as an integer
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum ListType {
|
pub enum ListType {
|
||||||
User,
|
User,
|
||||||
Blog,
|
Blog,
|
||||||
@@ -58,11 +58,7 @@ struct NewList<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! func {
|
macro_rules! func {
|
||||||
(
|
(@elem User $id:expr, $value:expr) => {
|
||||||
$(#[$outer:meta])*
|
|
||||||
@elem User $id:expr, $value:expr
|
|
||||||
) => {
|
|
||||||
$(#[$outer])*
|
|
||||||
NewListElem {
|
NewListElem {
|
||||||
list_id: $id,
|
list_id: $id,
|
||||||
user_id: Some(*$value),
|
user_id: Some(*$value),
|
||||||
@@ -70,11 +66,7 @@ macro_rules! func {
|
|||||||
word: None,
|
word: None,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(
|
(@elem Blog $id:expr, $value:expr) => {
|
||||||
$(#[$outer:meta])*
|
|
||||||
@elem Blog $id:expr, $value:expr
|
|
||||||
) => {
|
|
||||||
$(#[$outer])*
|
|
||||||
NewListElem {
|
NewListElem {
|
||||||
list_id: $id,
|
list_id: $id,
|
||||||
user_id: None,
|
user_id: None,
|
||||||
@@ -82,11 +74,7 @@ macro_rules! func {
|
|||||||
word: None,
|
word: None,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(
|
(@elem Word $id:expr, $value:expr) => {
|
||||||
$(#[$outer:meta])*
|
|
||||||
@elem Word $id:expr, $value:expr
|
|
||||||
) => {
|
|
||||||
$(#[$outer])*
|
|
||||||
NewListElem {
|
NewListElem {
|
||||||
list_id: $id,
|
list_id: $id,
|
||||||
user_id: None,
|
user_id: None,
|
||||||
@@ -94,11 +82,7 @@ macro_rules! func {
|
|||||||
word: Some($value),
|
word: Some($value),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(
|
(@elem Prefix $id:expr, $value:expr) => {
|
||||||
$(#[$outer:meta])*
|
|
||||||
@elem Prefix $id:expr, $value:expr
|
|
||||||
) => {
|
|
||||||
$(#[$outer])*
|
|
||||||
NewListElem {
|
NewListElem {
|
||||||
list_id: $id,
|
list_id: $id,
|
||||||
user_id: None,
|
user_id: None,
|
||||||
@@ -115,11 +99,7 @@ macro_rules! func {
|
|||||||
(@out_type Word) => { String };
|
(@out_type Word) => { String };
|
||||||
(@out_type Prefix) => { String };
|
(@out_type Prefix) => { String };
|
||||||
|
|
||||||
(
|
(add: $fn:ident, $kind:ident) => {
|
||||||
$(#[$outer:meta])*
|
|
||||||
add: $fn:ident, $kind:ident
|
|
||||||
) => {
|
|
||||||
$(#[$outer])*
|
|
||||||
pub fn $fn(&self, conn: &Connection, vals: &[func!(@in_type $kind)]) -> Result<()> {
|
pub fn $fn(&self, conn: &Connection, vals: &[func!(@in_type $kind)]) -> Result<()> {
|
||||||
if self.kind() != ListType::$kind {
|
if self.kind() != ListType::$kind {
|
||||||
return Err(Error::InvalidValue);
|
return Err(Error::InvalidValue);
|
||||||
@@ -136,11 +116,7 @@ macro_rules! func {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
(list: $fn:ident, $kind:ident, $table:ident) => {
|
||||||
$(#[$outer:meta])*
|
|
||||||
list: $fn:ident, $kind:ident, $table:ident
|
|
||||||
) => {
|
|
||||||
$(#[$outer])*
|
|
||||||
pub fn $fn(&self, conn: &Connection) -> Result<Vec<func!(@out_type $kind)>> {
|
pub fn $fn(&self, conn: &Connection) -> Result<Vec<func!(@out_type $kind)>> {
|
||||||
if self.kind() != ListType::$kind {
|
if self.kind() != ListType::$kind {
|
||||||
return Err(Error::InvalidValue);
|
return Err(Error::InvalidValue);
|
||||||
@@ -156,11 +132,7 @@ macro_rules! func {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
(
|
(set: $fn:ident, $kind:ident, $add:ident) => {
|
||||||
$(#[$outer:meta])*
|
|
||||||
set: $fn:ident, $kind:ident, $add:ident
|
|
||||||
) => {
|
|
||||||
$(#[$outer])*
|
|
||||||
pub fn $fn(&self, conn: &Connection, val: &[func!(@in_type $kind)]) -> Result<()> {
|
pub fn $fn(&self, conn: &Connection, val: &[func!(@in_type $kind)]) -> Result<()> {
|
||||||
if self.kind() != ListType::$kind {
|
if self.kind() != ListType::$kind {
|
||||||
return Err(Error::InvalidValue);
|
return Err(Error::InvalidValue);
|
||||||
@@ -274,35 +246,23 @@ impl List {
|
|||||||
private::ListElem::prefix_in_list(conn, self, word)
|
private::ListElem::prefix_in_list(conn, self, word)
|
||||||
}
|
}
|
||||||
|
|
||||||
func! {
|
|
||||||
/// Insert new users in a list
|
/// Insert new users in a list
|
||||||
add: add_users, User
|
func! {add: add_users, User}
|
||||||
}
|
|
||||||
|
|
||||||
func! {
|
|
||||||
/// Insert new blogs in a list
|
/// Insert new blogs in a list
|
||||||
add: add_blogs, Blog
|
func! {add: add_blogs, Blog}
|
||||||
}
|
|
||||||
|
|
||||||
func! {
|
|
||||||
/// Insert new words in a list
|
/// Insert new words in a list
|
||||||
add: add_words, Word
|
func! {add: add_words, Word}
|
||||||
}
|
|
||||||
|
|
||||||
func! {
|
|
||||||
/// Insert new prefixes in a list
|
/// Insert new prefixes in a list
|
||||||
add: add_prefixes, Prefix
|
func! {add: add_prefixes, Prefix}
|
||||||
}
|
|
||||||
|
|
||||||
func! {
|
|
||||||
/// Get all users in the list
|
/// Get all users in the list
|
||||||
list: list_users, User, users
|
func! {list: list_users, User, users}
|
||||||
}
|
|
||||||
|
|
||||||
func! {
|
|
||||||
/// Get all blogs in the list
|
/// Get all blogs in the list
|
||||||
list: list_blogs, Blog, blogs
|
func! {list: list_blogs, Blog, blogs}
|
||||||
}
|
|
||||||
|
|
||||||
/// Get all words in the list
|
/// Get all words in the list
|
||||||
pub fn list_words(&self, conn: &Connection) -> Result<Vec<String>> {
|
pub fn list_words(&self, conn: &Connection) -> Result<Vec<String>> {
|
||||||
|
|||||||
+19
-18
@@ -10,8 +10,8 @@ use plume_common::{
|
|||||||
activity_pub::{inbox::FromId, Id},
|
activity_pub::{inbox::FromId, Id},
|
||||||
utils::MediaProcessor,
|
utils::MediaProcessor,
|
||||||
};
|
};
|
||||||
|
use reqwest;
|
||||||
use std::{fs, path::Path};
|
use std::{fs, path::Path};
|
||||||
use tokio::prelude::*;
|
|
||||||
|
|
||||||
#[derive(Clone, Identifiable, Queryable)]
|
#[derive(Clone, Identifiable, Queryable)]
|
||||||
pub struct Media {
|
pub struct Media {
|
||||||
@@ -197,7 +197,8 @@ impl Media {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: merge with save_remote?
|
// TODO: merge with save_remote?
|
||||||
pub async fn from_activity(c: &mut 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 remote_url = image.object_props.url_string().ok()?;
|
||||||
let ext = remote_url
|
let ext = remote_url
|
||||||
.rsplit('.')
|
.rsplit('.')
|
||||||
@@ -210,11 +211,22 @@ impl Media {
|
|||||||
ext
|
ext
|
||||||
));
|
));
|
||||||
|
|
||||||
let mut dest = tokio::fs::File::create(path.clone()).await?;
|
let mut dest = fs::File::create(path.clone()).ok()?;
|
||||||
let contents = reqwest::get(remote_url.as_str()).await?.bytes().await?;
|
reqwest::get(remote_url.as_str())
|
||||||
dest.write_all(&contents).await?;
|
.ok()?
|
||||||
|
.copy_to(&mut dest)
|
||||||
|
.ok()?;
|
||||||
|
|
||||||
let owner_id = User::from_id(
|
Media::insert(
|
||||||
|
conn,
|
||||||
|
NewMedia {
|
||||||
|
file_path: path.to_str()?.to_string(),
|
||||||
|
alt_text: image.object_props.content_string().ok()?,
|
||||||
|
is_remote: false,
|
||||||
|
remote_url: None,
|
||||||
|
sensitive: image.object_props.summary_string().is_ok(),
|
||||||
|
content_warning: image.object_props.summary_string().ok(),
|
||||||
|
owner_id: User::from_id(
|
||||||
c,
|
c,
|
||||||
image
|
image
|
||||||
.object_props
|
.object_props
|
||||||
@@ -226,18 +238,7 @@ impl Media {
|
|||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.map_err(|(_, e)| e)?
|
.map_err(|(_, e)| e)?
|
||||||
.id;
|
.id,
|
||||||
|
|
||||||
Media::insert(
|
|
||||||
&mut c.conn,
|
|
||||||
NewMedia {
|
|
||||||
file_path: path.to_str()?.to_string(),
|
|
||||||
alt_text: image.object_props.content_string().ok()?,
|
|
||||||
is_remote: false,
|
|
||||||
remote_url: None,
|
|
||||||
sensitive: image.object_props.summary_string().is_ok(),
|
|
||||||
content_warning: image.object_props.summary_string().ok(),
|
|
||||||
owner_id
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ impl Mention {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn build_activity(c: &mut PlumeRocket, ment: &str) -> Result<link::Mention> {
|
pub fn build_activity(c: &PlumeRocket, ment: &str) -> Result<link::Mention> {
|
||||||
let user = User::find_by_fqn(c, ment).await?;
|
let user = User::find_by_fqn(c, ment)?;
|
||||||
let mut mention = link::Mention::default();
|
let mut mention = link::Mention::default();
|
||||||
mention.link_props.set_href_string(user.ap_url)?;
|
mention.link_props.set_href_string(user.ap_url)?;
|
||||||
mention.link_props.set_name_string(format!("@{}", ment))?;
|
mention.link_props.set_name_string(format!("@{}", ment))?;
|
||||||
|
|||||||
@@ -20,35 +20,20 @@ mod module {
|
|||||||
pub flash_msg: Option<(String, String)>,
|
pub flash_msg: Option<(String, String)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::async_trait]
|
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for PlumeRocket {
|
impl<'a, 'r> FromRequest<'a, 'r> for PlumeRocket {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
async fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
|
fn from_request(request: &'a Request<'r>) -> request::Outcome<PlumeRocket, ()> {
|
||||||
let conn = DbConn::from_request(request).await.succeeded().unwrap();
|
let conn = request.guard::<DbConn>()?;
|
||||||
let intl = rocket_i18n::I18n::from_request(request)
|
let intl = request.guard::<rocket_i18n::I18n>()?;
|
||||||
.await
|
let user = request.guard::<users::User>().succeeded();
|
||||||
.succeeded()
|
let worker = request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>()?;
|
||||||
.unwrap();
|
let searcher = request.guard::<'_, State<'_, Arc<search::Searcher>>>()?;
|
||||||
let user = users::User::from_request(request)
|
let flash_msg = request.guard::<FlashMessage<'_, '_>>().succeeded();
|
||||||
.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();
|
|
||||||
Outcome::Success(PlumeRocket {
|
Outcome::Success(PlumeRocket {
|
||||||
conn,
|
conn,
|
||||||
intl,
|
intl,
|
||||||
user: Some(user),
|
user,
|
||||||
flash_msg: flash_msg.map(|f| (f.name().into(), f.msg().into())),
|
flash_msg: flash_msg.map(|f| (f.name().into(), f.msg().into())),
|
||||||
worker: worker.clone(),
|
worker: worker.clone(),
|
||||||
searcher: searcher.clone(),
|
searcher: searcher.clone(),
|
||||||
@@ -75,18 +60,17 @@ mod module {
|
|||||||
pub worker: Arc<ScheduledThreadPool>,
|
pub worker: Arc<ScheduledThreadPool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::async_trait]
|
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for PlumeRocket {
|
impl<'a, 'r> FromRequest<'a, 'r> for PlumeRocket {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
async fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
|
fn from_request(request: &'a Request<'r>) -> request::Outcome<PlumeRocket, ()> {
|
||||||
let conn = try_outcome!(DbConn::from_request(request).await);
|
let conn = request.guard::<DbConn>()?;
|
||||||
let user = try_outcome!(users::User::from_request(request).await);
|
let user = request.guard::<users::User>().succeeded();
|
||||||
let worker = try_outcome!(request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>());
|
let worker = request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>()?;
|
||||||
let searcher = try_outcome!(request.guard::<'_, State<'_, Arc<search::Searcher>>>());
|
let searcher = request.guard::<'_, State<'_, Arc<search::Searcher>>>()?;
|
||||||
Outcome::Success(PlumeRocket {
|
Outcome::Success(PlumeRocket {
|
||||||
conn,
|
conn,
|
||||||
user: Some(user),
|
user,
|
||||||
worker: worker.clone(),
|
worker: worker.clone(),
|
||||||
searcher: searcher.clone(),
|
searcher: searcher.clone(),
|
||||||
})
|
})
|
||||||
|
|||||||
+29
-33
@@ -19,8 +19,8 @@ use plume_common::{
|
|||||||
},
|
},
|
||||||
utils::md_to_html,
|
utils::md_to_html,
|
||||||
};
|
};
|
||||||
|
use serde_json;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use tokio::runtime::Runtime;
|
|
||||||
|
|
||||||
pub type LicensedArticle = CustomObject<Licensed, Article>;
|
pub type LicensedArticle = CustomObject<Licensed, Article>;
|
||||||
|
|
||||||
@@ -554,11 +554,12 @@ impl FromId<PlumeRocket> for Post {
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Object = LicensedArticle;
|
type Object = LicensedArticle;
|
||||||
|
|
||||||
fn from_db(c: &mut PlumeRocket, id: &str) -> Result<Self> {
|
fn from_db(c: &PlumeRocket, id: &str) -> Result<Self> {
|
||||||
Self::find_by_ap_url(&c.conn, id)
|
Self::find_by_ap_url(&c.conn, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity(c: &mut PlumeRocket, article: LicensedArticle) -> Result<Self> {
|
fn from_activity(c: &PlumeRocket, article: LicensedArticle) -> Result<Self> {
|
||||||
|
let conn = &*c.conn;
|
||||||
let searcher = &c.searcher;
|
let searcher = &c.searcher;
|
||||||
let license = article.custom_props.license_string().unwrap_or_default();
|
let license = article.custom_props.license_string().unwrap_or_default();
|
||||||
let article = article.object;
|
let article = article.object;
|
||||||
@@ -569,24 +570,24 @@ impl FromId<PlumeRocket> for Post {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.fold((None, vec![]), |(blog, mut authors), link| {
|
.fold((None, vec![]), |(blog, mut authors), link| {
|
||||||
let url = link;
|
let url = link;
|
||||||
match User::from_id(&mut c, &url, None) {
|
match User::from_id(&c, &url, None) {
|
||||||
Ok(u) => {
|
Ok(u) => {
|
||||||
authors.push(u);
|
authors.push(u);
|
||||||
(blog, authors)
|
(blog, authors)
|
||||||
}
|
}
|
||||||
Err(_) => (blog.or_else(|| Blog::from_id(&mut c, &url, None).ok()), authors),
|
Err(_) => (blog.or_else(|| Blog::from_id(&c, &url, None).ok()), authors),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let image = article.object_props.icon_object::<Image>().ok().unwrap();
|
let cover = article
|
||||||
|
.object_props
|
||||||
let mut r = Runtime::new().unwrap();
|
.icon_object::<Image>()
|
||||||
let cover =
|
.ok()
|
||||||
Some(r.block_on(async { Media::from_activity(&mut c, &image).await.ok().unwrap().id }));
|
.and_then(|img| Media::from_activity(&c, &img).ok().map(|m| m.id));
|
||||||
|
|
||||||
let title = article.object_props.name_string()?;
|
let title = article.object_props.name_string()?;
|
||||||
let post = Post::insert(
|
let post = Post::insert(
|
||||||
&mut c.conn,
|
conn,
|
||||||
NewPost {
|
NewPost {
|
||||||
blog_id: blog?.id,
|
blog_id: blog?.id,
|
||||||
slug: title.to_kebab_case(),
|
slug: title.to_kebab_case(),
|
||||||
@@ -609,7 +610,7 @@ impl FromId<PlumeRocket> for Post {
|
|||||||
|
|
||||||
for author in authors {
|
for author in authors {
|
||||||
PostAuthor::insert(
|
PostAuthor::insert(
|
||||||
&mut c.conn,
|
conn,
|
||||||
NewPostAuthor {
|
NewPostAuthor {
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
author_id: author.id,
|
author_id: author.id,
|
||||||
@@ -626,7 +627,7 @@ impl FromId<PlumeRocket> for Post {
|
|||||||
if let Some(serde_json::Value::Array(tags)) = article.object_props.tag {
|
if let Some(serde_json::Value::Array(tags)) = article.object_props.tag {
|
||||||
for tag in tags {
|
for tag in tags {
|
||||||
serde_json::from_value::<link::Mention>(tag.clone())
|
serde_json::from_value::<link::Mention>(tag.clone())
|
||||||
.map(|m| Mention::from_activity(&mut c.conn, &m, post.id, true, true))
|
.map(|m| Mention::from_activity(conn, &m, post.id, true, true))
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
serde_json::from_value::<Hashtag>(tag.clone())
|
serde_json::from_value::<Hashtag>(tag.clone())
|
||||||
@@ -634,7 +635,7 @@ impl FromId<PlumeRocket> for Post {
|
|||||||
.and_then(|t| {
|
.and_then(|t| {
|
||||||
let tag_name = t.name_string()?;
|
let tag_name = t.name_string()?;
|
||||||
Ok(Tag::from_activity(
|
Ok(Tag::from_activity(
|
||||||
&mut c.conn,
|
conn,
|
||||||
&t,
|
&t,
|
||||||
post.id,
|
post.id,
|
||||||
hashtags.remove(&tag_name),
|
hashtags.remove(&tag_name),
|
||||||
@@ -650,21 +651,21 @@ impl FromId<PlumeRocket> for Post {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, Create, &mut PlumeRocket> for Post {
|
impl AsObject<User, Create, &PlumeRocket> for Post {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = Post;
|
type Output = Post;
|
||||||
|
|
||||||
fn activity(self, _c: &mut PlumeRocket, _actor: User, _id: &str) -> Result<Post> {
|
fn activity(self, _c: &PlumeRocket, _actor: User, _id: &str) -> Result<Post> {
|
||||||
// TODO: check that _actor is actually one of the author?
|
// TODO: check that _actor is actually one of the author?
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, Delete, &mut PlumeRocket> for Post {
|
impl AsObject<User, Delete, &PlumeRocket> for Post {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
fn activity(self, c: &mut PlumeRocket, actor: User, _id: &str) -> Result<()> {
|
fn activity(self, c: &PlumeRocket, actor: User, _id: &str) -> Result<()> {
|
||||||
let can_delete = self
|
let can_delete = self
|
||||||
.get_authors(&c.conn)?
|
.get_authors(&c.conn)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -692,28 +693,23 @@ impl FromId<PlumeRocket> for PostUpdate {
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Object = LicensedArticle;
|
type Object = LicensedArticle;
|
||||||
|
|
||||||
fn from_db(_: &mut PlumeRocket, _: &str) -> Result<Self> {
|
fn from_db(_: &PlumeRocket, _: &str) -> Result<Self> {
|
||||||
// Always fail because we always want to deserialize the AP object
|
// Always fail because we always want to deserialize the AP object
|
||||||
Err(Error::NotFound)
|
Err(Error::NotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity(c: &mut PlumeRocket, updated: LicensedArticle) -> Result<Self> {
|
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(&mut c, &image).await.ok().unwrap().id }));
|
|
||||||
|
|
||||||
Ok(PostUpdate {
|
Ok(PostUpdate {
|
||||||
ap_url: updated.object.object_props.id_string()?,
|
ap_url: updated.object.object_props.id_string()?,
|
||||||
title: updated.object.object_props.name_string().ok(),
|
title: updated.object.object_props.name_string().ok(),
|
||||||
subtitle: updated.object.object_props.summary_string().ok(),
|
subtitle: updated.object.object_props.summary_string().ok(),
|
||||||
content: updated.object.object_props.content_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
|
source: updated
|
||||||
.object
|
.object
|
||||||
.ap_object_props
|
.ap_object_props
|
||||||
@@ -726,11 +722,11 @@ impl FromId<PlumeRocket> for PostUpdate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, Update, &mut PlumeRocket> for PostUpdate {
|
impl AsObject<User, Update, &PlumeRocket> for PostUpdate {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
fn activity(self, c: &mut PlumeRocket, actor: User, _id: &str) -> Result<()> {
|
fn activity(self, c: &PlumeRocket, actor: User, _id: &str) -> Result<()> {
|
||||||
let conn = &*c.conn;
|
let conn = &*c.conn;
|
||||||
let searcher = &c.searcher;
|
let searcher = &c.searcher;
|
||||||
let mut post = Post::from_id(c, &self.ap_url, None).map_err(|(_, e)| e)?;
|
let mut post = Post::from_id(c, &self.ap_url, None).map_err(|(_, e)| e)?;
|
||||||
|
|||||||
@@ -107,11 +107,11 @@ impl Reshare {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, Announce, &mut PlumeRocket> for Post {
|
impl AsObject<User, Announce, &PlumeRocket> for Post {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = Reshare;
|
type Output = Reshare;
|
||||||
|
|
||||||
fn activity(self, c: &mut PlumeRocket, actor: User, id: &str) -> Result<Reshare> {
|
fn activity(self, c: &PlumeRocket, actor: User, id: &str) -> Result<Reshare> {
|
||||||
let conn = &*c.conn;
|
let conn = &*c.conn;
|
||||||
let reshare = Reshare::insert(
|
let reshare = Reshare::insert(
|
||||||
conn,
|
conn,
|
||||||
@@ -132,11 +132,11 @@ impl FromId<PlumeRocket> for Reshare {
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Object = Announce;
|
type Object = Announce;
|
||||||
|
|
||||||
fn from_db(c: &mut PlumeRocket, id: &str) -> Result<Self> {
|
fn from_db(c: &PlumeRocket, id: &str) -> Result<Self> {
|
||||||
Reshare::find_by_ap_url(&c.conn, id)
|
Reshare::find_by_ap_url(&c.conn, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity(c: &mut PlumeRocket, act: Announce) -> Result<Self> {
|
fn from_activity(c: &PlumeRocket, act: Announce) -> Result<Self> {
|
||||||
let res = Reshare::insert(
|
let res = Reshare::insert(
|
||||||
&c.conn,
|
&c.conn,
|
||||||
NewReshare {
|
NewReshare {
|
||||||
@@ -154,11 +154,11 @@ impl FromId<PlumeRocket> for Reshare {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, Undo, &mut PlumeRocket> for Reshare {
|
impl AsObject<User, Undo, &PlumeRocket> for Reshare {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
fn activity(self, c: &mut PlumeRocket, actor: User, _id: &str) -> Result<()> {
|
fn activity(self, c: &PlumeRocket, actor: User, _id: &str) -> Result<()> {
|
||||||
let conn = &*c.conn;
|
let conn = &*c.conn;
|
||||||
if actor.id == self.user_id {
|
if actor.id == self.user_id {
|
||||||
diesel::delete(&self).execute(conn)?;
|
diesel::delete(&self).execute(conn)?;
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ mod searcher;
|
|||||||
mod tokenizer;
|
mod tokenizer;
|
||||||
pub use self::query::PlumeQuery as Query;
|
pub use self::query::PlumeQuery as Query;
|
||||||
pub use self::searcher::*;
|
pub use self::searcher::*;
|
||||||
|
pub use self::tokenizer::TokenizerKind;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) mod tests {
|
pub(crate) mod tests {
|
||||||
use super::{Query, Searcher};
|
use super::{Query, Searcher, TokenizerKind};
|
||||||
use diesel::Connection;
|
use diesel::Connection;
|
||||||
use plume_common::utils::random_hex;
|
use plume_common::utils::random_hex;
|
||||||
use std::env::temp_dir;
|
use std::env::temp_dir;
|
||||||
@@ -14,18 +15,20 @@ pub(crate) mod tests {
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
blogs::tests::fill_database,
|
blogs::tests::fill_database,
|
||||||
|
config::SearchTokenizerConfig,
|
||||||
post_authors::*,
|
post_authors::*,
|
||||||
posts::{NewPost, Post},
|
posts::{NewPost, Post},
|
||||||
safe_string::SafeString,
|
safe_string::SafeString,
|
||||||
tests::db,
|
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()));
|
let dir = temp_dir().join(&format!("plume-test-{}", random_hex()));
|
||||||
if dir.exists() {
|
if dir.exists() {
|
||||||
Searcher::open(&dir)
|
Searcher::open(&dir, tokenizers)
|
||||||
} else {
|
} else {
|
||||||
Searcher::create(&dir)
|
Searcher::create(&dir, tokenizers)
|
||||||
}
|
}
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
@@ -100,27 +103,27 @@ pub(crate) mod tests {
|
|||||||
fn open() {
|
fn open() {
|
||||||
let dir = temp_dir().join(format!("plume-test-{}", random_hex()));
|
let dir = temp_dir().join(format!("plume-test-{}", random_hex()));
|
||||||
{
|
{
|
||||||
Searcher::create(&dir).unwrap();
|
Searcher::create(&dir, &CONFIG.search_tokenizers).unwrap();
|
||||||
}
|
}
|
||||||
Searcher::open(&dir).unwrap();
|
Searcher::open(&dir, &CONFIG.search_tokenizers).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn create() {
|
fn create() {
|
||||||
let dir = temp_dir().join(format!("plume-test-{}", random_hex()));
|
let dir = temp_dir().join(format!("plume-test-{}", random_hex()));
|
||||||
|
|
||||||
assert!(Searcher::open(&dir).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]
|
#[test]
|
||||||
fn search() {
|
fn search() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
let searcher = get_searcher();
|
let searcher = get_searcher(&CONFIG.search_tokenizers);
|
||||||
let blog = &fill_database(conn).1[0];
|
let blog = &fill_database(conn).1[0];
|
||||||
let author = &blog.list_authors(conn).unwrap()[0];
|
let author = &blog.list_authors(conn).unwrap()[0];
|
||||||
|
|
||||||
@@ -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]
|
#[test]
|
||||||
fn drop_writer() {
|
fn drop_writer() {
|
||||||
let searcher = get_searcher();
|
let searcher = get_searcher(&CONFIG.search_tokenizers);
|
||||||
searcher.drop_writer();
|
searcher.drop_writer();
|
||||||
get_searcher();
|
get_searcher(&CONFIG.search_tokenizers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,14 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
instance::Instance,
|
config::SearchTokenizerConfig, instance::Instance, posts::Post, schema::posts,
|
||||||
posts::Post,
|
search::query::PlumeQuery, tags::Tag, Connection, Result,
|
||||||
schema::posts,
|
|
||||||
search::{query::PlumeQuery, tokenizer},
|
|
||||||
tags::Tag,
|
|
||||||
Connection, Result,
|
|
||||||
};
|
};
|
||||||
use chrono::Datelike;
|
use chrono::Datelike;
|
||||||
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl};
|
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::{cmp, fs::create_dir_all, path::Path, sync::Mutex};
|
use std::{cmp, fs::create_dir_all, path::Path, sync::Mutex};
|
||||||
use tantivy::{
|
use tantivy::{
|
||||||
collector::TopDocs, directory::MmapDirectory, schema::*, tokenizer::*, Index, IndexReader,
|
collector::TopDocs, directory::MmapDirectory, schema::*, Index, IndexReader, IndexWriter,
|
||||||
IndexWriter, ReloadPolicy, Term,
|
ReloadPolicy, Term,
|
||||||
};
|
};
|
||||||
use whatlang::{detect as detect_lang, Lang};
|
use whatlang::{detect as detect_lang, Lang};
|
||||||
|
|
||||||
@@ -34,7 +30,7 @@ impl Searcher {
|
|||||||
pub fn schema() -> Schema {
|
pub fn schema() -> Schema {
|
||||||
let tag_indexing = TextOptions::default().set_indexing_options(
|
let tag_indexing = TextOptions::default().set_indexing_options(
|
||||||
TextFieldIndexing::default()
|
TextFieldIndexing::default()
|
||||||
.set_tokenizer("whitespace_tokenizer")
|
.set_tokenizer("tag_tokenizer")
|
||||||
.set_index_option(IndexRecordOption::Basic),
|
.set_index_option(IndexRecordOption::Basic),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -70,15 +66,7 @@ impl Searcher {
|
|||||||
schema_builder.build()
|
schema_builder.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create(path: &dyn AsRef<Path>) -> Result<Self> {
|
pub fn create(path: &dyn AsRef<Path>, tokenizers: &SearchTokenizerConfig) -> Result<Self> {
|
||||||
let whitespace_tokenizer = tokenizer::WhitespaceTokenizer.filter(LowerCaser);
|
|
||||||
|
|
||||||
let content_tokenizer = SimpleTokenizer
|
|
||||||
.filter(RemoveLongFilter::limit(40))
|
|
||||||
.filter(LowerCaser);
|
|
||||||
|
|
||||||
let property_tokenizer = NgramTokenizer::new(2, 8, false).filter(LowerCaser);
|
|
||||||
|
|
||||||
let schema = Self::schema();
|
let schema = Self::schema();
|
||||||
|
|
||||||
create_dir_all(path).map_err(|_| SearcherError::IndexCreationError)?;
|
create_dir_all(path).map_err(|_| SearcherError::IndexCreationError)?;
|
||||||
@@ -90,9 +78,9 @@ impl Searcher {
|
|||||||
|
|
||||||
{
|
{
|
||||||
let tokenizer_manager = index.tokenizers();
|
let tokenizer_manager = index.tokenizers();
|
||||||
tokenizer_manager.register("whitespace_tokenizer", whitespace_tokenizer);
|
tokenizer_manager.register("tag_tokenizer", tokenizers.tag_tokenizer);
|
||||||
tokenizer_manager.register("content_tokenizer", content_tokenizer);
|
tokenizer_manager.register("content_tokenizer", tokenizers.content_tokenizer);
|
||||||
tokenizer_manager.register("property_tokenizer", property_tokenizer);
|
tokenizer_manager.register("property_tokenizer", tokenizers.property_tokenizer);
|
||||||
} //to please the borrow checker
|
} //to please the borrow checker
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
writer: Mutex::new(Some(
|
writer: Mutex::new(Some(
|
||||||
@@ -109,31 +97,38 @@ impl Searcher {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open(path: &dyn AsRef<Path>) -> Result<Self> {
|
pub fn open(path: &dyn AsRef<Path>, tokenizers: &SearchTokenizerConfig) -> Result<Self> {
|
||||||
let whitespace_tokenizer = tokenizer::WhitespaceTokenizer.filter(LowerCaser);
|
let mut index =
|
||||||
|
|
||||||
let content_tokenizer = SimpleTokenizer
|
|
||||||
.filter(RemoveLongFilter::limit(40))
|
|
||||||
.filter(LowerCaser);
|
|
||||||
|
|
||||||
let property_tokenizer = NgramTokenizer::new(2, 8, false).filter(LowerCaser);
|
|
||||||
|
|
||||||
let index =
|
|
||||||
Index::open(MmapDirectory::open(path).map_err(|_| SearcherError::IndexOpeningError)?)
|
Index::open(MmapDirectory::open(path).map_err(|_| SearcherError::IndexOpeningError)?)
|
||||||
.map_err(|_| SearcherError::IndexOpeningError)?;
|
.map_err(|_| SearcherError::IndexOpeningError)?;
|
||||||
|
|
||||||
{
|
{
|
||||||
let tokenizer_manager = index.tokenizers();
|
let tokenizer_manager = index.tokenizers();
|
||||||
tokenizer_manager.register("whitespace_tokenizer", whitespace_tokenizer);
|
tokenizer_manager.register("tag_tokenizer", tokenizers.tag_tokenizer);
|
||||||
tokenizer_manager.register("content_tokenizer", content_tokenizer);
|
tokenizer_manager.register("content_tokenizer", tokenizers.content_tokenizer);
|
||||||
tokenizer_manager.register("property_tokenizer", property_tokenizer);
|
tokenizer_manager.register("property_tokenizer", tokenizers.property_tokenizer);
|
||||||
} //to please the borrow checker
|
} //to please the borrow checker
|
||||||
let mut writer = index
|
let writer = index
|
||||||
.writer(50_000_000)
|
.writer(50_000_000)
|
||||||
.map_err(|_| SearcherError::WriteLockAcquisitionError)?;
|
.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)?;
|
.map_err(|_| SearcherError::IndexEditionError)?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
writer: Mutex::new(Some(writer)),
|
writer: Mutex::new(Some(writer)),
|
||||||
reader: index
|
reader: index
|
||||||
|
|||||||
@@ -1,5 +1,34 @@
|
|||||||
|
#[cfg(feature = "search-lindera")]
|
||||||
|
use lindera_tantivy::tokenizer::LinderaTokenizer;
|
||||||
use std::str::CharIndices;
|
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,
|
/// Tokenize the text by splitting on whitespaces. Pretty much a copy of Tantivy's SimpleTokenizer,
|
||||||
/// but not splitting on punctuation
|
/// but not splitting on punctuation
|
||||||
@@ -12,15 +41,13 @@ pub struct WhitespaceTokenStream<'a> {
|
|||||||
token: Token,
|
token: Token,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Tokenizer<'a> for WhitespaceTokenizer {
|
impl Tokenizer for WhitespaceTokenizer {
|
||||||
type TokenStreamImpl = WhitespaceTokenStream<'a>;
|
fn token_stream<'a>(&self, text: &'a str) -> BoxTokenStream<'a> {
|
||||||
|
BoxTokenStream::from(WhitespaceTokenStream {
|
||||||
fn token_stream(&self, text: &'a str) -> Self::TokenStreamImpl {
|
|
||||||
WhitespaceTokenStream {
|
|
||||||
text,
|
text,
|
||||||
chars: text.char_indices(),
|
chars: text.char_indices(),
|
||||||
token: Token::default(),
|
token: Token::default(),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'a> WhitespaceTokenStream<'a> {
|
impl<'a> WhitespaceTokenStream<'a> {
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ impl Timeline {
|
|||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_to_all_timelines(rocket: &mut PlumeRocket, post: &Post, kind: Kind<'_>) -> Result<()> {
|
pub fn add_to_all_timelines(rocket: &PlumeRocket, post: &Post, kind: Kind<'_>) -> Result<()> {
|
||||||
let timelines = timeline_definition::table
|
let timelines = timeline_definition::table
|
||||||
.load::<Self>(rocket.conn.deref())
|
.load::<Self>(rocket.conn.deref())
|
||||||
.map_err(Error::from)?;
|
.map_err(Error::from)?;
|
||||||
@@ -231,7 +231,7 @@ impl Timeline {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn matches(&self, rocket: &mut PlumeRocket, post: &Post, kind: Kind<'_>) -> Result<bool> {
|
pub fn matches(&self, rocket: &PlumeRocket, post: &Post, kind: Kind<'_>) -> Result<bool> {
|
||||||
let query = TimelineQuery::parse(&self.query)?;
|
let query = TimelineQuery::parse(&self.query)?;
|
||||||
query.matches(rocket, self, post, kind)
|
query.matches(rocket, self, post, kind)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,7 @@ use crate::{
|
|||||||
users::User,
|
users::User,
|
||||||
PlumeRocket, Result,
|
PlumeRocket, Result,
|
||||||
};
|
};
|
||||||
use futures::stream::{self, StreamExt};
|
|
||||||
use plume_common::activity_pub::inbox::AsActor;
|
use plume_common::activity_pub::inbox::AsActor;
|
||||||
use tokio::runtime::Runtime;
|
|
||||||
use whatlang::{self, Lang};
|
use whatlang::{self, Lang};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
@@ -162,7 +160,7 @@ enum TQ<'a> {
|
|||||||
impl<'a> TQ<'a> {
|
impl<'a> TQ<'a> {
|
||||||
fn matches(
|
fn matches(
|
||||||
&self,
|
&self,
|
||||||
rocket: &mut PlumeRocket,
|
rocket: &PlumeRocket,
|
||||||
timeline: &Timeline,
|
timeline: &Timeline,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
kind: Kind<'_>,
|
kind: Kind<'_>,
|
||||||
@@ -207,7 +205,7 @@ enum Arg<'a> {
|
|||||||
impl<'a> Arg<'a> {
|
impl<'a> Arg<'a> {
|
||||||
pub fn matches(
|
pub fn matches(
|
||||||
&self,
|
&self,
|
||||||
rocket: &mut PlumeRocket,
|
rocket: &PlumeRocket,
|
||||||
timeline: &Timeline,
|
timeline: &Timeline,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
kind: Kind<'_>,
|
kind: Kind<'_>,
|
||||||
@@ -232,7 +230,7 @@ enum WithList {
|
|||||||
impl WithList {
|
impl WithList {
|
||||||
pub fn matches(
|
pub fn matches(
|
||||||
&self,
|
&self,
|
||||||
rocket: &mut PlumeRocket,
|
rocket: &PlumeRocket,
|
||||||
timeline: &Timeline,
|
timeline: &Timeline,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
list: &List<'_>,
|
list: &List<'_>,
|
||||||
@@ -297,33 +295,15 @@ impl WithList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
List::Array(list) => match self {
|
List::Array(list) => match self {
|
||||||
WithList::Blog => {
|
WithList::Blog => Ok(list
|
||||||
let mut rt = Runtime::new().unwrap();
|
.iter()
|
||||||
rt.block_on(async move {
|
.filter_map(|b| Blog::find_by_fqn(rocket, b).ok())
|
||||||
Ok(stream::iter(list)
|
.any(|b| b.id == post.blog_id)),
|
||||||
.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::Author { boosts, likes } => match kind {
|
WithList::Author { boosts, likes } => match kind {
|
||||||
Kind::Original => {
|
Kind::Original => Ok(list
|
||||||
let mut rt = Runtime::new().unwrap();
|
.iter()
|
||||||
rt.block_on(async move {
|
.filter_map(|a| User::find_by_fqn(rocket, a).ok())
|
||||||
Ok(stream::iter(list)
|
.any(|a| post.is_author(&rocket.conn, a.id).unwrap_or(false))),
|
||||||
.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::Reshare(u) => {
|
Kind::Reshare(u) => {
|
||||||
if *boosts {
|
if *boosts {
|
||||||
Ok(list.iter().any(|user| &u.fqn == user))
|
Ok(list.iter().any(|user| &u.fqn == user))
|
||||||
@@ -391,7 +371,7 @@ enum Bool {
|
|||||||
impl Bool {
|
impl Bool {
|
||||||
pub fn matches(
|
pub fn matches(
|
||||||
&self,
|
&self,
|
||||||
rocket: &mut PlumeRocket,
|
rocket: &PlumeRocket,
|
||||||
timeline: &Timeline,
|
timeline: &Timeline,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
kind: Kind<'_>,
|
kind: Kind<'_>,
|
||||||
@@ -426,8 +406,8 @@ impl Bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Bool::HasCover => Ok(post.cover_id.is_some()),
|
Bool::HasCover => Ok(post.cover_id.is_some()),
|
||||||
Bool::Local => Ok(post.get_blog(&rocket.conn)?.is_local()),
|
Bool::Local => Ok(post.get_blog(&rocket.conn)?.is_local() && kind == Kind::Original),
|
||||||
Bool::All => Ok(true),
|
Bool::All => Ok(kind == Kind::Original),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -662,7 +642,7 @@ impl<'a> TimelineQuery<'a> {
|
|||||||
|
|
||||||
pub fn matches(
|
pub fn matches(
|
||||||
&self,
|
&self,
|
||||||
rocket: &mut PlumeRocket,
|
rocket: &PlumeRocket,
|
||||||
timeline: &Timeline,
|
timeline: &Timeline,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
kind: Kind<'_>,
|
kind: Kind<'_>,
|
||||||
|
|||||||
+45
-48
@@ -11,6 +11,7 @@ use activitypub::{
|
|||||||
object::{Image, Tombstone},
|
object::{Image, Tombstone},
|
||||||
Activity, CustomObject, Endpoint,
|
Activity, CustomObject, Endpoint,
|
||||||
};
|
};
|
||||||
|
use bcrypt;
|
||||||
use chrono::{NaiveDateTime, Utc};
|
use chrono::{NaiveDateTime, Utc};
|
||||||
use diesel::{self, BelongingToDsl, ExpressionMethods, OptionalExtension, QueryDsl, RunQueryDsl};
|
use diesel::{self, BelongingToDsl, ExpressionMethods, OptionalExtension, QueryDsl, RunQueryDsl};
|
||||||
use openssl::{
|
use openssl::{
|
||||||
@@ -36,6 +37,7 @@ use rocket::{
|
|||||||
outcome::IntoOutcome,
|
outcome::IntoOutcome,
|
||||||
request::{self, FromRequest, Request},
|
request::{self, FromRequest, Request},
|
||||||
};
|
};
|
||||||
|
use serde_json;
|
||||||
use std::{
|
use std::{
|
||||||
cmp::PartialEq,
|
cmp::PartialEq,
|
||||||
hash::{Hash, Hasher},
|
hash::{Hash, Hasher},
|
||||||
@@ -189,7 +191,7 @@ impl User {
|
|||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn find_by_fqn(c: &mut PlumeRocket, fqn: &str) -> Result<User> {
|
pub fn find_by_fqn(c: &PlumeRocket, fqn: &str) -> Result<User> {
|
||||||
let from_db = users::table
|
let from_db = users::table
|
||||||
.filter(users::fqn.eq(fqn))
|
.filter(users::fqn.eq(fqn))
|
||||||
.first(&*c.conn)
|
.first(&*c.conn)
|
||||||
@@ -197,13 +199,12 @@ impl User {
|
|||||||
if let Some(from_db) = from_db {
|
if let Some(from_db) = from_db {
|
||||||
Ok(from_db)
|
Ok(from_db)
|
||||||
} else {
|
} else {
|
||||||
User::fetch_from_webfinger(c, fqn).await
|
User::fetch_from_webfinger(c, fqn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fetch_from_webfinger(c: &mut PlumeRocket, acct: &str) -> Result<User> {
|
fn fetch_from_webfinger(c: &PlumeRocket, acct: &str) -> Result<User> {
|
||||||
let link = resolve(acct.to_owned(), true)
|
let link = resolve(acct.to_owned(), true)?
|
||||||
.await?
|
|
||||||
.links
|
.links
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|l| l.mime_type == Some(String::from("application/activity+json")))
|
.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)
|
User::from_id(c, link.href.as_ref()?, None).map_err(|(_, e)| e)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_remote_interact_uri(acct: &str) -> Result<String> {
|
pub fn fetch_remote_interact_uri(acct: &str) -> Result<String> {
|
||||||
resolve(acct.to_owned(), true)
|
resolve(acct.to_owned(), true)?
|
||||||
.await?
|
|
||||||
.links
|
.links
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|l| l.rel == "http://ostatus.org/schema/1.0/subscribe")
|
.find(|l| l.rel == "http://ostatus.org/schema/1.0/subscribe")
|
||||||
@@ -221,9 +221,9 @@ impl User {
|
|||||||
.ok_or(Error::Webfinger)
|
.ok_or(Error::Webfinger)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fetch(url: &str) -> Result<CustomPerson> {
|
fn fetch(url: &str) -> Result<CustomPerson> {
|
||||||
let res = ClientBuilder::new()
|
let mut res = ClientBuilder::new()
|
||||||
.connect_timeout(std::time::Duration::from_secs(5))
|
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
||||||
.build()?
|
.build()?
|
||||||
.get(url)
|
.get(url)
|
||||||
.header(
|
.header(
|
||||||
@@ -235,9 +235,8 @@ impl User {
|
|||||||
.join(", "),
|
.join(", "),
|
||||||
)?,
|
)?,
|
||||||
)
|
)
|
||||||
.send()
|
.send()?;
|
||||||
.await?;
|
let text = &res.text()?;
|
||||||
let text = &res.text().await?;
|
|
||||||
// without this workaround, publicKey is not correctly deserialized
|
// without this workaround, publicKey is not correctly deserialized
|
||||||
let ap_sign = serde_json::from_str::<ApSignature>(text)?;
|
let ap_sign = serde_json::from_str::<ApSignature>(text)?;
|
||||||
let mut json = serde_json::from_str::<CustomPerson>(text)?;
|
let mut json = serde_json::from_str::<CustomPerson>(text)?;
|
||||||
@@ -245,13 +244,12 @@ impl User {
|
|||||||
Ok(json)
|
Ok(json)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_from_url(c: &mut PlumeRocket, url: &str) -> Result<User> {
|
pub fn fetch_from_url(c: &PlumeRocket, url: &str) -> Result<User> {
|
||||||
let json = User::fetch(url).await?;
|
User::fetch(url).and_then(|json| User::from_activity(c, json))
|
||||||
User::from_activity(c, json)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn refetch(&self, conn: &Connection) -> Result<()> {
|
pub fn refetch(&self, conn: &Connection) -> Result<()> {
|
||||||
let json = User::fetch(&self.ap_url.clone()).await?;
|
User::fetch(&self.ap_url.clone()).and_then(|json| {
|
||||||
let avatar = Media::save_remote(
|
let avatar = Media::save_remote(
|
||||||
conn,
|
conn,
|
||||||
json.object
|
json.object
|
||||||
@@ -287,6 +285,7 @@ impl User {
|
|||||||
.execute(conn)
|
.execute(conn)
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hash_pass(pass: &str) -> Result<String> {
|
pub fn hash_pass(pass: &str) -> Result<String> {
|
||||||
@@ -357,10 +356,9 @@ impl User {
|
|||||||
.set_part_of_link(Id::new(&self.outbox_url))?;
|
.set_part_of_link(Id::new(&self.outbox_url))?;
|
||||||
Ok(ActivityStream::new(coll))
|
Ok(ActivityStream::new(coll))
|
||||||
}
|
}
|
||||||
|
fn fetch_outbox_page<T: Activity>(&self, url: &str) -> Result<(Vec<T>, Option<String>)> {
|
||||||
async fn fetch_outbox_page<T: Activity>(&self, url: &str) -> Result<(Vec<T>, Option<String>)> {
|
let mut res = ClientBuilder::new()
|
||||||
let res = ClientBuilder::new()
|
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
||||||
.connect_timeout(std::time::Duration::from_secs(5))
|
|
||||||
.build()?
|
.build()?
|
||||||
.get(url)
|
.get(url)
|
||||||
.header(
|
.header(
|
||||||
@@ -372,9 +370,8 @@ impl User {
|
|||||||
.join(", "),
|
.join(", "),
|
||||||
)?,
|
)?,
|
||||||
)
|
)
|
||||||
.send()
|
.send()?;
|
||||||
.await?;
|
let text = &res.text()?;
|
||||||
let text = &res.text().await?;
|
|
||||||
let json: serde_json::Value = serde_json::from_str(text)?;
|
let json: serde_json::Value = serde_json::from_str(text)?;
|
||||||
let items = json["items"]
|
let items = json["items"]
|
||||||
.as_array()
|
.as_array()
|
||||||
@@ -389,9 +386,9 @@ impl User {
|
|||||||
};
|
};
|
||||||
Ok((items, next))
|
Ok((items, next))
|
||||||
}
|
}
|
||||||
pub async fn fetch_outbox<T: Activity>(&self) -> Result<Vec<T>> {
|
pub fn fetch_outbox<T: Activity>(&self) -> Result<Vec<T>> {
|
||||||
let res = ClientBuilder::new()
|
let mut res = ClientBuilder::new()
|
||||||
.connect_timeout(std::time::Duration::from_secs(5))
|
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
||||||
.build()?
|
.build()?
|
||||||
.get(&self.outbox_url[..])
|
.get(&self.outbox_url[..])
|
||||||
.header(
|
.header(
|
||||||
@@ -403,14 +400,13 @@ impl User {
|
|||||||
.join(", "),
|
.join(", "),
|
||||||
)?,
|
)?,
|
||||||
)
|
)
|
||||||
.send()
|
.send()?;
|
||||||
.await?;
|
let text = &res.text()?;
|
||||||
let text = &res.text().await?;
|
|
||||||
let json: serde_json::Value = serde_json::from_str(text)?;
|
let json: serde_json::Value = serde_json::from_str(text)?;
|
||||||
if let Some(first) = json.get("first") {
|
if let Some(first) = json.get("first") {
|
||||||
let mut items: Vec<T> = Vec::new();
|
let mut items: Vec<T> = Vec::new();
|
||||||
let mut next = first.as_str().unwrap().to_owned();
|
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() {
|
if page.is_empty() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -435,9 +431,9 @@ impl User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_followers_ids(&self) -> Result<Vec<String>> {
|
pub fn fetch_followers_ids(&self) -> Result<Vec<String>> {
|
||||||
let res = ClientBuilder::new()
|
let mut res = ClientBuilder::new()
|
||||||
.connect_timeout(std::time::Duration::from_secs(5))
|
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
||||||
.build()?
|
.build()?
|
||||||
.get(&self.followers_endpoint[..])
|
.get(&self.followers_endpoint[..])
|
||||||
.header(
|
.header(
|
||||||
@@ -449,9 +445,8 @@ impl User {
|
|||||||
.join(", "),
|
.join(", "),
|
||||||
)?,
|
)?,
|
||||||
)
|
)
|
||||||
.send()
|
.send()?;
|
||||||
.await?;
|
let text = &res.text()?;
|
||||||
let text = &res.text().await?;
|
|
||||||
let json: serde_json::Value = serde_json::from_str(text)?;
|
let json: serde_json::Value = serde_json::from_str(text)?;
|
||||||
Ok(json["items"]
|
Ok(json["items"]
|
||||||
.as_array()
|
.as_array()
|
||||||
@@ -794,12 +789,11 @@ impl User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::async_trait]
|
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for User {
|
impl<'a, 'r> FromRequest<'a, 'r> for User {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
async fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
|
fn from_request(request: &'a Request<'r>) -> request::Outcome<User, ()> {
|
||||||
let conn = try_outcome!(DbConn::from_request(request).await);
|
let conn = request.guard::<DbConn>()?;
|
||||||
request
|
request
|
||||||
.cookies()
|
.cookies()
|
||||||
.get_private(AUTH_COOKIE)
|
.get_private(AUTH_COOKIE)
|
||||||
@@ -821,11 +815,11 @@ impl FromId<PlumeRocket> for User {
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Object = CustomPerson;
|
type Object = CustomPerson;
|
||||||
|
|
||||||
fn from_db(c: &mut PlumeRocket, id: &str) -> Result<Self> {
|
fn from_db(c: &PlumeRocket, id: &str) -> Result<Self> {
|
||||||
Self::find_by_ap_url(&c.conn, id)
|
Self::find_by_ap_url(&c.conn, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity(c: &mut PlumeRocket, acct: CustomPerson) -> Result<Self> {
|
fn from_activity(c: &PlumeRocket, acct: CustomPerson) -> Result<Self> {
|
||||||
let url = Url::parse(&acct.object.object_props.id_string()?)?;
|
let url = Url::parse(&acct.object.object_props.id_string()?)?;
|
||||||
let inst = url.host_str()?;
|
let inst = url.host_str()?;
|
||||||
let instance = Instance::find_by_domain(&c.conn, inst).or_else(|_| {
|
let instance = Instance::find_by_domain(&c.conn, inst).or_else(|_| {
|
||||||
@@ -917,7 +911,7 @@ impl FromId<PlumeRocket> for User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsActor<&mut PlumeRocket> for User {
|
impl AsActor<&PlumeRocket> for User {
|
||||||
fn get_inbox_url(&self) -> String {
|
fn get_inbox_url(&self) -> String {
|
||||||
self.inbox_url.clone()
|
self.inbox_url.clone()
|
||||||
}
|
}
|
||||||
@@ -933,11 +927,11 @@ impl AsActor<&mut PlumeRocket> for User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, Delete, &mut PlumeRocket> for User {
|
impl AsObject<User, Delete, &PlumeRocket> for User {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
fn activity(self, c: &mut PlumeRocket, actor: User, _id: &str) -> Result<()> {
|
fn activity(self, c: &PlumeRocket, actor: User, _id: &str) -> Result<()> {
|
||||||
if self.id == actor.id {
|
if self.id == actor.id {
|
||||||
self.delete(&c.conn, &c.searcher).map(|_| ())
|
self.delete(&c.conn, &c.searcher).map(|_| ())
|
||||||
} else {
|
} else {
|
||||||
@@ -1032,6 +1026,7 @@ impl NewUser {
|
|||||||
pub(crate) mod tests {
|
pub(crate) mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
config::CONFIG,
|
||||||
instance::{tests as instance_tests, Instance},
|
instance::{tests as instance_tests, Instance},
|
||||||
search::tests::get_searcher,
|
search::tests::get_searcher,
|
||||||
tests::{db, rockets},
|
tests::{db, rockets},
|
||||||
@@ -1128,7 +1123,9 @@ pub(crate) mod tests {
|
|||||||
let inserted = fill_database(conn);
|
let inserted = fill_database(conn);
|
||||||
|
|
||||||
assert!(User::get(conn, inserted[0].id).is_ok());
|
assert!(User::get(conn, inserted[0].id).is_ok());
|
||||||
inserted[0].delete(conn, &get_searcher()).unwrap();
|
inserted[0]
|
||||||
|
.delete(conn, &get_searcher(&CONFIG.search_tokenizers))
|
||||||
|
.unwrap();
|
||||||
assert!(User::get(conn, inserted[0].id).is_err());
|
assert!(User::get(conn, inserted[0].id).is_err());
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-2
@@ -10,8 +10,7 @@ msgstr ""
|
|||||||
"MIME-Version: 1.0\n"
|
"MIME-Version: 1.0\n"
|
||||||
"Content-Type: text/plain; charset=UTF-8\n"
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
"Plural-Forms: nplurals=6; plural=(n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 "
|
"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"
|
||||||
"&& n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5);\n"
|
|
||||||
"X-Crowdin-Project: plume\n"
|
"X-Crowdin-Project: plume\n"
|
||||||
"X-Crowdin-Language: ar\n"
|
"X-Crowdin-Language: ar\n"
|
||||||
"X-Crowdin-File: /master/po/plume/plume.pot\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")
|
raise Exception("No browser was requested")
|
||||||
capabilities['acceptSslCerts'] = True
|
capabilities['acceptSslCerts'] = True
|
||||||
self.driver = webdriver.Remote(
|
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)
|
desired_capabilities=capabilities)
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.driver.close()
|
self.driver.close()
|
||||||
|
|
||||||
def get(self, url):
|
def get(self, url):
|
||||||
|
# Like "selenium", integration is mapped to the container that runs the plume instance
|
||||||
return self.driver.get("https://localhost" + url)
|
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 &
|
plume &
|
||||||
caddy -conf /Caddyfile &
|
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/
|
cd $(dirname $0)/browser_test/
|
||||||
python3 -m unittest *.py
|
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)>);
|
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>
|
impl<'a, 'r, A, S> FromRequest<'a, 'r> for Authorization<A, S>
|
||||||
where
|
where
|
||||||
A: Action,
|
A: Action,
|
||||||
@@ -43,10 +42,9 @@ where
|
|||||||
{
|
{
|
||||||
type Error = ();
|
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
|
request
|
||||||
.guard::<ApiToken>()
|
.guard::<ApiToken>()
|
||||||
.await
|
|
||||||
.map_failure(|_| (Status::Unauthorized, ()))
|
.map_failure(|_| (Status::Unauthorized, ()))
|
||||||
.and_then(|token| {
|
.and_then(|token| {
|
||||||
if token.can(A::to_str(), S::to_str()) {
|
if token.can(A::to_str(), S::to_str()) {
|
||||||
|
|||||||
+14
-22
@@ -4,6 +4,7 @@ use rocket::{
|
|||||||
response::{self, Responder},
|
response::{self, Responder},
|
||||||
};
|
};
|
||||||
use rocket_contrib::json::Json;
|
use rocket_contrib::json::Json;
|
||||||
|
use serde_json;
|
||||||
|
|
||||||
use plume_common::utils::random_hex;
|
use plume_common::utils::random_hex;
|
||||||
use plume_models::{api_tokens::*, apps::App, users::User, Error, PlumeRocket};
|
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 {
|
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 {
|
match self.0 {
|
||||||
Error::NotFound => {
|
Error::NotFound => Json(json!({
|
||||||
Json(json!({
|
|
||||||
"error": "Not found"
|
"error": "Not found"
|
||||||
}))
|
}))
|
||||||
.respond_to(req)
|
.respond_to(req),
|
||||||
.await
|
Error::Unauthorized => Json(json!({
|
||||||
}
|
|
||||||
Error::Unauthorized => {
|
|
||||||
Json(json!({
|
|
||||||
"error": "You are not authorized to access this resource"
|
"error": "You are not authorized to access this resource"
|
||||||
}))
|
}))
|
||||||
.respond_to(req)
|
.respond_to(req),
|
||||||
.await
|
_ => Json(json!({
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
Json(json!({
|
|
||||||
"error": "Server error"
|
"error": "Server error"
|
||||||
}))
|
}))
|
||||||
.respond_to(req)
|
.respond_to(req),
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,16 +55,17 @@ pub struct OAuthRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/oauth2?<query..>")]
|
#[get("/oauth2?<query..>")]
|
||||||
pub async fn oauth(
|
pub fn oauth(
|
||||||
query: Form<OAuthRequest>,
|
query: Form<OAuthRequest>,
|
||||||
rockets: PlumeRocket,
|
rockets: PlumeRocket,
|
||||||
) -> Result<Json<serde_json::Value>, ApiError> {
|
) -> Result<Json<serde_json::Value>, ApiError> {
|
||||||
let app = App::find_by_client_id(&rockets.conn, &query.client_id)?;
|
let conn = &*rockets.conn;
|
||||||
|
let app = App::find_by_client_id(conn, &query.client_id)?;
|
||||||
if app.client_secret == query.client_secret {
|
if app.client_secret == query.client_secret {
|
||||||
if let Ok(user) = User::find_by_fqn(&mut rockets, &query.username).await {
|
if let Ok(user) = User::find_by_fqn(&rockets, &query.username) {
|
||||||
if user.auth(&query.password) {
|
if user.auth(&query.password) {
|
||||||
let token = ApiToken::insert(
|
let token = ApiToken::insert(
|
||||||
&rockets.conn,
|
conn,
|
||||||
NewApiToken {
|
NewApiToken {
|
||||||
app_id: app.id,
|
app_id: app.id,
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
@@ -93,7 +85,7 @@ pub async fn oauth(
|
|||||||
// Making fake password verification to avoid different
|
// Making fake password verification to avoid different
|
||||||
// response times that would make it possible to know
|
// response times that would make it possible to know
|
||||||
// if a username is registered or not.
|
// if a username is registered or not.
|
||||||
User::get(&rockets.conn, 1)?.auth(&query.password);
|
User::get(conn, 1)?.auth(&query.password);
|
||||||
Ok(Json(json!({
|
Ok(Json(json!({
|
||||||
"error": "Invalid credentials"
|
"error": "Invalid credentials"
|
||||||
})))
|
})))
|
||||||
|
|||||||
+2
-2
@@ -98,7 +98,7 @@ pub fn list(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[post("/posts", data = "<payload>")]
|
#[post("/posts", data = "<payload>")]
|
||||||
pub async fn create(
|
pub fn create(
|
||||||
auth: Authorization<Write, Post>,
|
auth: Authorization<Write, Post>,
|
||||||
payload: Json<NewPostData>,
|
payload: Json<NewPostData>,
|
||||||
rockets: PlumeRocket,
|
rockets: PlumeRocket,
|
||||||
@@ -192,7 +192,7 @@ pub async fn create(
|
|||||||
for m in mentions.into_iter() {
|
for m in mentions.into_iter() {
|
||||||
Mention::from_activity(
|
Mention::from_activity(
|
||||||
&*conn,
|
&*conn,
|
||||||
&Mention::build_activity(&rockets, &m).await?,
|
&Mention::build_activity(&rockets, &m)?,
|
||||||
post.id,
|
post.id,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
|
|||||||
+20
-20
@@ -9,9 +9,9 @@ use plume_models::{
|
|||||||
use rocket::{data::*, http::Status, response::status, Outcome::*, Request};
|
use rocket::{data::*, http::Status, response::status, Outcome::*, Request};
|
||||||
use rocket_contrib::json::*;
|
use rocket_contrib::json::*;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use tokio::io::AsyncReadExt;
|
use std::io::Read;
|
||||||
|
|
||||||
pub async fn handle_incoming(
|
pub fn handle_incoming(
|
||||||
rockets: PlumeRocket,
|
rockets: PlumeRocket,
|
||||||
data: SignedJson<serde_json::Value>,
|
data: SignedJson<serde_json::Value>,
|
||||||
headers: Headers<'_>,
|
headers: Headers<'_>,
|
||||||
@@ -32,7 +32,6 @@ pub async fn handle_incoming(
|
|||||||
// maybe we just know an old key?
|
// maybe we just know an old key?
|
||||||
actor
|
actor
|
||||||
.refetch(conn)
|
.refetch(conn)
|
||||||
.await
|
|
||||||
.and_then(|_| User::get(conn, actor.id))
|
.and_then(|_| User::get(conn, actor.id))
|
||||||
.and_then(|u| {
|
.and_then(|u| {
|
||||||
if verify_http_headers(&u, &headers.0, &sig).is_secure() || act.clone().verify(&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 Owned = String;
|
||||||
type Borrowed = str;
|
type Borrowed = str;
|
||||||
|
|
||||||
fn transform<'r>(r: &'r Request, d: Data) -> TransformFuture<'r, Self::Owned, Self::Error> {
|
fn transform(
|
||||||
Box::pin(async move {
|
r: &Request<'_>,
|
||||||
|
d: Data,
|
||||||
|
) -> Transform<rocket::data::Outcome<Self::Owned, Self::Error>> {
|
||||||
let size_limit = r.limits().get("json").unwrap_or(JSON_LIMIT);
|
let size_limit = r.limits().get("json").unwrap_or(JSON_LIMIT);
|
||||||
let mut s = String::with_capacity(512);
|
let mut s = String::with_capacity(512);
|
||||||
let outcome = match d.open().take(size_limit).read_to_string(&mut s).await {
|
match d.open().take(size_limit).read_to_string(&mut s) {
|
||||||
Ok(_) => Success(s),
|
Ok(_) => Transform::Borrowed(Success(s)),
|
||||||
Err(e) => Failure((Status::BadRequest, JsonError::Io(e))),
|
Err(e) => Transform::Borrowed(Failure((Status::BadRequest, JsonError::Io(e)))),
|
||||||
};
|
}
|
||||||
Transform::Borrowed(outcome)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_data(
|
fn from_data(
|
||||||
_: &Request<'_>,
|
_: &Request<'_>,
|
||||||
o: Transformed<'a, Self>,
|
o: Transformed<'a, Self>,
|
||||||
) -> FromDataFuture<'a, Self, Self::Error> {
|
) -> rocket::data::Outcome<Self, Self::Error> {
|
||||||
Box::pin(async move {
|
let string = o.borrowed()?;
|
||||||
let string = try_outcome!(o.borrowed());
|
|
||||||
match serde_json::from_str(&string) {
|
match serde_json::from_str(&string) {
|
||||||
Ok(v) => Success(SignedJson(Digest::from_body(&string), Json(v))),
|
Ok(v) => Success(SignedJson(Digest::from_body(&string), Json(v))),
|
||||||
Err(e) if e.is_data() => {
|
Err(e) => {
|
||||||
return Failure((Status::UnprocessableEntity, JsonError::Parse(string, e)))
|
if e.is_data() {
|
||||||
}
|
Failure((Status::UnprocessableEntity, JsonError::Parse(string, e)))
|
||||||
Err(e) => Failure((Status::BadRequest, JsonError::Parse(string, e))),
|
} else {
|
||||||
}
|
Failure((Status::BadRequest, JsonError::Parse(string, e)))
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-5
@@ -1,5 +1,5 @@
|
|||||||
#![allow(clippy::too_many_arguments)]
|
#![allow(clippy::too_many_arguments)]
|
||||||
#![feature(proc_macro_hygiene, try_trait)]
|
#![feature(decl_macro, proc_macro_hygiene, try_trait)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate gettext_macros;
|
extern crate gettext_macros;
|
||||||
@@ -9,7 +9,6 @@ extern crate rocket;
|
|||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate validator_derive;
|
extern crate validator_derive;
|
||||||
extern crate validator;
|
|
||||||
|
|
||||||
use clap::App;
|
use clap::App;
|
||||||
use diesel::r2d2::ConnectionManager;
|
use diesel::r2d2::ConnectionManager;
|
||||||
@@ -20,13 +19,15 @@ use plume_models::{
|
|||||||
search::{Searcher as UnmanagedSearcher, SearcherError},
|
search::{Searcher as UnmanagedSearcher, SearcherError},
|
||||||
Connection, Error, CONFIG,
|
Connection, Error, CONFIG,
|
||||||
};
|
};
|
||||||
|
use rocket_csrf::CsrfFairingBuilder;
|
||||||
use scheduled_thread_pool::ScheduledThreadPool;
|
use scheduled_thread_pool::ScheduledThreadPool;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
init_i18n!(
|
init_i18n!(
|
||||||
"plume", ar, bg, ca, cs, de, en, eo, es, 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;
|
mod api;
|
||||||
@@ -98,7 +99,7 @@ Then try to restart Plume.
|
|||||||
let workpool = ScheduledThreadPool::with_name("worker {}", num_cpus::get());
|
let workpool = ScheduledThreadPool::with_name("worker {}", num_cpus::get());
|
||||||
// we want a fast exit here, so
|
// we want a fast exit here, so
|
||||||
#[allow(clippy::match_wild_err_arm)]
|
#[allow(clippy::match_wild_err_arm)]
|
||||||
let searcher = match UnmanagedSearcher::open(&CONFIG.search_index) {
|
let searcher = match UnmanagedSearcher::open(&CONFIG.search_index, &CONFIG.search_tokenizers) {
|
||||||
Err(Error::Search(e)) => match e {
|
Err(Error::Search(e)) => match e {
|
||||||
SearcherError::WriteLockAcquisitionError => panic!(
|
SearcherError::WriteLockAcquisitionError => panic!(
|
||||||
r#"
|
r#"
|
||||||
@@ -273,7 +274,25 @@ Then try to restart Plume
|
|||||||
.manage(dbpool)
|
.manage(dbpool)
|
||||||
.manage(Arc::new(workpool))
|
.manage(Arc::new(workpool))
|
||||||
.manage(searcher)
|
.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")]
|
#[cfg(feature = "test")]
|
||||||
let rocket = rocket.mount("/test", routes![test_routes::health,]);
|
let rocket = rocket.mount("/test", routes![test_routes::health,]);
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user