Merge branch 'master' into use-non-alpha-tokio

This commit is contained in:
Konrad Borowski 2019-12-11 16:10:52 +01:00
commit 5b1154a9ec
11 changed files with 838 additions and 426 deletions

8
Cargo.lock generated
View File

@ -1110,6 +1110,11 @@ dependencies = [
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "once_cell"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "opaque-debug" name = "opaque-debug"
version = "0.2.3" version = "0.2.3"
@ -1204,9 +1209,9 @@ dependencies = [
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"mime 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pulldown-cmark 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2508,6 +2513,7 @@ dependencies = [
"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09" "checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09"
"checksum num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c81ffc11c212fa327657cb19dd85eb7419e163b5b076bede2bdb5c974c07e4" "checksum num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c81ffc11c212fa327657cb19dd85eb7419e163b5b076bede2bdb5c974c07e4"
"checksum num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72" "checksum num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72"
"checksum once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "891f486f630e5c5a4916c7e16c4b24a53e78c860b646e9f8e005e4f16847bfed"
"checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" "checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
"checksum openssl 0.10.26 (registry+https://github.com/rust-lang/crates.io-index)" = "3a3cc5799d98e1088141b8e01ff760112bbd9f19d850c124500566ca6901a585" "checksum openssl 0.10.26 (registry+https://github.com/rust-lang/crates.io-index)" = "3a3cc5799d98e1088141b8e01ff760112bbd9f19d850c124500566ca6901a585"
"checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" "checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"

View File

@ -16,9 +16,9 @@ env_logger = { version = "0.6.0", default-features = false }
futures = "0.1.28" futures = "0.1.28"
futures03 = { version = "0.3.1", package = "futures", features = ["compat"] } futures03 = { version = "0.3.1", package = "futures", features = ["compat"] }
itertools = "0.8.1" itertools = "0.8.1"
lazy_static = "1.3.0"
log = "0.4.6" log = "0.4.6"
mime = "0.3.13" mime = "0.3.13"
once_cell = "1.2.0"
pulldown-cmark = "0.5.0" pulldown-cmark = "0.5.0"
rand = "0.7.0" rand = "0.7.0"
reqwest = "0.9.19" reqwest = "0.9.19"

View File

@ -15,7 +15,7 @@
{ {
"identifier": "clang", "identifier": "clang",
"label": "Run", "label": "Run",
"code": "mv code code.cpp; clang++ %s code.cpp && ./a.out" "code": "mv code code.c; clang %s code.c && ./a.out"
} }
] ]
}, },

1103
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,16 +5,16 @@
"devDependencies": { "devDependencies": {
"@types/codemirror": "0.0.78", "@types/codemirror": "0.0.78",
"@types/prismjs": "^1.16.0", "@types/prismjs": "^1.16.0",
"codemirror": "^5.49.0", "codemirror": "^5.49.2",
"css-loader": "^3.2.0", "css-loader": "^3.3.0",
"monaco-editor": "^0.18.1", "monaco-editor": "^0.18.1",
"monaco-editor-webpack-plugin": "^1.7.0", "monaco-editor-webpack-plugin": "^1.7.0",
"prismjs": "^1.17.1", "prismjs": "^1.17.1",
"style-loader": "^1.0.0", "style-loader": "^1.0.1",
"ts-loader": "^6.2.0", "ts-loader": "^6.2.1",
"typescript": "^3.7.2", "typescript": "^3.7.3",
"webpack": "^4.40.2", "webpack": "^4.41.2",
"webpack-cli": "^3.3.9", "webpack-cli": "^3.3.10",
"webpack-stats-plugin": "^0.3.0" "webpack-stats-plugin": "^0.3.0"
} }
} }

View File

