2024-08-25 23:15:11 -03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"time"
|
2024-09-03 21:51:36 -03:00
|
|
|
|
|
|
|
"github.com/joho/godotenv"
|
2024-08-25 23:15:11 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
filesDir = "./files"
|
2024-09-03 21:51:36 -03:00
|
|
|
port = ":8999"
|
2024-08-25 23:15:11 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := new(Application)
|
|
|
|
|
2024-09-03 21:51:36 -03:00
|
|
|
godotenv.Load()
|
|
|
|
|
2024-08-25 23:15:11 -03:00
|
|
|
app.auth.username = os.Getenv("AUTH_USERNAME")
|
|
|
|
app.auth.password = os.Getenv("AUTH_PASSWORD")
|
2024-09-03 21:51:36 -03:00
|
|
|
app.url = os.Getenv("ABYSS_URL")
|
|
|
|
app.key = os.Getenv("UPLOAD_KEY")
|
2024-08-25 23:15:11 -03:00
|
|
|
|
|
|
|
if app.auth.username == "" {
|
|
|
|
log.Fatal("basic auth username must be provided")
|
|
|
|
}
|
|
|
|
|
|
|
|
if app.auth.password == "" {
|
|
|
|
log.Fatal("basic auth password must be provided")
|
|
|
|
}
|
|
|
|
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
mux.HandleFunc("/", app.fileHandler)
|
|
|
|
mux.HandleFunc(
|
|
|
|
"/tree/",
|
|
|
|
app.basicAuth(app.treeHandler),
|
|
|
|
)
|
|
|
|
|
|
|
|
srv := &http.Server{
|
|
|
|
Addr: 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)
|
|
|
|
}
|
|
|
|
}
|