Julia Luna
2 years ago
commit
5e9c273773
13 changed files with 1616 additions and 0 deletions
@ -0,0 +1,4 @@
@@ -0,0 +1,4 @@
|
||||
filename: example.txt |
||||
more: meta data |
||||
--- |
||||
actual file contents |
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
[package] |
||||
name = "v" |
||||
version = "0.1.0" |
||||
edition = "2021" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
anyhow = "1.0.68" |
||||
axum = "0.6.1" |
||||
dashmap = "5.4.0" |
||||
lazy_static = "1.4.0" |
||||
nanoid = "0.4.0" |
||||
parking_lot = "0.12.1" |
||||
serde = { version = "1.0.152", features = ["derive", "serde_derive"] } |
||||
tera = "1.17.1" |
||||
tokio = { version = "1.23.0", features = ["full"] } |
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
^V |
||||
--- |
||||
|
||||
the dead simple |
||||
- link shortener |
||||
- file paste |
||||
- image paste |
||||
- text paste |
||||
|
||||
## design goals |
||||
|
||||
- no database |
||||
- easily browsable file structure |
||||
- near zero setup time |
||||
- perform well even without a caching reverse proxy |
||||
|
||||
## env vars |
||||
|
||||
- `DATA_DIR` |
||||
- `LISTEN_ADDR` |
||||
- `FILE_CACHE_MAX_SIZE` |
||||
- `FILE_UPLOAD_MAX_SIZE` |
||||
- `` |
@ -0,0 +1,11 @@
@@ -0,0 +1,11 @@
|
||||
use axum::{routing::get, Router}; |
||||
|
||||
pub(crate) fn routes() -> Router { |
||||
Router::new() |
||||
.route("/t/:id", get(todo!())) |
||||
.route("/f/:id", get(todo!())) |
||||
.route("/l/:id", get(todo!())) |
||||
.route("/text/:id", get(todo!())) |
||||
.route("/file/:id", get(todo!())) |
||||
.route("/link/:id", get(todo!())) |
||||
} |
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
use std::{collections::HashMap, net::SocketAddr, path::PathBuf}; |
||||
|
||||
use axum::{routing::get, Router}; |
||||
use dashmap::DashMap; |
||||
use parking_lot::RwLock; |
||||
use serde::{Deserialize, Serialize}; |
||||
|
||||
use lazy_static::lazy_static; |
||||
use tera::Tera; |
||||
|
||||
mod down; |
||||
mod up; |
||||
|
||||
lazy_static! { |
||||
pub static ref TEMPLATES: Tera = { |
||||
let tera = Tera::new(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*.html")) |
||||
.expect("Parsing error(s):"); |
||||
|
||||
tera |
||||
}; |
||||
} |
||||
|
||||
struct TextPaste { |
||||
pub text: String, |
||||
pub meta: HashMap<String, String>, |
||||
} |
||||
|
||||
struct FileMeta { |
||||
file_name: String, |
||||
} |
||||
|
||||
struct DataStorage { |
||||
links: DashMap<String, String>, |
||||
text: DashMap<String, TextPaste>, |
||||
files: DashMap<String, FileMeta>, |
||||
} |
||||
|
||||
struct AppState { |
||||
alphabet: Box<[char; 32]>, |
||||
id_length: usize, |
||||
cache: DataStorage, |
||||
base_dir: PathBuf, |
||||
} |
||||
|
||||
impl AppState { |
||||
|
||||
} |
||||
|
||||
fn routes() -> Router { |
||||
let up = up::routes(); |
||||
let down = down::routes(); |
||||
Router::new() |
||||
.route("/", get(|| async { "Hello, World!" })) |
||||
.merge(down) |
||||
.nest("/up", up) |
||||
} |
||||
|
||||
#[tokio::main] |
||||
async fn main() -> anyhow::Result<()> { |
||||
let addr: SocketAddr = std::env::var("LISTEN_ADDR") |
||||
.unwrap_or("127.0.0.1:8080".to_string()) |
||||
.parse() |
||||
.expect("parse error"); |
||||
|
||||
let app = routes(); |
||||
|
||||
axum::Server::bind(&addr) |
||||
.serve(app.into_make_service()) |
||||
.await?; |
||||
|
||||
Ok(()) |
||||
} |
@ -0,0 +1,8 @@
@@ -0,0 +1,8 @@
|
||||
use axum::{routing::post, Router}; |
||||
|
||||
pub(crate) fn routes() -> Router { |
||||
Router::new() |
||||
.route("/text", post(todo!())) |
||||
.route("/file", post(todo!())) |
||||
.route("/link", post(todo!())) |
||||
} |
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html> |
||||
<html lang="en"> |
||||
<head> |
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
||||
<title>^V - the everything paste bin</title> |
||||
<meta name="description" content="^V - paste bin"/> |
||||
<meta name="author" content="xenua" /> |
||||
<meta name="keywords" content="keywords" /> |
||||
<link rel="stylesheet" href="static/main.css" type="text/css" /> |
||||
</head> |
||||
<body> |
||||
|
||||
</body> |
||||
</html> |
Loading…
Reference in new issue