pixivfe/main.go

83 lines
1.4 KiB
Go
Raw Normal View History

2023-05-13 03:34:31 +00:00
package main
import (
2023-05-13 12:25:32 +00:00
"html/template"
2023-05-18 13:18:44 +00:00
"pixivfe/configs"
2023-05-16 12:35:39 +00:00
"pixivfe/views"
"regexp"
"strconv"
2023-06-04 04:03:05 +00:00
"strings"
2023-05-13 03:34:31 +00:00
"github.com/gin-gonic/gin"
)
2023-05-16 12:35:39 +00:00
func setupRouter() *gin.Engine {
server := gin.Default()
2023-05-16 12:35:39 +00:00
2023-05-13 12:25:32 +00:00
server.SetFuncMap(template.FuncMap{
2023-05-16 12:35:39 +00:00
"inc": func(n int) int {
// For rankings to increment a number by 1
2023-05-16 12:35:39 +00:00
return n + 1
},
"add": func(a int, b int) int {
return a + b
},
"dec": func(n int) int {
return n - 1
},
"toInt": func(s string) int64 {
n, _ := strconv.ParseInt(s, 10, 32)
return n
},
"proxyImage": func(url string) string {
2023-06-04 04:03:05 +00:00
if strings.Contains(url, "s.pximg.net") {
// This subdomain didn't get proxied
return url
}
regex := regexp.MustCompile(`.*?pximg\.net`)
proxy := "https://" + configs.Configs.ImageProxyServer
return regex.ReplaceAllString(url, proxy)
},
"isEmpty": func(s string) bool {
return len(s) < 1
},
"isEmphasize": func(s string) bool {
switch s {
case
"R-18",
"R-18G":
return true
}
return false
},
2023-05-13 12:25:32 +00:00
})
2023-05-16 12:35:39 +00:00
// Static files
2023-05-14 12:30:03 +00:00
server.StaticFile("/favicon.ico", "./template/favicon.ico")
server.Static("css/", "./template/css")
2023-06-02 03:19:27 +00:00
server.Static("assets/", "./template/assets")
2023-05-16 12:35:39 +00:00
// HTML templates, automatically loaded
server.LoadHTMLGlob("template/*.html")
2023-05-16 12:35:39 +00:00
// Routes/Views
views.SetupRoutes(server)
return server
}
func main() {
2023-05-18 13:18:44 +00:00
configs.Configs.ReadConfig()
2023-05-16 12:35:39 +00:00
r := setupRouter()
r.Run(":8080")
2023-05-13 03:34:31 +00:00
}