Compare commits
2 Commits
00d2f3e510
...
c8b23c79b9
Author | SHA1 | Date | |
---|---|---|---|
c8b23c79b9 | |||
8afc49bd04 |
66
README.md
66
README.md
@ -38,27 +38,87 @@ docker compose up -d # might be docker-compose depending on distro
|
|||||||
|
|
||||||
## uploading
|
## uploading
|
||||||
|
|
||||||
- then, simply upload your files with curl:
|
#### with curl
|
||||||
|
|
||||||
|
- to upload your files with curl:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -F "file=@/path/to/file" -H "X-Auth: "$(cat /path/to/.key) http://localhost:3235/
|
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
|
## theming
|
||||||
|
|
||||||
- there is an example homepage in `static/` you can edit directly, which the server will serve automatically
|
- 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.
|
- 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/`
|
- 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
|
- 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
|
## docs
|
||||||
|
|
||||||
- `ABYSS_URL`: this is used for the correct formatting of the response of `curl`.
|
- `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.
|
- `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_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
|
- `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 files you will need authentication (same as `/tree`), anything other than that and upload is free for anyone
|
- `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
|
||||||
|
|
||||||
## todo:
|
## todo:
|
||||||
|
|
||||||
|
46
abyss.go
46
abyss.go
@ -13,6 +13,28 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
app := new(Application)
|
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()
|
err := godotenv.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Warn("no .env file detected, getting env from running process")
|
slog.Warn("no .env file detected, getting env from running process")
|
||||||
@ -25,7 +47,7 @@ func main() {
|
|||||||
app.filesDir = os.Getenv("ABYSS_FILEDIR")
|
app.filesDir = os.Getenv("ABYSS_FILEDIR")
|
||||||
app.port = os.Getenv("ABYSS_PORT")
|
app.port = os.Getenv("ABYSS_PORT")
|
||||||
|
|
||||||
auth := os.Getenv("SHOULD_AUTH")
|
app.authText = os.Getenv("SHOULD_AUTH")
|
||||||
|
|
||||||
if app.auth.username == "" {
|
if app.auth.username == "" {
|
||||||
log.Fatal("basic auth username must be provided")
|
log.Fatal("basic auth username must be provided")
|
||||||
@ -56,9 +78,11 @@ func main() {
|
|||||||
slog.Warn("no root url detected, defaulting to localhost.")
|
slog.Warn("no root url detected, defaulting to localhost.")
|
||||||
app.url = "localhost" + app.port
|
app.url = "localhost" + app.port
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
func setupHandlers(mux *http.ServeMux, app *Application) {
|
||||||
mux.HandleFunc("/", app.indexHandler)
|
mux.HandleFunc("/", app.indexHandler)
|
||||||
|
|
||||||
mux.Handle(
|
mux.Handle(
|
||||||
"/tree/",
|
"/tree/",
|
||||||
http.StripPrefix(
|
http.StripPrefix(
|
||||||
@ -66,26 +90,14 @@ func main() {
|
|||||||
app.basicAuth(app.fileListingHandler),
|
app.basicAuth(app.fileListingHandler),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
mux.HandleFunc("/last", app.lastUploadedHandler)
|
mux.HandleFunc("/last", app.lastUploadedHandler)
|
||||||
if auth == "yes" {
|
|
||||||
|
if app.authText == "yes" {
|
||||||
mux.HandleFunc("/upload", app.basicAuth(app.uploadHandler))
|
mux.HandleFunc("/upload", app.basicAuth(app.uploadHandler))
|
||||||
slog.Warn("text uploading through the browser will be restricted")
|
slog.Warn("text uploading through the browser will be restricted")
|
||||||
} else {
|
} else {
|
||||||
mux.HandleFunc("/upload", app.uploadHandler)
|
mux.HandleFunc("/upload", app.uploadHandler)
|
||||||
slog.Warn("text uploading through the browser will NOT be restricted")
|
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ type Application struct {
|
|||||||
key string
|
key string
|
||||||
filesDir string
|
filesDir string
|
||||||
port string
|
port string
|
||||||
|
authText string
|
||||||
lastUploadedFile string
|
lastUploadedFile string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user