Compare commits

..

No commits in common. "c8b23c79b99f0a3e9d015995574e16ab5ba08526" and "00d2f3e5109247b14e2434c54aa9db0b92a26219" have entirely different histories.

3 changed files with 20 additions and 93 deletions

View File

@ -38,87 +38,27 @@ docker compose up -d # might be docker-compose depending on distro
## uploading
#### with curl
- to upload your files with curl:
- then, simply upload your files with curl:
```bash
curl -F "file=@/path/to/file" -H "X-Auth: "$(cat /path/to/.key) http://localhost:3235/
```
- you should probably create an `alias` or a `function` to do this automatically for you.
<details>
<summary>click for an example for bash/zsh:</summary>
```bash
pst() {
local file
if [[ -p /dev/stdin ]]; then
file=$(mktemp)
cat > "$file"
elif [[ -n $1 ]]; then
file="$1"
else
echo "Usage: pst [file]"
return 1
fi
curl -F "file=@$file" -H "X-Auth: $(cat ~/.key)" https://paste.jabuxas.xyz
if [[ -p /dev/stdin ]]; then
rm "$file"
fi
}
```
</details>
<details>
<summary>click for an example for fish shell:</summary>
```bash
function pst
set -l file
if command test -p /dev/stdin
set file "/tmp/tmp.txt"
cat > $file
else if test -n "$argv[1]"
set file "$argv[1]"
end
curl -F "file=@$file" -H "X-Auth: $(cat ~/.key)" https://paste.jabuxas.xyz
if command test -p /dev/stdin
rm "$file"
end
end
```
</details>
#### through the browser
- you can only upload text through the browser, to do so, simply write text in the form in the default webpage and click upload.
- this upload can be restricted to need authentication or not, controlled by an environment variable.
## theming
- there is an example homepage in `static/` you can edit directly, which the server will serve automatically
- if running with docker, it's also possible to override `/static` inside the container with your own page.
- otherwise you will need to clone this repository and edit `static/` and `templates/` manually, or recreate the structure.
- same thing with templates in `templates/`
- it is preferred to use `dev/` for that reason, since it is git-ignored and that way makes it easier if wanting to update regularly without making changes to the tree
## docs
- `ABYSS_URL`: this is used for the correct formatting of the response of `curl`.
- `AUTH_USERNAME | AUTH_PASSWORD`: this is used to access `/tree`, which shows all uploaded files
- `AUTH_USERNAME | AUTH_PASSWORD`: this is used to access `/tree/`, which shows all uploaded files
- `UPLOAD_KEY`: this is key checked when uploading files. if the key doesn't match with server's one, then it refuses uploading.
- `ABYSS_FILEDIR`: this points to the directory where abyss will save the uploads to. defaults to `./files`
- `ABYSS_PORT`: this is the port the server will run on. safe to leave empty. defaults to 3235
- `SHOULD_AUTH`: if it is `yes`, then to upload text through the browser you will need authentication (same auth as `/tree`), any value other than that and upload is auth-less
- `SHOULD_AUTH`: if it is `yes`, then to upload files you will need authentication (same as `/tree`), anything other than that and upload is free for anyone
## todo:

View File

@ -13,28 +13,6 @@ import (
func main() {
app := new(Application)
parseEnv(app)
mux := http.NewServeMux()
setupHandlers(mux, app)
srv := &http.Server{
Addr: app.port,
Handler: mux,
IdleTimeout: 10 * time.Second,
ReadTimeout: 10 * time.Second,
WriteTimeout: 60 * time.Second,
}
log.Printf("starting server on %s", srv.Addr)
if err := srv.ListenAndServe(); err != nil {
log.Fatalf("Failed to start server: %v", err)
}
}
func parseEnv(app *Application) {
err := godotenv.Load()
if err != nil {
slog.Warn("no .env file detected, getting env from running process")
@ -47,7 +25,7 @@ func parseEnv(app *Application) {
app.filesDir = os.Getenv("ABYSS_FILEDIR")
app.port = os.Getenv("ABYSS_PORT")
app.authText = os.Getenv("SHOULD_AUTH")
auth := os.Getenv("SHOULD_AUTH")
if app.auth.username == "" {
log.Fatal("basic auth username must be provided")
@ -78,11 +56,9 @@ func parseEnv(app *Application) {
slog.Warn("no root url detected, defaulting to localhost.")
app.url = "localhost" + app.port
}
}
func setupHandlers(mux *http.ServeMux, app *Application) {
mux := http.NewServeMux()
mux.HandleFunc("/", app.indexHandler)
mux.Handle(
"/tree/",
http.StripPrefix(
@ -90,14 +66,26 @@ func setupHandlers(mux *http.ServeMux, app *Application) {
app.basicAuth(app.fileListingHandler),
),
)
mux.HandleFunc("/last", app.lastUploadedHandler)
if app.authText == "yes" {
if auth == "yes" {
mux.HandleFunc("/upload", app.basicAuth(app.uploadHandler))
slog.Warn("text uploading through the browser will be restricted")
} else {
mux.HandleFunc("/upload", app.uploadHandler)
slog.Warn("text uploading through the browser will NOT be restricted")
}
srv := &http.Server{
Addr: app.port,
Handler: mux,
IdleTimeout: time.Minute,
ReadTimeout: 10 * time.Second,
WriteTimeout: 60 * time.Second,
}
log.Printf("starting server on %s", srv.Addr)
if err := srv.ListenAndServe(); err != nil {
log.Fatalf("Failed to start server: %v", err)
}
}

View File

@ -22,7 +22,6 @@ type Application struct {
key string
filesDir string
port string
authText string
lastUploadedFile string
}