7 Commits

Author SHA1 Message Date
9960febb4a update 0.2.0
Some checks reported errors
continuous-integration/drone/tag Build encountered an error
continuous-integration/drone/push Build encountered an error
2020-02-17 00:15:27 +01:00
0d80322526 variable mime
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2020-02-17 00:07:09 +01:00
c112dd7407 fix date 2020-02-16 23:50:59 +01:00
aaf2bce03c silly idea 2020-02-16 23:34:32 +01:00
d4b2f1ffbc update image
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2020-02-15 18:12:01 +01:00
faef1469f8 test in debug
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2020-02-15 16:46:01 +01:00
c2f93e5aea allow user provided mime types
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2020-02-15 16:43:37 +01:00
6 changed files with 302 additions and 407 deletions

View File

@@ -3,12 +3,11 @@ name: default
steps:
- name: build
image: rust:1.37.0-buster
image: rust:1.41.0-buster
commands:
- apt update && apt install git clang make pkg-config nettle-dev libssl-dev capnproto libsqlite3-dev -y
- cargo test
- rustup target add x86_64-unknown-linux-musl
- cargo build --release --target x86_64-unknown-linux-musl
- cargo install --path . --root .
- name: dockerize
image: plugins/docker
settings:

645
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
[package]
name = "brownpaper"
version = "0.1.0"
authors = ["shim_ <shimun@shimun.net>"]
version = "0.2.0"
authors = ["shimun <shimun@shimun.net>"]
edition = "2018"
[dependencies]

View File

@@ -4,6 +4,6 @@ VOLUME /snips
EXPOSE 3000
COPY target/release/brownpaper /bin/
COPY bin/brownpaper /bin/
ENTRYPOINT [ "/bin/brownpaper" ]

View File

@@ -10,29 +10,23 @@ mod chacha_io;
mod pgp;
mod snippet;
use crate::snippet::*;
use crate::pgp::KnownKeys;
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use chacha_io::{ChaChaReader, ChaChaWriter};
use chrono::*;
use core::cell::RefCell;
use crate::snippet::*;
use iron::method::Method;
use iron::modifiers::Redirect;
use iron::prelude::*;
use iron::url::Url;
use rand::Rng;
use sha2::{Digest, Sha256};
use std::borrow::BorrowMut;
use std::convert::TryInto;
use std::fs;
use std::fs::File;
use iron::mime::Mime;
use sha2::Digest;
use std::io;
use std::io::prelude::*;
use std::iter::Iterator;
use std::path::{Path, PathBuf};
use std::sync::Mutex;
use std::path::Path;
use std::sync::Arc;
use std::sync::Mutex;
#[cfg(not(debug_assertions))]
const STORAGE_DIR: &str = "/snips";
@@ -100,7 +94,17 @@ fn handle(req: &mut Request) -> IronResult<Response> {
)))
}
}
(Method::Get, Some(id)) => {
(Method::Get, Some(path)) => {
let (id, mime) = {
let mut parts = path.split(".");
(
parts.next().unwrap().to_string(),
Some(parts.collect::<Vec<_>>().join("/"))
.filter(|s| s.len() > 0)
.and_then(|format| format.parse::<Mime>().ok()),
)
};
let mime = mime.unwrap_or("text/plain".parse().unwrap());
let att = storage.open(&id).map(|snip| snip.contents()).map(|res| {
Response::with(
match res.map(|text| (iron::status::Ok, text)).map_err(|err| {
@@ -111,6 +115,7 @@ fn handle(req: &mut Request) -> IronResult<Response> {
Err(e) => (iron::status::InternalServerError, e),
},
)
.set(mime)
});
Ok(att.unwrap_or(Response::with((iron::status::NotFound, "Not here sry"))))
}

View File

@@ -1,24 +1,17 @@
use crate::pgp::KnownKeys;
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use crate::chacha_io::{ChaChaReader, ChaChaWriter};
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use chrono::*;
use core::cell::RefCell;
use iron::method::Method;
use iron::modifiers::Redirect;
use iron::prelude::*;
use iron::url::Url;
use rand::Rng;
use sha2::{Digest, Sha256};
use std::borrow::BorrowMut;
use std::convert::TryInto;
use std::fs;
use std::fs::File;
use std::io;
use std::io::prelude::*;
use std::iter::Iterator;
use std::path::{Path, PathBuf};
use std::sync::Mutex;
use std::sync::Arc;
pub struct Snippet<'a> {
pub id: String,
@@ -87,7 +80,7 @@ impl<'a> Snippet<'a> {
hdl.read_exact(&mut comp)?;
let comp = String::from_utf8(comp).unwrap();
Ok(SnippetMeta {
created: Utc.timestamp_millis(timestamp),
created: Utc.timestamp(timestamp, 0),
compression: Some(comp).filter(|_| comp_len > 0),
})
}
@@ -158,4 +151,3 @@ impl<'a> SnippetStorage<'a> {
}
}
}