Browse Source

write more code (also ew frontend)

xenua 2 years ago
parent
commit
f0717425fb
  1. 1
      .gitignore
  2. 4
      README.md
  3. 36
      src/main.rs
  4. 0
      static/main.css
  5. 66
      static/main.js
  6. 18
      templates/base.html
  7. 33
      templates/index.html

1
.gitignore vendored

@ -1 +1,2 @@
/target /target
.idea/

4
README.md

@ -7,6 +7,8 @@ the dead simple
- image paste - image paste
- text paste - text paste
"pastebin on estrogen" ~harmonia
## design goals ## design goals
- no database - no database
@ -20,4 +22,4 @@ the dead simple
- `LISTEN_ADDR` - `LISTEN_ADDR`
- `FILE_CACHE_MAX_SIZE` - `FILE_CACHE_MAX_SIZE`
- `FILE_UPLOAD_MAX_SIZE` - `FILE_UPLOAD_MAX_SIZE`
- `` - ``

36
src/main.rs

@ -2,7 +2,7 @@ mod data;
mod down; mod down;
mod up; mod up;
use std::net::SocketAddr; use std::{net::SocketAddr, path::PathBuf};
use axum::{routing::get, Router}; use axum::{routing::get, Router};
use lazy_static::lazy_static; use lazy_static::lazy_static;
@ -19,13 +19,45 @@ lazy_static! {
}; };
} }
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("DataStorage error")]
DataStorage(#[from] data::Error),
#[error("invalid env var")]
EnvVar,
}
struct AppState { struct AppState {
alphabet: Vec<char>, alphabet: Vec<char>,
id_length: usize, id_length: usize,
cache: DataStorage, cache: DataStorage,
} }
impl AppState {} impl AppState {
pub fn new() -> Result<Self, Error> {
let base_dir_string = std::env::var("V_BASE_DIR").or(Err(Error::EnvVar))?;
let id_length: usize = std::env::var("V_ID_LENGTH")
.unwrap_or("6".to_string())
.parse()
.or(Err(Error::EnvVar))?;
let alphabet = std::env::var("V_ID_ALPHABET")
.unwrap_or("abcdefghijkmnpqrstuwxyz123467890".to_string())
.chars()
.collect();
let base_dir = PathBuf::new();
base_dir.push(base_dir_string);
let mut cache = DataStorage::new(base_dir);
cache.init()?;
Ok(Self {
alphabet,
id_length,
cache,
})
}
}
fn routes() -> Router { fn routes() -> Router {
let up = up::routes(); let up = up::routes();

0
static/main.css

66
static/main.js

@ -0,0 +1,66 @@
// i dont know how to java script. if you do know how to,
// want to rewrite this into proper java script,
// and can do so without introducing any dependencies etc,
// email me at v-contrib @ xenua dot me
document.addEventListener('load', () => {
let replaceMe = document.querySelector("#scriptReplaceTarget");
// TODO
})
window.addEventListener('paste', (event) => {
handleDataTransfer(event.clipboardData);
});
handleDataTransfer = (data) => {
if (data.clipboardData.items) {
let item = data.clipboardData.items[0];
if (item.kind === 'string') {
item.getAsString((thing) => {
try {
let url = new URL(thing);
promptUser("you pasted a valid link; do you want to create a short link?", () => {
createShortLink(url);
}, () => {
initTextArea(thing);
});
} catch (e) {
initTextArea(thing);
}
})
} else {
uploadFile(item.getAsFile());
}
}
}
promptUser = (promptText, yesAction, noAction) => {
}
initTextArea = (initialContents) => {
}
uploadFile = (file) => {
}
onDropHandler = (event) => {
}
onDragEnterHandler = (event) => {
if (event.target.classList.contains("dropzone")) {
event.target.classList.add("dragover");
}
}
onDragLeaveHandler = (event) => {
if (event.target.classList.contains("dropzone")) {
event.target.classList.remove("dragover");
}
}
createShortLink = (url) => {
}

18
templates/base.html

@ -2,13 +2,25 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>^V - the everything paste bin</title> <title>{% block title %}^V - the everything paste bin{% endblock title %}</title>
<meta name="description" content="^V - paste bin"/> <meta name="description" content="^V - paste bin"/>
<meta name="author" content="xenua" /> <meta name="author" content="xenua" />
<meta name="keywords" content="keywords" /> <meta name="keywords" content="keywords" />
{% block head %}
<link rel="stylesheet" href="static/main.css" type="text/css" /> <link rel="stylesheet" href="static/main.css" type="text/css" />
{% endblock head %}
</head> </head>
<body> <body {% block bodytags %}{% endblock bodytags %}>
{% block body %}
<header>
{% block header %}{% endblock header %}
</header>
<main>
{% block main %}{% enblock main %}
</main>
<footer>
{% block footer %}{% endblock footer %}
</footer>
{% endblock body %}
</body> </body>
</html> </html>

33
templates/index.html

@ -0,0 +1,33 @@
{% extends "base.html" %}
{% block main %}
<div id="theBox">
<!-- <noscript id="scriptReplaceTarget">-->
<span class="logo">^V</span>
<div>
<span>
lets you upload files and images
<form method="post">
<input type="file" name="file" required>
<input type="submit" value="upload">
</form>
</span>
<span>
or create short links
<form method="post">
<label for="link">to</label>
<input type="url" name="link" placeholder="https://youtu.be/dQw4w9WgXcQ" required>
<input type="submit" value="create short link">
</form>
</span>
<form method="post">
<div>
<span>or share some text</span>
<input type="submit" value="upload text">
</div>
<textarea name="text" placeholder="text area meow" required></textarea>
</form>
</div>
<!-- </noscript>-->
</div>
{% endblock main %}
Loading…
Cancel
Save