mirror of
https://codeberg.org/video-prize-ranch/rimgo.git
synced 2025-12-13 19:55:21 +00:00
Seperate API from UI
This commit is contained in:
12
pages/apiClient.go
Normal file
12
pages/apiClient.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package pages
|
||||
|
||||
import (
|
||||
"codeberg.org/video-prize-ranch/rimgo/api"
|
||||
"codeberg.org/video-prize-ranch/rimgo/utils"
|
||||
)
|
||||
|
||||
var ApiClient *api.Client
|
||||
|
||||
func InitializeApiClient() {
|
||||
ApiClient = api.NewClient(utils.Config.ImgurId)
|
||||
}
|
||||
@@ -16,11 +16,11 @@ func HandleEmbed(c *fiber.Ctx) error {
|
||||
post, err := api.Album{}, error(nil)
|
||||
switch {
|
||||
case strings.HasPrefix(c.Path(), "/a"):
|
||||
post, err = api.FetchAlbum(c.Params("postID"))
|
||||
post, err = ApiClient.FetchAlbum(c.Params("postID"))
|
||||
case strings.HasPrefix(c.Path(), "/gallery"):
|
||||
post, err = api.FetchPosts(c.Params("postID"))
|
||||
post, err = ApiClient.FetchPosts(c.Params("postID"))
|
||||
default:
|
||||
post, err = api.FetchMedia(c.Params("postID"))
|
||||
post, err = ApiClient.FetchMedia(c.Params("postID"))
|
||||
}
|
||||
if err != nil && err.Error() == "ratelimited by imgur" {
|
||||
return c.Status(429).Render("errors/429", nil)
|
||||
|
||||
@@ -17,11 +17,11 @@ func HandlePost(c *fiber.Ctx) error {
|
||||
post, err := api.Album{}, error(nil)
|
||||
switch {
|
||||
case strings.HasPrefix(c.Path(), "/a"):
|
||||
post, err = api.FetchAlbum(c.Params("postID"))
|
||||
post, err = ApiClient.FetchAlbum(c.Params("postID"))
|
||||
case strings.HasPrefix(c.Path(), "/gallery"):
|
||||
post, err = api.FetchPosts(c.Params("postID"))
|
||||
post, err = ApiClient.FetchPosts(c.Params("postID"))
|
||||
default:
|
||||
post, err = api.FetchMedia(c.Params("postID"))
|
||||
post, err = ApiClient.FetchMedia(c.Params("postID"))
|
||||
}
|
||||
if err != nil && err.Error() == "ratelimited by imgur" {
|
||||
return c.Status(429).Render("errors/429", nil)
|
||||
@@ -36,7 +36,7 @@ func HandlePost(c *fiber.Ctx) error {
|
||||
comments := []api.Comment{}
|
||||
if post.SharedWithCommunity {
|
||||
c.Set("Cache-Control", "public,max-age=604800")
|
||||
comments, err = api.FetchComments(c.Params("postID"))
|
||||
comments, err = ApiClient.FetchComments(c.Params("postID"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package pages
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"codeberg.org/video-prize-ranch/rimgo/api"
|
||||
"codeberg.org/video-prize-ranch/rimgo/utils"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
@@ -29,7 +28,7 @@ func HandleTag(c *fiber.Ctx) error {
|
||||
displayPrevPage = false
|
||||
}
|
||||
|
||||
tag, err := api.FetchTag(c.Params("tag"), c.Query("sort"), page)
|
||||
tag, err := ApiClient.FetchTag(c.Params("tag"), c.Query("sort"), page)
|
||||
if err != nil && err.Error() == "ratelimited by imgur" {
|
||||
return c.Status(429).Render("errors/429", nil)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package pages
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"codeberg.org/video-prize-ranch/rimgo/api"
|
||||
"codeberg.org/video-prize-ranch/rimgo/utils"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
@@ -24,7 +23,7 @@ func HandleUser(c *fiber.Ctx) error {
|
||||
pageNumber = 0
|
||||
}
|
||||
|
||||
user, err := api.FetchUser(c.Params("userID"))
|
||||
user, err := ApiClient.FetchUser(c.Params("userID"))
|
||||
if err != nil && err.Error() == "ratelimited by imgur" {
|
||||
return c.Status(429).Render("errors/429", nil)
|
||||
}
|
||||
@@ -35,7 +34,7 @@ func HandleUser(c *fiber.Ctx) error {
|
||||
return c.Status(404).Render("errors/404", nil)
|
||||
}
|
||||
|
||||
submissions, err := api.FetchSubmissions(c.Params("userID"), "newest", page)
|
||||
submissions, err := ApiClient.FetchSubmissions(c.Params("userID"), "newest", page)
|
||||
if err != nil && err.Error() == "ratelimited by imgur" {
|
||||
c.Status(429)
|
||||
return c.Render("errors/429", nil)
|
||||
|
||||
Reference in New Issue
Block a user