diff --git a/pixiv/user.go b/pixiv/user.go index 6ea7c34..95b7a18 100644 --- a/pixiv/user.go +++ b/pixiv/user.go @@ -20,7 +20,7 @@ const ( UserArt_AnyAlt UserArtCategory = "artworks" UserArt_Illustration UserArtCategory = "illustrations" UserArt_Manga UserArtCategory = "manga" - UserArt_Bookmarked UserArtCategory = "bookmarks" // what this user has bookmarked; not art by this user + UserArt_Bookmarks UserArtCategory = "bookmarks" // what this user has bookmarked; not art by this user UserArt_Novel UserArtCategory = "novels" ) @@ -29,9 +29,9 @@ func (s UserArtCategory) Validate() error { s != UserArt_AnyAlt && s != UserArt_Illustration && s != UserArt_Manga && - s != UserArt_Bookmarked && + s != UserArt_Bookmarks && s != UserArt_Novel { - return fmt.Errorf("Invalid work category: %#v. "+`Only "%s", "%s", "%s", "%s", "%s" and "%s" are available`, s, UserArt_Any, UserArt_AnyAlt, UserArt_Illustration, UserArt_Manga, UserArt_Bookmarked, UserArt_Novel) + return fmt.Errorf("Invalid work category: %#v. "+`Only "%s", "%s", "%s", "%s", "%s" and "%s" are available`, s, UserArt_Any, UserArt_AnyAlt, UserArt_Illustration, UserArt_Manga, UserArt_Bookmarks, UserArt_Novel) } else { return nil } @@ -267,7 +267,7 @@ func GetUserArtwork(c *fiber.Ctx, id string, category UserArtCategory, page int, return user, err } - if category == "bookmarks" { + if category == UserArt_Bookmarks { // Bookmarks works, count, err := GetUserBookmarks(c, id, "show", page) if err != nil { @@ -278,7 +278,7 @@ func GetUserArtwork(c *fiber.Ctx, id string, category UserArtCategory, page int, // Public bookmarks count user.ArtworksCount = count - } else if category == "novels" { + } else if category == UserArt_Novel { ids, count, err := GetUserArtworksID(c, id, category, page) if err != nil { return user, err diff --git a/routes/artwork-multi.go b/routes/artworkMulti.go similarity index 96% rename from routes/artwork-multi.go rename to routes/artworkMulti.go index b980cbc..354b27c 100644 --- a/routes/artwork-multi.go +++ b/routes/artworkMulti.go @@ -58,7 +58,7 @@ func ArtworkMultiPage(c *fiber.Ctx) error { return err_global } - return c.Render("artwork-multi", fiber.Map{ + return c.Render("artworkMulti", fiber.Map{ "Artworks": artworks, "Title": fmt.Sprintf("(%d images)", len(artworks)), }) diff --git a/routes/user.go b/routes/user.go index b893cf0..5e78faf 100644 --- a/routes/user.go +++ b/routes/user.go @@ -41,7 +41,7 @@ func fetchData(c *fiber.Ctx, getTags bool) (userPageData, error) { var worksCount int var worksPerPage float64 - if category == core.UserArt_Bookmarked { + if category == core.UserArt_Bookmarks { worksPerPage = 48.0 } else { worksPerPage = 30.0 @@ -75,7 +75,9 @@ func UserAtomFeed(c *fiber.Ctx) error { return err } - err = c.Render("user.atom", fiber.Map{ + c.Context().SetContentType("application/atom+xml") + + return c.Render("user.atom", fiber.Map{ "URL": string(c.Request().RequestURI()), "Title": data.user.Name, "User": data.user, @@ -85,11 +87,4 @@ func UserAtomFeed(c *fiber.Ctx) error { "Page": data.page, // "MetaImage": data.user.BackgroundImage, }, "") - if err != nil { - return err - } - - c.Context().SetContentType("application/atom+xml") - - return nil } diff --git a/semgrep.yml b/semgrep.yml index 3a1afd7..12e3854 100644 --- a/semgrep.yml +++ b/semgrep.yml @@ -87,6 +87,14 @@ rules: message: "raw UserArtCategory string" languages: [go] severity: WARNING - pattern-either: + patterns: - pattern: | - ($A : UserArtCategory) == "$B" + ($A : UserArtCategory) == $B + - pattern-not: | + ($A : UserArtCategory) == ($B : UserArtCategory) +- id: rule-7 + message: "c.Render" + languages: [go] + severity: INFO + pattern: | + c.Render(...) diff --git a/main_test.go b/tests/integration/main_test.go similarity index 99% rename from main_test.go rename to tests/integration/main_test.go index d0817d4..3cb770d 100644 --- a/main_test.go +++ b/tests/integration/main_test.go @@ -1,4 +1,4 @@ -package main_test +package main import ( "log" diff --git a/tests/readme b/tests/readme new file mode 100644 index 0000000..02c8e9f --- /dev/null +++ b/tests/readme @@ -0,0 +1,6 @@ +# About testing + +There are two places where data transformations aren't type checked. + +1. passing data from Go to Jet (layout engine) +2. whether response from pixiv API fit our JSON schema or not diff --git a/tests/test.go b/tests/test.go deleted file mode 100644 index ca8701d..0000000 --- a/tests/test.go +++ /dev/null @@ -1 +0,0 @@ -package tests diff --git a/views/pages/artwork-multi.jet.html b/views/pages/artworkMulti.jet.html similarity index 100% rename from views/pages/artwork-multi.jet.html rename to views/pages/artworkMulti.jet.html