diff --git a/api.go b/api.go index f199baecd2ad97621e1cb65406041f6f181e4e63..4f329cdb068555c02ac9072e8871634ac1858c52 100644 --- a/api.go +++ b/api.go @@ -286,6 +286,30 @@ func registerAPI() { context.JSON(http.StatusOK, image) }) + router.GET(api.ImagePage, func(context *gin.Context) { + context.String(http.StatusOK, strconv.Itoa(instance.PageTotal(store.ImageRootPageVariant))) + }) + + router.GET(api.ImagePageField, func(context *gin.Context) { + param := context.Param("entry") + entry, err := strconv.Atoi(param) + if err != nil { + context.JSON(http.StatusBadRequest, api.Error{Error: err.Error()}) + return + } + context.JSON(http.StatusOK, instance.Page(store.ImageRootPageVariant, entry)) + }) + + router.GET(api.ImagePageImage, func(context *gin.Context) { + param := context.Param("entry") + entry, err := strconv.Atoi(param) + if err != nil { + context.JSON(http.StatusBadRequest, api.Error{Error: err.Error()}) + return + } + context.JSON(http.StatusOK, instance.PageImages(store.ImageRootPageVariant, entry)) + }) + router.GET(api.ImageField, func(context *gin.Context) { context.JSON(http.StatusOK, instance.ImageSnowflake(context.Param("flake"))) }) @@ -508,30 +532,6 @@ func registerAPI() { } instance.TagType(context.Param("tag"), payload.Type) }) - - router.GET(api.Page, func(context *gin.Context) { - context.String(http.StatusOK, strconv.Itoa(instance.PageTotal(store.ImageRootPageVariant))) - }) - - router.GET(api.PageField, func(context *gin.Context) { - param := context.Param("entry") - entry, err := strconv.Atoi(param) - if err != nil { - context.JSON(http.StatusBadRequest, api.Error{Error: err.Error()}) - return - } - context.JSON(http.StatusOK, instance.Page(store.ImageRootPageVariant, entry)) - }) - - router.GET(api.PageImage, func(context *gin.Context) { - param := context.Param("entry") - entry, err := strconv.Atoi(param) - if err != nil { - context.JSON(http.StatusBadRequest, api.Error{Error: err.Error()}) - return - } - context.JSON(http.StatusOK, instance.PageImages(store.ImageRootPageVariant, entry)) - }) } func getUser(context *gin.Context) (store.User, bool) { diff --git a/api/paths.go b/api/paths.go index 5738d9269a9e6ad08d59297372ee7510ed6a57b0..13fd58419bcbfd12b2b92d301b9a28bd7b860501 100644 --- a/api/paths.go +++ b/api/paths.go @@ -1,32 +1,32 @@ package api const ( - Base = "/api" - SingleUser = Base + "/single_user" - Image = Base + "/image" - ImageField = Image + "/:flake" - ImageFile = ImageField + "/file" - ImagePreview = ImageField + "/preview" - ImageTag = ImageField + "/tag" - ImageTagField = ImageTag + "/:tag" - Tag = Base + "/tag" - TagField = Tag + "/:tag" - TagInfo = TagField + "/info" - TagPage = TagField + "/page" - TagPageField = TagPage + "/:entry" - TagPageImage = TagPageField + "/image" - Page = Base + "/page" - PageField = Page + "/:entry" - PageImage = PageField + "/image" - Search = Base + "/search" - SearchField = Search + "/:tags" - User = Base + "/user" - UserThis = User + "/this" - UserField = User + "/:flake" - UserSecret = UserField + "/secret" - UserImage = UserField + "/image" - UserPassword = UserField + "/password" - Username = Base + "/username" - UsernameField = Username + "/:name" - UsernameAuth = UsernameField + "/auth" + Base = "/api" + SingleUser = Base + "/single_user" + Image = Base + "/image" + ImagePage = Image + "/page" + ImagePageField = ImagePage + "/:entry" + ImagePageImage = ImagePageField + "/image" + ImageField = Image + "/:flake" + ImageFile = ImageField + "/file" + ImagePreview = ImageField + "/preview" + ImageTag = ImageField + "/tag" + ImageTagField = ImageTag + "/:tag" + Tag = Base + "/tag" + TagField = Tag + "/:tag" + TagInfo = TagField + "/info" + TagPage = TagField + "/page" + TagPageField = TagPage + "/:entry" + TagPageImage = TagPageField + "/image" + Search = Base + "/search" + SearchField = Search + "/:tags" + User = Base + "/user" + UserThis = User + "/this" + UserField = User + "/:flake" + UserSecret = UserField + "/secret" + UserImage = UserField + "/image" + UserPassword = UserField + "/password" + Username = Base + "/username" + UsernameField = Username + "/:name" + UsernameAuth = UsernameField + "/auth" )