49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"git.neunzweinull.com/jan/CCTV/config"
|
|
"git.neunzweinull.com/jan/CCTV/internal"
|
|
)
|
|
|
|
const (
|
|
CleanupInterval = 5 * time.Minute
|
|
)
|
|
|
|
func init() {
|
|
//Load the env file
|
|
config.LoadEnv()
|
|
|
|
//Initialize the log file
|
|
internal.InitLog()
|
|
|
|
//Initialize the Upload Directory
|
|
config.InitUploadDir()
|
|
|
|
//Start background cleanup for expired bans
|
|
go func() {
|
|
for {
|
|
time.Sleep(CleanupInterval)
|
|
internal.CleanupBans()
|
|
}
|
|
}()
|
|
}
|
|
|
|
func main() {
|
|
defer internal.CloseLog()
|
|
|
|
http.HandleFunc("/", internal.LandingHandler)
|
|
http.HandleFunc("/login", internal.LoginHandler)
|
|
http.HandleFunc("/dash", internal.AuthClientMiddleware(internal.DashboardHandler))
|
|
http.HandleFunc("/upload", internal.AuthMiddleware(internal.UploadHandler))
|
|
http.HandleFunc("/health", internal.HealthHandler)
|
|
|
|
http.HandleFunc("/uploads/", internal.AuthClientMiddleware(
|
|
internal.HandlerToHandlerFunc(http.StripPrefix("/uploads/", http.FileServer(http.Dir("./uploads")))),
|
|
))
|
|
|
|
http.ListenAndServe(":8080", nil)
|
|
}
|