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"
|
2023-06-01 13:02:19 +00:00
|
|
|
"regexp"
|
2023-06-01 10:22:20 +00:00
|
|
|
"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 {
|
2023-05-13 10:03:13 +00:00
|
|
|
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 {
|
2023-05-19 05:15:27 +00:00
|
|
|
// For rankings to increment a number by 1
|
2023-05-16 12:35:39 +00:00
|
|
|
return n + 1
|
|
|
|
},
|
2023-05-19 15:05:55 +00:00
|
|
|
"add": func(a int, b int) int {
|
|
|
|
return a + b
|
|
|
|
},
|
|
|
|
|
|
|
|
"dec": func(n int) int {
|
|
|
|
return n - 1
|
|
|
|
},
|
2023-06-01 13:02:19 +00:00
|
|
|
|
2023-06-01 10:22:20 +00:00
|
|
|
"toInt": func(s string) int64 {
|
|
|
|
n, _ := strconv.ParseInt(s, 10, 32)
|
|
|
|
return n
|
|
|
|
},
|
2023-05-19 05:15:27 +00:00
|
|
|
|
2023-06-01 13:02:19 +00:00
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
2023-06-01 13:02:19 +00:00
|
|
|
regex := regexp.MustCompile(`.*?pximg\.net`)
|
|
|
|
proxy := "https://" + configs.Configs.ImageProxyServer
|
|
|
|
|
|
|
|
return regex.ReplaceAllString(url, proxy)
|
|
|
|
},
|
|
|
|
|
2023-05-19 05:15:27 +00:00
|
|
|
"isEmpty": func(s string) bool {
|
|
|
|
return len(s) < 1
|
|
|
|
},
|
2023-05-19 11:17:59 +00:00
|
|
|
|
|
|
|
"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")
|
2023-05-13 10:03:13 +00:00
|
|
|
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
|
2023-05-13 10:03:13 +00:00
|
|
|
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
|
|
|
}
|