2023-05-16 12:35:39 +00:00
|
|
|
package views
|
|
|
|
|
|
|
|
import (
|
2023-05-19 15:05:55 +00:00
|
|
|
"math"
|
2023-05-16 12:35:39 +00:00
|
|
|
"net/http"
|
2023-05-18 15:03:21 +00:00
|
|
|
"pixivfe/configs"
|
2023-05-16 12:35:39 +00:00
|
|
|
"pixivfe/handler"
|
2023-05-19 15:05:55 +00:00
|
|
|
"strconv"
|
2023-05-18 15:03:21 +00:00
|
|
|
"time"
|
2023-06-01 10:22:20 +00:00
|
|
|
"unicode"
|
2023-05-18 15:03:21 +00:00
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2023-05-16 12:35:39 +00:00
|
|
|
)
|
|
|
|
|
2023-06-01 10:22:20 +00:00
|
|
|
func capitalize(str string) string {
|
|
|
|
runes := []rune(str)
|
|
|
|
runes[0] = unicode.ToUpper(runes[0])
|
|
|
|
return string(runes)
|
|
|
|
}
|
|
|
|
|
2023-05-18 15:03:21 +00:00
|
|
|
var PC *models.PixivClient
|
|
|
|
|
2023-05-16 12:35:39 +00:00
|
|
|
func artwork_page(c *gin.Context) {
|
2023-05-18 15:03:21 +00:00
|
|
|
id := c.Param("id")
|
|
|
|
illust, _ := PC.GetArtworkByID(id)
|
|
|
|
related, _ := PC.GetRelatedArtworks(id)
|
2023-05-19 15:05:55 +00:00
|
|
|
artist_info, _ := PC.GetUserInformation(illust.UserID, 1)
|
2023-05-18 15:03:21 +00:00
|
|
|
|
2023-05-16 12:35:39 +00:00
|
|
|
c.HTML(http.StatusOK, "artwork.html", gin.H{
|
|
|
|
"Illust": illust,
|
|
|
|
"Related": related,
|
2023-05-18 15:03:21 +00:00
|
|
|
"Artist": artist_info,
|
2023-05-16 12:35:39 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-05-18 15:03:21 +00:00
|
|
|
// func index_page(c *gin.Context) {
|
|
|
|
// recommended, _ := handler.GetRecommendedIllust(c)
|
|
|
|
// ranking, _ := handler.GetRankingIllust(c, "day")
|
|
|
|
// spotlight := handler.GetSpotlightArticle(c)
|
|
|
|
// newest, _ := handler.GetNewestIllust(c)
|
|
|
|
// c.HTML(http.StatusOK, "index.html", gin.H{
|
|
|
|
// "Recommended": recommended,
|
|
|
|
// "Rankings": ranking,
|
|
|
|
// "Spotlights": spotlight,
|
|
|
|
// "Newest": newest,
|
|
|
|
// })
|
|
|
|
// }
|
2023-05-16 12:35:39 +00:00
|
|
|
|
2023-05-16 15:07:17 +00:00
|
|
|
func user_page(c *gin.Context) {
|
2023-05-18 15:03:21 +00:00
|
|
|
id := c.Param("id")
|
2023-05-19 15:05:55 +00:00
|
|
|
page, ok := c.GetQuery("page")
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
page = "1"
|
|
|
|
}
|
|
|
|
|
|
|
|
pageInt, _ := strconv.Atoi(page)
|
|
|
|
user, _ := PC.GetUserInformation(id, pageInt)
|
|
|
|
|
|
|
|
worksCount, _ := PC.GetUserArtworksCount(id)
|
2023-05-20 04:16:25 +00:00
|
|
|
pageLimit := math.Ceil(float64(worksCount)/float64(configs.Configs.PageItems)) + 1.0
|
2023-05-19 15:05:55 +00:00
|
|
|
|
|
|
|
c.HTML(http.StatusOK, "user.html", gin.H{"User": user, "PageLimit": int(pageLimit), "Page": pageInt})
|
2023-05-16 15:07:17 +00:00
|
|
|
}
|
|
|
|
|
2023-06-01 09:14:02 +00:00
|
|
|
func ranking_page(c *gin.Context) {
|
|
|
|
mode, ok := c.GetQuery("mode")
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
mode = "daily"
|
|
|
|
}
|
|
|
|
|
|
|
|
content, ok := c.GetQuery("content")
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
content = "all"
|
|
|
|
}
|
|
|
|
|
|
|
|
page, ok := c.GetQuery("page")
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
page = "1"
|
|
|
|
}
|
|
|
|
|
2023-06-01 14:36:47 +00:00
|
|
|
pageInt, _ := strconv.Atoi(page)
|
|
|
|
|
2023-06-01 09:14:02 +00:00
|
|
|
response, _ := PC.GetRanking(mode, content, page)
|
|
|
|
|
2023-06-01 10:22:20 +00:00
|
|
|
c.HTML(http.StatusOK, "rank.html", gin.H{"Items": response.Artworks,
|
|
|
|
"Mode": mode,
|
|
|
|
"Content": content,
|
2023-06-01 14:36:47 +00:00
|
|
|
"Page": pageInt})
|
2023-06-01 09:14:02 +00:00
|
|
|
}
|
|
|
|
|
2023-05-21 15:09:13 +00:00
|
|
|
func newestArtworksPage(c *gin.Context) {
|
|
|
|
worktype, ok := c.GetQuery("type")
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
worktype = "illust"
|
|
|
|
}
|
|
|
|
r18, ok := c.GetQuery("r18")
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
r18 = "false"
|
|
|
|
}
|
|
|
|
|
|
|
|
works, _ := PC.GetNewestArtworks(worktype, r18)
|
|
|
|
|
|
|
|
c.HTML(http.StatusOK, "list.html", gin.H{"Title": "Newest works from all users", "Items": works})
|
|
|
|
}
|
|
|
|
|
2023-06-02 12:57:55 +00:00
|
|
|
func tag_page(c *gin.Context) {
|
|
|
|
_ = c.Param("name")
|
|
|
|
|
|
|
|
c.HTML(http.StatusOK, "tag.html", gin.H{})
|
|
|
|
}
|
|
|
|
|
2023-05-18 15:03:21 +00:00
|
|
|
func NewPixivClient(timeout int) *models.PixivClient {
|
|
|
|
transport := &http.Transport{Proxy: http.ProxyFromEnvironment}
|
|
|
|
client := &http.Client{
|
|
|
|
Timeout: time.Duration(timeout) * time.Millisecond,
|
|
|
|
Transport: transport,
|
|
|
|
}
|
|
|
|
|
|
|
|
pc := &models.PixivClient{
|
|
|
|
Client: client,
|
|
|
|
Header: make(map[string]string),
|
|
|
|
Cookie: make(map[string]string),
|
|
|
|
Lang: "en",
|
|
|
|
}
|
|
|
|
|
|
|
|
return pc
|
|
|
|
}
|
|
|
|
|
2023-05-16 12:35:39 +00:00
|
|
|
func SetupRoutes(r *gin.Engine) {
|
2023-05-18 15:03:21 +00:00
|
|
|
PC = NewPixivClient(5000)
|
|
|
|
PC.SetSessionID(configs.Configs.PHPSESSID)
|
|
|
|
PC.SetUserAgent(configs.Configs.UserAgent)
|
|
|
|
// r.GET("/", index_page)
|
2023-05-16 12:35:39 +00:00
|
|
|
r.GET("artworks/:id", artwork_page)
|
2023-05-18 15:03:21 +00:00
|
|
|
r.GET("users/:id", user_page)
|
2023-05-21 15:09:13 +00:00
|
|
|
r.GET("newest", newestArtworksPage)
|
2023-06-01 09:14:02 +00:00
|
|
|
r.GET("ranking", ranking_page)
|
2023-06-02 12:57:55 +00:00
|
|
|
r.GET("tags/:name", tag_page)
|
2023-05-16 12:35:39 +00:00
|
|
|
}
|