2024-04-27 12:16:43 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-04-27 12:25:21 +02:00
|
|
|
"embed"
|
2024-06-28 18:03:17 +02:00
|
|
|
"fmt"
|
2024-04-27 12:16:43 +02:00
|
|
|
"leech/config"
|
|
|
|
"leech/route"
|
2024-04-27 12:25:21 +02:00
|
|
|
"net/http"
|
2024-06-28 17:58:28 +02:00
|
|
|
"net/url"
|
2024-04-27 12:16:43 +02:00
|
|
|
|
|
|
|
"github.com/gofiber/fiber/v2"
|
2024-04-27 12:25:21 +02:00
|
|
|
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
2024-04-27 12:16:43 +02:00
|
|
|
"github.com/gofiber/fiber/v2/middleware/logger"
|
|
|
|
)
|
|
|
|
|
2024-04-27 12:25:21 +02:00
|
|
|
//go:embed assets/**
|
|
|
|
var assetsEmbed embed.FS
|
|
|
|
|
2024-04-27 12:16:43 +02:00
|
|
|
func main() {
|
2024-04-27 12:40:07 +02:00
|
|
|
config.Init()
|
2024-04-27 12:16:43 +02:00
|
|
|
app := fiber.New()
|
|
|
|
app.Use(logger.New(logger.Config{
|
|
|
|
Format: "[${ip}]:${port} ${status} - ${method} ${path}\n",
|
|
|
|
}))
|
|
|
|
|
2024-04-27 12:25:21 +02:00
|
|
|
app.Use("/assets", filesystem.New(filesystem.Config{
|
|
|
|
Root: http.FS(assetsEmbed),
|
|
|
|
PathPrefix: "assets",
|
|
|
|
Browse: true,
|
|
|
|
}))
|
2024-04-27 12:16:43 +02:00
|
|
|
|
2024-04-27 12:40:07 +02:00
|
|
|
for dirName, dirToServe := range config.Config.ServeDirs {
|
2024-06-28 18:03:17 +02:00
|
|
|
fmt.Println("Registering route /serve/" + url.QueryEscape(dirName))
|
2024-06-28 18:11:37 +02:00
|
|
|
app.Static("/serve/"+url.QueryEscape(dirName), dirToServe) // For some reason this doesn't work and this is not my fault.
|
2024-04-27 12:16:43 +02:00
|
|
|
}
|
|
|
|
|
2024-06-10 21:36:26 +02:00
|
|
|
app.Use("/thumb", route.HandleThumb)
|
|
|
|
|
2024-04-28 00:45:42 +02:00
|
|
|
app.Use("/", route.HandleList)
|
|
|
|
|
2024-04-27 12:40:07 +02:00
|
|
|
app.Listen(config.Config.Host)
|
2024-04-27 12:16:43 +02:00
|
|
|
}
|