@ -1,4 +1,5 @@
use crate::models::paste; use crate::models::paste;
use crate::models::paste::ExtraPasteParameters;
use crate::schema::{implementation_wrappers, implementations, languages, pastes}; use crate::schema::{implementation_wrappers, implementations, languages, pastes};
use crate::Connection; use crate::Connection;
use diesel::prelude::*; use diesel::prelude::*;
@ -71,10 +72,7 @@ pub fn run(connection: &Connection) -> Result<(), Box<dyn Error>> {
None, None,
&languages_identifier, &languages_identifier,
hello_world, hello_world,
"".into(), ExtraPasteParameters::default(),
None,
None,
None,
) )
.unwrap(); .unwrap();
diesel::update(languages::table) diesel::update(languages::table)

View File

@ -5,8 +5,8 @@ use ammonia::Builder;
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use diesel::prelude::*; use diesel::prelude::*;
use itertools::Itertools; use itertools::Itertools;
use lazy_static::lazy_static;
use log::info; use log::info;
use once_cell::sync::Lazy;
use pulldown_cmark::{Options, Parser}; use pulldown_cmark::{Options, Parser};
use rand::seq::SliceRandom; use rand::seq::SliceRandom;
use std::iter; use std::iter;
@ -52,15 +52,25 @@ struct InsertPaste {
exit_code: Option<i32>, exit_code: Option<i32>,
} }
#[derive(Default)]
pub struct ExtraPasteParameters {
pub stdin: String,
pub stdout: Option<String>,
pub stderr: Option<String>,
pub exit_code: Option<i32>,
}
pub fn insert( pub fn insert(
connection: &Connection, connection: &Connection,
delete_at: Option<DateTime<Utc>>, delete_at: Option<DateTime<Utc>>,
language: &str, language: &str,
paste: String, paste: String,
stdin: String, ExtraPasteParameters {
stdout: Option<String>, stdin,
stderr: Option<String>, stdout,
exit_code: Option<i32>, stderr,
exit_code,
}: ExtraPasteParameters,
) -> Result<String, Rejection> { ) -> Result<String, Rejection> {
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
let identifier: String = (0..10) let identifier: String = (0..10)
@ -75,13 +85,13 @@ pub fn insert(
.ok_or_else(|| warp::reject::custom(CustomRejection::UnrecognizedLanguageIdentifier))?; .ok_or_else(|| warp::reject::custom(CustomRejection::UnrecognizedLanguageIdentifier))?;
for (field, name) in &[(&paste, "paste"), (&stdin, "stdin")] { for (field, name) in &[(&paste, "paste"), (&stdin, "stdin")] {
if field.len() > 1_000_000 { if field.len() > 1_000_000 {
Err(warp::reject::custom(CustomRejection::FieldTooLarge(name)))?; return Err(warp::reject::custom(CustomRejection::FieldTooLarge(name)));
} }
} }
for (field, name) in &[(&stdout, "stdout"), (&stderr, "stderr")] { for (field, name) in &[(&stdout, "stdout"), (&stderr, "stderr")] {
if let Some(field) = field { if let Some(field) = field {
if field.len() > 1_000_000 { if field.len() > 1_000_000 {
Err(warp::reject::custom(CustomRejection::FieldTooLarge(name)))?; return Err(warp::reject::custom(CustomRejection::FieldTooLarge(name)));
} }
} }
} }
@ -144,8 +154,7 @@ impl ExternPaste {
} }
fn render_markdown(markdown: &str) -> String { fn render_markdown(markdown: &str) -> String {
lazy_static! { static FILTER: Lazy<Builder<'static>> = Lazy::new(|| {
static ref FILTER: Builder<'static> = {
let mut builder = Builder::new(); let mut builder = Builder::new();
builder.link_rel(Some("noopener noreferrer nofollow")); builder.link_rel(Some("noopener noreferrer nofollow"));
builder.add_generic_attributes(iter::once("class")); builder.add_generic_attributes(iter::once("class"));
@ -163,8 +172,7 @@ fn render_markdown(markdown: &str) -> String {
} }
}); });
builder builder
}; });
}
let mut output = String::new(); let mut output = String::new();
let options = Options::ENABLE_TABLES | Options::ENABLE_STRIKETHROUGH; let options = Options::ENABLE_TABLES | Options::ENABLE_STRIKETHROUGH;
pulldown_cmark::html::push_html(&mut output, Parser::new_ext(markdown, options)); pulldown_cmark::html::push_html(&mut output, Parser::new_ext(markdown, options));

