maintenance

This commit is contained in:
Julian 2023-04-28 13:19:02 -04:00
parent 6f42483f16
commit 164811388f
Signed by: NotNite
GPG Key ID: BD91A5402CCEB08A
19 changed files with 130 additions and 64 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@ files/
.env
u.db*
upload-local.sh

42
Cargo.lock generated
View File

@ -154,10 +154,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "client"
version = "0.1.0"
[[package]]
name = "cpufeatures"
version = "0.2.5"
@ -964,25 +960,6 @@ dependencies = [
"serde",
]
[[package]]
name = "server"
version = "0.1.0"
dependencies = [
"anyhow",
"async-trait",
"axum",
"dotenvy",
"hyper",
"mime_guess",
"nanoid",
"serde",
"sqlx",
"tokio",
"tokio-stream",
"tower",
"tower-http",
]
[[package]]
name = "sha1"
version = "0.10.5"
@ -1366,6 +1343,25 @@ version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
[[package]]
name = "u"
version = "0.1.0"
dependencies = [
"anyhow",
"async-trait",
"axum",
"dotenvy",
"hyper",
"mime_guess",
"nanoid",
"serde",
"sqlx",
"tokio",
"tokio-stream",
"tower",
"tower-http",
]
[[package]]
name = "unicase"
version = "2.6.0"

View File

@ -1,2 +1,21 @@
[workspace]
members = ["client", "server"]
[package]
name = "u"
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.69"
async-trait = "0.1.65"
axum = { version = "0.6.10", features = ["multipart", "headers"] }
dotenvy = "0.15.6"
hyper = "0.14.24"
mime_guess = "2.0.4"
nanoid = "0.4.0"
serde = { version = "1.0.152", features = ["derive"] }
sqlx = { version = "0.6.2", features = ["sqlite", "runtime-tokio-rustls"] }
tokio = { version = "1.26.0", features = ["full"] }
tokio-stream = { version = "0.1.12", features = ["net"] }
tower = "0.4.13"
tower-http = { version = "0.4.0", features = ["fs"] }

View File

@ -1,3 +1,76 @@
# u
blazingly-fast super-concurrent webscale file server
## setup
requirements:
- git
- rust toolchain
```sh
git clone https://git.n2.pm/NotNite/u.git
cd u
cat <<EOF >> .env
DATABASE_URL="sqlite:/somewhere/u.db"
U_PORT="8075"
U_FILES_DIR="/somewhere/files"
EOF
cargo build --release
```
on first run, it'll print out the admin key - keep that safe. you need it to create more API keys.
while losing the database isn't the end of the world (only contains API keys and revocation keys for files), obviously keep your files directory safe.
## setup (client)
requirements:
- api key for an existing u server
- coreutils, `curl`, `jq`, `xclip`
```sh
export U_API_KEY="..."
export U_HOST="https://.../"
export U_REVOCATION_KEY_PATH="$HOME/.u_revocation_keys"
./upload.sh /path/to/file
```
## using u
examples are with curl - you can (obviously) use any HTTP client.
### creating a new API key
```sh
curl -X POST -H "Authorization: $U_API_KEY" "$U_HOST/api/new_key"
```
requires an admin key to execute. you can give this API key to someone else so they can use your instance.
you can't modify API keys (delete or make admin) through the API - you'll have to open your database in your favorite sqlite client and edit the row manually.
### uploading a file
```sh
curl -F file=@/path/to/file -H "Authorization: $U_API_KEY" "$U_HOST/api/upload"
```
the `upload.sh` in this repository is just a wrapper around this curl command.
### deleting a file
```sh
curl -X DELETE "$U_HOST/i/$file_id?revocation_key=$revocation_key"
```
`file_id` and `revocation_key` are the values returned by the upload endpoint. if using `upload.sh`, the revocation key is stored in `$U_REVOCATION_KEY_PATH`.
### accessing files
files can be accessed with the URL `$U_HOST/i/$file_id`. you can add a file extension to the path if you want the server to return a specific mime type.

7
client/Cargo.lock generated
View File

@ -1,7 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "client"
version = "0.1.0"

View File

@ -1,8 +0,0 @@
[package]
name = "client"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -1,3 +0,0 @@
fn main() {
println!("Hello, world!");
}

View File

@ -1,21 +0,0 @@
[package]
name = "server"
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.69"
async-trait = "0.1.65"
axum = { version = "0.6.10", features = ["multipart", "headers"] }
dotenvy = "0.15.6"
hyper = "0.14.24"
mime_guess = "2.0.4"
nanoid = "0.4.0"
serde = { version = "1.0.152", features = ["derive"] }
sqlx = { version = "0.6.2", features = ["sqlite", "runtime-tokio-rustls"] }
tokio = { version = "1.26.0", features = ["full"] }
tokio-stream = { version = "0.1.12", features = ["net"] }
tower = "0.4.13"
tower-http = { version = "0.4.0", features = ["fs"] }

15
upload.sh Normal file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env sh
set -eux
path=$1
extension=$(echo "$path" | cut -d'.' -f2)
data=$(curl -F file=@$path -H "Authorization: $U_API_KEY" "$U_HOST/api/upload")
image_id=$(echo "$data" | jq -r .id)
image_revocation_key=$(echo "$data" | jq -r .revocation_key)
echo "$image_id $image_revocation_key" >> $U_REVOCATION_KEY_PATH
image_url="https://u.n2.pm/i/$image_id.$extension"
echo "$image_url"
echo "$image_url" | xclip -selection clipboard