2021-08-31 19:07:19 +05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
log.SetOutput(os.Stderr)
|
2021-09-22 19:04:46 +05:00
|
|
|
log.SetFormatter(&log.TextFormatter{ForceColors: true, DisableTimestamp: true})
|
2021-08-31 19:07:19 +05:00
|
|
|
log.SetLevel(log.ErrorLevel)
|
|
|
|
|
|
|
|
err := initConfig()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("initConfig:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.SetLevel(config.LogLevel)
|
|
|
|
|
|
|
|
err = initTemplates()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("initTemplates:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.RemoveFilePeriod > 0 {
|
2024-07-10 16:16:51 +05:00
|
|
|
go removeOldFilesThread(time.Duration(config.RemoveFilePeriod) * time.Hour)
|
2021-08-31 19:07:19 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
http.HandleFunc("/", HandleRoot)
|
2021-09-22 19:09:26 +05:00
|
|
|
http.HandleFunc("/icon", HandleIcon)
|
2021-08-31 19:07:19 +05:00
|
|
|
http.HandleFunc("/upload", HandleUpload)
|
|
|
|
http.HandleFunc("/download", HandleDownload)
|
2021-10-10 12:16:37 +05:00
|
|
|
http.HandleFunc("/stream", HandleStream)
|
2021-08-31 19:07:19 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
go func() {
|
|
|
|
err := http.ListenAndServe(config.ListenAddress, nil)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
c := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
|
|
|
|
|
|
|
<-c
|
|
|
|
log.Debugln("Stop signal received.")
|
|
|
|
}
|