Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
9960febb4a
|
|||
0d80322526
|
|||
c112dd7407
|
|||
aaf2bce03c
|
|||
d4b2f1ffbc
|
|||
faef1469f8
|
|||
c2f93e5aea
|
@@ -3,12 +3,11 @@ name: default
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build
|
- name: build
|
||||||
image: rust:1.37.0-buster
|
image: rust:1.41.0-buster
|
||||||
commands:
|
commands:
|
||||||
- apt update && apt install git clang make pkg-config nettle-dev libssl-dev capnproto libsqlite3-dev -y
|
- apt update && apt install git clang make pkg-config nettle-dev libssl-dev capnproto libsqlite3-dev -y
|
||||||
- cargo test
|
- cargo test
|
||||||
- rustup target add x86_64-unknown-linux-musl
|
- cargo install --path . --root .
|
||||||
- cargo build --release --target x86_64-unknown-linux-musl
|
|
||||||
- name: dockerize
|
- name: dockerize
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
settings:
|
settings:
|
||||||
|
645
Cargo.lock
generated
645
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "brownpaper"
|
name = "brownpaper"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
authors = ["shim_ <shimun@shimun.net>"]
|
authors = ["shimun <shimun@shimun.net>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@@ -4,6 +4,6 @@ VOLUME /snips
|
|||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
COPY target/release/brownpaper /bin/
|
COPY bin/brownpaper /bin/
|
||||||
|
|
||||||
ENTRYPOINT [ "/bin/brownpaper" ]
|
ENTRYPOINT [ "/bin/brownpaper" ]
|
||||||
|
35
src/main.rs
35
src/main.rs
@@ -10,29 +10,23 @@ mod chacha_io;
|
|||||||
mod pgp;
|
mod pgp;
|
||||||
mod snippet;
|
mod snippet;
|
||||||
|
|
||||||
use crate::snippet::*;
|
|
||||||
use crate::pgp::KnownKeys;
|
use crate::pgp::KnownKeys;
|
||||||
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
|
use crate::snippet::*;
|
||||||
use chacha_io::{ChaChaReader, ChaChaWriter};
|
|
||||||
use chrono::*;
|
|
||||||
use core::cell::RefCell;
|
|
||||||
use iron::method::Method;
|
use iron::method::Method;
|
||||||
use iron::modifiers::Redirect;
|
use iron::modifiers::Redirect;
|
||||||
use iron::prelude::*;
|
use iron::prelude::*;
|
||||||
use iron::url::Url;
|
use iron::url::Url;
|
||||||
use rand::Rng;
|
|
||||||
use sha2::{Digest, Sha256};
|
use iron::mime::Mime;
|
||||||
use std::borrow::BorrowMut;
|
use sha2::Digest;
|
||||||
use std::convert::TryInto;
|
|
||||||
use std::fs;
|
|
||||||
use std::fs::File;
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::Path;
|
||||||
use std::sync::Mutex;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
const STORAGE_DIR: &str = "/snips";
|
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| {
|
let att = storage.open(&id).map(|snip| snip.contents()).map(|res| {
|
||||||
Response::with(
|
Response::with(
|
||||||
match res.map(|text| (iron::status::Ok, text)).map_err(|err| {
|
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),
|
Err(e) => (iron::status::InternalServerError, e),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
.set(mime)
|
||||||
});
|
});
|
||||||
Ok(att.unwrap_or(Response::with((iron::status::NotFound, "Not here sry"))))
|
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 crate::chacha_io::{ChaChaReader, ChaChaWriter};
|
||||||
|
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use chrono::*;
|
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 rand::Rng;
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use std::borrow::BorrowMut;
|
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::fs;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::Mutex;
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub struct Snippet<'a> {
|
pub struct Snippet<'a> {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
@@ -87,7 +80,7 @@ impl<'a> Snippet<'a> {
|
|||||||
hdl.read_exact(&mut comp)?;
|
hdl.read_exact(&mut comp)?;
|
||||||
let comp = String::from_utf8(comp).unwrap();
|
let comp = String::from_utf8(comp).unwrap();
|
||||||
Ok(SnippetMeta {
|
Ok(SnippetMeta {
|
||||||
created: Utc.timestamp_millis(timestamp),
|
created: Utc.timestamp(timestamp, 0),
|
||||||
compression: Some(comp).filter(|_| comp_len > 0),
|
compression: Some(comp).filter(|_| comp_len > 0),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -158,4 +151,3 @@ impl<'a> SnippetStorage<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user