View File

@ -1,4 +1,4 @@
use crate::models::paste; use crate::models::paste::{self, ExtraPasteParameters};
use crate::{blocking, Connection}; use crate::{blocking, Connection};
use chrono::{Duration, Utc}; use chrono::{Duration, Utc};
use futures::Future; use futures::Future;
@ -68,10 +68,12 @@ pub fn insert_paste(
expiration.map(|expiration| Utc::now() + expiration.0), expiration.map(|expiration| Utc::now() + expiration.0),
&language, &language,
code, code,
"".into(), ExtraPasteParameters {
None, stdin: "".into(),
None, stdout: None,
None, stderr: None,
exit_code: None,
},
) )
}) })
.compat() .compat()

View File

@ -1,4 +1,5 @@
use crate::models::paste; use crate::models::paste;
use crate::models::paste::ExtraPasteParameters;
use crate::{blocking, Connection}; use crate::{blocking, Connection};
use chrono::{Duration, Utc}; use chrono::{Duration, Utc};
use futures::Future; use futures::Future;
@ -40,10 +41,12 @@ pub fn insert_paste(
delete_at, delete_at,
&language, &language,
code, code,
ExtraPasteParameters {
stdin, stdin,
stdout, stdout,
stderr, stderr,
status, exit_code: status,
},
)?; )?;
Ok(reply::with_header( Ok(reply::with_header(
StatusCode::SEE_OTHER, StatusCode::SEE_OTHER,

View File

@ -212,7 +212,7 @@ mod test {
use crate::migration; use crate::migration;
use diesel::r2d2::{ConnectionManager, CustomizeConnection, Pool}; use diesel::r2d2::{ConnectionManager, CustomizeConnection, Pool};
use diesel::Connection; use diesel::Connection;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use scraper::{Html, Selector}; use scraper::{Html, Selector};
use serde::Deserialize; use serde::Deserialize;
use std::env; use std::env;
@ -223,8 +223,7 @@ mod test {
use warp::reply::{Reply, Response}; use warp::reply::{Reply, Response};
use warp::Filter; use warp::Filter;
lazy_static! { static ROUTES: Lazy<BoxedFilter<(Response,)>> = Lazy::new(|| {
static ref ROUTES: BoxedFilter<(Response,)> = {
let pool = Pool::builder() let pool = Pool::builder()
.connection_customizer(Box::new(ExecuteWithinTransaction)) .connection_customizer(Box::new(ExecuteWithinTransaction))
.max_size(1) .max_size(1)
@ -235,8 +234,7 @@ mod test {
diesel_migrations::run_pending_migrations(&pool.get().unwrap()).unwrap(); diesel_migrations::run_pending_migrations(&pool.get().unwrap()).unwrap();
migration::run(&pool.get().unwrap()).unwrap(); migration::run(&pool.get().unwrap()).unwrap();
routes(pool).map(Reply::into_response).boxed() routes(pool).map(Reply::into_response).boxed()
}; });
}
#[derive(Debug)] #[derive(Debug)]
struct ExecuteWithinTransaction; struct ExecuteWithinTransaction;

View File

@ -3,16 +3,14 @@ use crate::{blocking, Connection};
use diesel::prelude::*; use diesel::prelude::*;
use futures::Future; use futures::Future;
use futures03::TryFutureExt; use futures03::TryFutureExt;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use reqwest::r#async::Client; use reqwest::r#async::Client;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::env; use std::env;
use warp::{Rejection, Reply}; use warp::{Rejection, Reply};
lazy_static! { static CLIENT: Lazy<Client> = Lazy::new(Client::new);
static ref CLIENT: Client = Client::new(); static SANDBOX_URL: Lazy<String> = Lazy::new(|| env::var("SANDBOX_URL").unwrap());
static ref SANDBOX_URL: String = env::var("SANDBOX_URL").unwrap();
}
#[derive(Deserialize)] #[derive(Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]