Compare commits
3 Commits
47994c2bb2
...
3c8224cb4d
Author | SHA1 | Date | |
---|---|---|---|
3c8224cb4d | |||
7dd62b2cd7 | |||
31e894b6bc |
@ -27,8 +27,6 @@ docker compose up -d # might be docker-compose depending on distro
|
||||
|
||||
- you can optionally use the [docker image](https://git.jabuxas.xyz/jabuxas/-/packages/container/abyss/latest) directly and set it up how you want
|
||||
|
||||
- dont change inside port of 8999 unless you know what you're doing
|
||||
|
||||
### manual
|
||||
|
||||
- to run it manually, build it with `go build -o abyss` and run:
|
||||
@ -48,8 +46,10 @@ curl -F "file=@/path/to/file" -H "X-Auth: "$(cat /path/to/.key) http://localhost
|
||||
## docs
|
||||
|
||||
- `ABYSS_URL`: this is used for the correct formatting of the response of `curl`.
|
||||
- `AUTH_USERNAME | AUTH_PASSWORD`: this is used to access `http://localhost:8999/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
|
||||
|
||||
## todo:
|
||||
|
||||
|
30
abyss.go
30
abyss.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
@ -9,11 +10,6 @@ import (
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
const (
|
||||
filesDir = "./files"
|
||||
port = ":8999"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := new(Application)
|
||||
|
||||
@ -23,6 +19,8 @@ func main() {
|
||||
app.auth.password = os.Getenv("AUTH_PASSWORD")
|
||||
app.url = os.Getenv("ABYSS_URL")
|
||||
app.key = os.Getenv("UPLOAD_KEY")
|
||||
app.filesDir = os.Getenv("ABYSS_FILEDIR")
|
||||
app.port = os.Getenv("ABYSS_PORT")
|
||||
|
||||
if app.auth.username == "" {
|
||||
log.Fatal("basic auth username must be provided")
|
||||
@ -32,6 +30,26 @@ func main() {
|
||||
log.Fatal("basic auth password must be provided")
|
||||
}
|
||||
|
||||
if app.url == "" {
|
||||
slog.Warn("no root url detected, defaulting to localhost.")
|
||||
}
|
||||
|
||||
if app.key == "" {
|
||||
slog.Warn("no upload key detected")
|
||||
}
|
||||
|
||||
if app.filesDir == "" {
|
||||
slog.Warn("file dir is not set, running on default ./files")
|
||||
app.filesDir = "./files"
|
||||
}
|
||||
|
||||
if app.port == "" {
|
||||
slog.Info("running on default port")
|
||||
app.port = ":3235"
|
||||
} else {
|
||||
slog.Info("running on modified port")
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", app.fileHandler)
|
||||
mux.HandleFunc(
|
||||
@ -40,7 +58,7 @@ func main() {
|
||||
)
|
||||
|
||||
srv := &http.Server{
|
||||
Addr: port,
|
||||
Addr: app.port,
|
||||
Handler: mux,
|
||||
IdleTimeout: time.Minute,
|
||||
ReadTimeout: 10 * time.Second,
|
||||
|
@ -2,7 +2,7 @@ services:
|
||||
paste:
|
||||
image: git.jabuxas.xyz/jabuxas/abyss:latest
|
||||
ports:
|
||||
- "58080:8999"
|
||||
- "3235:3235"
|
||||
volumes:
|
||||
- ./files:/app/files
|
||||
restart: unless-stopped
|
||||
|
@ -5,6 +5,13 @@ read -p "Server domain name - this is the end url of where abyss will be hosted
|
||||
|
||||
read -p "Upload key - this is the key you will need to have to be able to make uploads to the server []: " -e UPLOAD_KEY
|
||||
|
||||
read -p "Files Directory - this is the dir location for storing the files [./files]: " -e ABYSS_FILEDIR
|
||||
if [ -z $ABYSS_FILEDIR ]; then
|
||||
ABYSS_FILEDIR="./files"
|
||||
fi
|
||||
|
||||
read -p "Server port - this is the port the server will run on; type just the port number. []: " -e ABYSS_PORT
|
||||
|
||||
read -p "Auth username - this is the username to access /tree (show all uploaded files) [admin]: " -e AUTH_USERNAME
|
||||
if [ -z $AUTH_USERNAME ]; then
|
||||
AUTH_USERNAME="admin"
|
||||
@ -19,6 +26,12 @@ cat << EOF > .env
|
||||
# This is the full name of the final domain for the server. Example: paste.abyss.dev
|
||||
ABYSS_URL=$ABYSS_URL
|
||||
|
||||
# Where abyss will store files. It's fine to leave it empty. Defaults to "./files"
|
||||
ABYSS_FILEDIR=$ABYSS_FILEDIR
|
||||
|
||||
# The port the server will run on, it's fine to leave it empty. Defaults to :3235
|
||||
ABYSS_PORT=:$ABYSS_PORT
|
||||
|
||||
# This is the username of the user for accessing /tree
|
||||
AUTH_USERNAME=$AUTH_USERNAME
|
||||
|
||||
|
14
handlers.go
14
handlers.go
@ -18,6 +18,8 @@ type Application struct {
|
||||
}
|
||||
url string
|
||||
key string
|
||||
filesDir string
|
||||
port string
|
||||
}
|
||||
|
||||
func (app *Application) fileHandler(w http.ResponseWriter, r *http.Request) {
|
||||
@ -27,7 +29,7 @@ func (app *Application) fileHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
name := filepath.Clean(r.URL.Path)
|
||||
path := filepath.Join(filesDir, name)
|
||||
path := filepath.Join(app.filesDir, name)
|
||||
|
||||
if !filepath.IsLocal(path) {
|
||||
http.Error(w, "Wrong url", http.StatusBadRequest)
|
||||
@ -42,7 +44,7 @@ func (app *Application) fileHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (app *Application) treeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
http.StripPrefix("/tree/", http.FileServer(http.Dir(filesDir))).ServeHTTP(w, r)
|
||||
http.StripPrefix("/tree/", http.FileServer(http.Dir(app.filesDir))).ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func (app *Application) uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
@ -63,8 +65,8 @@ func (app *Application) uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
if _, err := os.Stat(filesDir); err != nil {
|
||||
if err := os.Mkdir(filesDir, 0750); err != nil {
|
||||
if _, err := os.Stat(app.filesDir); err != nil {
|
||||
if err := os.Mkdir(app.filesDir, 0750); err != nil {
|
||||
http.Error(w, "Error creating storage directory", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
@ -73,7 +75,7 @@ func (app *Application) uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
filename := fmt.Sprintf("%d%s", time, filepath.Ext(handler.Filename))
|
||||
|
||||
filepath := fmt.Sprintf("%s/%s", filesDir, filename)
|
||||
filepath := fmt.Sprintf("%s/%s", app.filesDir, filename)
|
||||
|
||||
dst, err := os.Create(filepath)
|
||||
if err != nil {
|
||||
@ -86,7 +88,7 @@ func (app *Application) uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if app.url == "" {
|
||||
fmt.Fprintf(w, "http://localhost%s/%s\n", port, filename)
|
||||
fmt.Fprintf(w, "http://localhost%s/%s\n", app.port, filename)
|
||||
} else {
|
||||
fmt.Fprintf(w, "http://%s/%s\n", app.url, filename)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user