Compare commits

..

No commits in common. "a572ca0d7cd8acd47cfd0c034336a5b608f5bf01" and "c33e3051367c23384511bac55bb98c1533455f3d" have entirely different histories.

5 changed files with 848 additions and 798 deletions

1562
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -13,11 +13,8 @@ chrono = "0.4"
clap = "2.33"
walkdir = "2"
juniper = "0.14"
serde = "1.0.103"
serde_json = "1.0.44"
actix-web = "2.0.0"
actix-rt = "1.0.0"
actix-cors = "0.2.0"
juniper_warp = "0.5.2"
warp = "0.1.8"
[dependencies.rusqlite]
version = "0.21.0"

View file

@ -2,15 +2,11 @@ extern crate juniper;
use crate::database::{DBLog, DBMessage};
use chrono::prelude::*;
use juniper::http::GraphQLRequest;
use juniper::Value::Null;
use juniper::{FieldError, FieldResult};
use std::collections::HashSet;
use std::convert::TryInto;
use std::sync::Arc;
use actix_cors::Cors;
use actix_web::{http, middleware, web, App, Error, HttpResponse, HttpServer};
use warp::Filter;
#[derive(Debug, juniper::GraphQLObject)]
#[graphql(description = "Paginated list of messages")]
@ -252,52 +248,18 @@ impl Mutation {}
type Schema = juniper::RootNode<'static, Query, Mutation>;
async fn graphql(
st: web::Data<Arc<GQLData>>,
data: web::Json<GraphQLRequest>,
) -> Result<HttpResponse, Error> {
let user = web::block(move || {
let res = data.execute(&st.schema, &st.context);
Ok::<_, serde_json::error::Error>(serde_json::to_string(&res)?)
})
.await?;
Ok(HttpResponse::Ok()
.content_type("application/json")
.body(user))
}
struct GQLData {
schema: Schema,
context: Context,
}
pub async fn server(bind: &str, databases: Vec<DBLog>) -> std::io::Result<()> {
// Create Juniper schema
pub fn server(databases: Vec<DBLog>) {
let schema = Schema::new(Query, Mutation);
let context = Context {
databases: databases.into_iter().map(from_db).collect(),
};
let data = std::sync::Arc::new(GQLData { schema, context });
let state = warp::any().map(move || Context {
databases: databases.clone().into_iter().map(from_db).collect(),
});
let graphql_filter = juniper_warp::make_graphql_filter(schema, state.boxed());
// Start http server
HttpServer::new(move || {
App::new()
.data(data.clone())
.wrap(middleware::Logger::default())
.wrap(
Cors::new()
.allowed_methods(vec!["GET", "POST", "OPTIONS"])
.allowed_headers(vec![
http::header::AUTHORIZATION,
http::header::ACCEPT,
http::header::CONTENT_TYPE,
])
.max_age(3600)
.finish(),
warp::serve(
warp::get2()
.and(warp::path("graphiql"))
.and(juniper_warp::graphiql_filter("/graphql"))
.or(warp::path("graphql").and(graphql_filter)),
)
.service(web::resource("/graphql").route(web::post().to(graphql)))
})
.bind(bind)?
.run()
.await
.run(([127, 0, 0, 1], 8080));
}

View file

@ -5,8 +5,7 @@ use clap::{App, Arg};
use database::scan_dbs;
use graphql::server;
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
fn main() -> std::io::Result<()> {
let cmd = App::new("Riplog")
.version("1.0")
.arg(
@ -22,13 +21,14 @@ async fn main() -> std::io::Result<()> {
.required(true)
.short("b")
.help("Address to bind to")
.default_value("127.0.0.1:8080"),
.default_value("127.0.0.1:9743")
.index(2),
)
.get_matches();
let basedir = cmd.value_of("basedir").unwrap();
let addr = cmd.value_of("bind").unwrap();
let logs = scan_dbs(basedir);
println!("Loaded data for {} workspaces", logs.len());
server(addr, logs).await
server(logs);
Ok(())
}

3
frontend/.gitignore vendored
View file

@ -1,3 +0,0 @@
node_modules
.cache
dist