2026-04-25 17:40:39 +03:00
|
|
|
package server
|
|
|
|
|
|
2026-04-25 18:04:10 +03:00
|
|
|
import (
|
2026-04-28 18:44:16 +03:00
|
|
|
"time"
|
|
|
|
|
|
2026-04-25 18:04:10 +03:00
|
|
|
"github.com/gin-contrib/gzip"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2026-04-25 17:40:39 +03:00
|
|
|
|
2026-04-28 18:44:16 +03:00
|
|
|
"warpbox/lib/boxstore"
|
|
|
|
|
"warpbox/lib/helpers"
|
2026-04-27 17:49:19 +03:00
|
|
|
"warpbox/lib/routing"
|
2026-04-27 17:33:52 +03:00
|
|
|
)
|
|
|
|
|
|
2026-04-25 17:40:39 +03:00
|
|
|
func Run(addr string) error {
|
|
|
|
|
router := gin.Default()
|
2026-04-25 18:04:10 +03:00
|
|
|
router.LoadHTMLGlob("templates/*.html")
|
2026-04-25 17:40:39 +03:00
|
|
|
|
2026-04-27 17:49:19 +03:00
|
|
|
routing.Register(router, routing.Handlers{
|
|
|
|
|
Index: handleIndex,
|
|
|
|
|
ShowBox: handleShowBox,
|
2026-04-27 18:18:53 +03:00
|
|
|
BoxLogin: handleBoxLogin,
|
|
|
|
|
BoxLoginPost: handleBoxLoginPost,
|
2026-04-27 17:49:19 +03:00
|
|
|
BoxStatus: handleBoxStatus,
|
|
|
|
|
DownloadBox: handleDownloadBox,
|
|
|
|
|
DownloadFile: handleDownloadFile,
|
2026-04-28 18:44:16 +03:00
|
|
|
DownloadThumbnail: handleDownloadThumbnail,
|
2026-04-27 17:49:19 +03:00
|
|
|
CreateBox: handleCreateBox,
|
|
|
|
|
ManifestFileUpload: handleManifestFileUpload,
|
|
|
|
|
FileStatusUpdate: handleFileStatusUpdate,
|
|
|
|
|
DirectBoxUpload: handleDirectBoxUpload,
|
|
|
|
|
LegacyUpload: handleLegacyUpload,
|
2026-04-25 18:46:16 +03:00
|
|
|
})
|
|
|
|
|
|
2026-04-25 18:04:10 +03:00
|
|
|
compressed := router.Group("/", gzip.Gzip(gzip.DefaultCompression))
|
|
|
|
|
compressed.Static("/static", "./static")
|
|
|
|
|
|
2026-04-28 18:44:16 +03:00
|
|
|
batchSize := helpers.EnvInt("WARPBOX_THUMBNAIL_BATCH_SIZE", 10, 1)
|
|
|
|
|
intervalSeconds := helpers.EnvInt("WARPBOX_THUMBNAIL_INTERVAL_SECONDS", 30, 1)
|
|
|
|
|
boxstore.StartThumbnailWorker(batchSize, time.Duration(intervalSeconds)*time.Second)
|
|
|
|
|
|
2026-04-25 17:40:39 +03:00
|
|
|
return router.Run(addr)
|
|
|
|
|
}
|