Browse Source

initial meow

Julia Luna 2 years ago
commit
5e9c273773
Signed by: xenua
GPG Key ID: 6A0C04FA9A7D7582
  1. 0
      .data-example/accounts
  2. 0
      .data-example/files/id
  3. 1
      .data-example/files/id.meta
  4. 0
      .data-example/files/id_here/example.png
  5. 4
      .data-example/text/id
  6. 1
      .gitignore
  7. 1465
      Cargo.lock
  8. 17
      Cargo.toml
  9. 23
      README.md
  10. 11
      src/down.rs
  11. 72
      src/main.rs
  12. 8
      src/up.rs
  13. 14
      templates/base.html

0
.data-example/accounts

0
.data-example/files/id

1
.data-example/files/id.meta

@ -0,0 +1 @@ @@ -0,0 +1 @@
filename: example.png

0
.data-example/files/id_here/example.png

4
.data-example/text/id

@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
filename: example.txt
more: meta data
---
actual file contents

1
.gitignore vendored

@ -0,0 +1 @@ @@ -0,0 +1 @@
/target

1465
Cargo.lock generated

File diff suppressed because it is too large Load Diff

17
Cargo.toml

@ -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"] }

23
README.md

@ -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`
- ``

11
src/down.rs

@ -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!()))
}

72
src/main.rs

@ -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(())
}

8
src/up.rs

@ -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!()))
}

14
templates/base.html

@ -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…
Cancel
Save