Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
9960febb4a
|
|||
0d80322526
|
|||
c112dd7407
|
|||
aaf2bce03c
|
|||
d4b2f1ffbc
|
|||
faef1469f8
|
|||
c2f93e5aea
|
@@ -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
645
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -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]
|
||||
|
@@ -4,6 +4,6 @@ VOLUME /snips
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
COPY target/release/brownpaper /bin/
|
||||
COPY bin/brownpaper /bin/
|
||||
|
||||
ENTRYPOINT [ "/bin/brownpaper" ]
|
||||
|
35
src/main.rs
35
src/main.rs
@@ -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"))))
|
||||
}
|
||||
|
@@ -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> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user