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)",
]
[[package]]
name = "once_cell"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "opaque-debug"
version = "0.2.3"
@ -1204,9 +1209,9 @@ dependencies = [
"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)",
"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)",
"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)",
"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)",
@ -2508,6 +2513,7 @@ dependencies = [
"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_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 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"

View File

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

View File

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

1105
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@ -5,8 +5,8 @@ use ammonia::Builder;
use chrono::{DateTime, Utc};
use diesel::prelude::*;
use itertools::Itertools;
use lazy_static::lazy_static;
use log::info;
use once_cell::sync::Lazy;
use pulldown_cmark::{Options, Parser};
use rand::seq::SliceRandom;
use std::iter;
@ -52,15 +52,25 @@ struct InsertPaste {
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(
connection: &Connection,
delete_at: Option<DateTime<Utc>>,
language: &str,
paste: String,
stdin: String,
stdout: Option<String>,
stderr: Option<String>,
exit_code: Option<i32>,
ExtraPasteParameters {
stdin,
stdout,
stderr,
exit_code,
}: ExtraPasteParameters,
) -> Result<String, Rejection> {
let mut rng = rand::thread_rng();
let identifier: String = (0..10)
@ -75,13 +85,13 @@ pub fn insert(
.ok_or_else(|| warp::reject::custom(CustomRejection::UnrecognizedLanguageIdentifier))?;
for (field, name) in &[(&paste, "paste"), (&stdin, "stdin")] {
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")] {
if let Some(field) = field {
if field.len() > 1_000_000 {
Err(warp::reject::custom(CustomRejection::FieldTooLarge(name)))?;
return Err(warp::reject::custom(CustomRejection::FieldTooLarge(name)));
}
}
}
@ -144,27 +154,25 @@ impl ExternPaste {
}
fn render_markdown(markdown: &str) -> String {
lazy_static! {
static ref FILTER: Builder<'static> = {
let mut builder = Builder::new();
builder.link_rel(Some("noopener noreferrer nofollow"));
builder.add_generic_attributes(iter::once("class"));
builder.attribute_filter(|_, attribute, value| {
if attribute == "class" {
Some(
value
.split_ascii_whitespace()
.filter(|value| value.starts_with("language-"))
.join(" ")
.into(),
)
} else {
Some(value.into())
}
});
builder
};
}
static FILTER: Lazy<Builder<'static>> = Lazy::new(|| {
let mut builder = Builder::new();
builder.link_rel(Some("noopener noreferrer nofollow"));
builder.add_generic_attributes(iter::once("class"));
builder.attribute_filter(|_, attribute, value| {
if attribute == "class" {
Some(
value
.split_ascii_whitespace()
.filter(|value| value.starts_with("language-"))
.join(" ")
.into(),
)
} else {
Some(value.into())
}
});
builder
});
let mut output = String::new();
let options = Options::ENABLE_TABLES | Options::ENABLE_STRIKETHROUGH;
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 chrono::{Duration, Utc};
use futures::Future;
@ -68,10 +68,12 @@ pub fn insert_paste(
expiration.map(|expiration| Utc::now() + expiration.0),
&language,
code,
"".into(),
None,
None,
None,
ExtraPasteParameters {
stdin: "".into(),
stdout: None,
stderr: None,
exit_code: None,
},
)
})
.compat()

View File

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

View File

@ -201,8 +201,8 @@ fn not_found(pool: PgPool) -> impl Clone + Fn(Rejection) -> NotFoundFuture {
Err(rejection)
}
}
.boxed()
.compat()
.boxed()
.compat()
}
}
@ -212,7 +212,7 @@ mod test {
use crate::migration;
use diesel::r2d2::{ConnectionManager, CustomizeConnection, Pool};
use diesel::Connection;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use scraper::{Html, Selector};
use serde::Deserialize;
use std::env;
@ -223,20 +223,18 @@ mod test {
use warp::reply::{Reply, Response};
use warp::Filter;
lazy_static! {
static ref ROUTES: BoxedFilter<(Response,)> = {
let pool = Pool::builder()
.connection_customizer(Box::new(ExecuteWithinTransaction))
.max_size(1)
.build(ConnectionManager::new(env::var("DATABASE_URL").expect(
"Setting DATABASE_URL environment variable required to run tests",
)))
.expect("Couldn't create a connection connection");
diesel_migrations::run_pending_migrations(&pool.get().unwrap()).unwrap();
migration::run(&pool.get().unwrap()).unwrap();
routes(pool).map(Reply::into_response).boxed()
};
}
static ROUTES: Lazy<BoxedFilter<(Response,)>> = Lazy::new(|| {
let pool = Pool::builder()
.connection_customizer(Box::new(ExecuteWithinTransaction))
.max_size(1)
.build(ConnectionManager::new(env::var("DATABASE_URL").expect(
"Setting DATABASE_URL environment variable required to run tests",
)))
.expect("Couldn't create a connection connection");
diesel_migrations::run_pending_migrations(&pool.get().unwrap()).unwrap();
migration::run(&pool.get().unwrap()).unwrap();
routes(pool).map(Reply::into_response).boxed()
});
#[derive(Debug)]
struct ExecuteWithinTransaction;

View File

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