From d6789522d3dd076f7c98dafa3e7d42df09252093 Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Wed, 15 Jul 2026 02:25:20 -0500 Subject: fix: document exported API, fix naming, and harden Download The remaining golangci-lint findings. These land together because the Url -> URL rename spans util.go, parsers.go and wrapper.go, and splitting it would leave an intermediate commit that does not compile. Download() carried the most serious bug here: try() only prints an error, it does not return, so a failed request fell through to resp.Body.Close() on a nil resp and panicked. Every failure path now returns the zero Downloaded, and callers check Status. ReturnHTTPError guards against the resulting status 0, which would otherwise panic WriteHeader. Requests carry a context with a timeout (noctx), and a download-proxy now routes through ProxiedTransport so it keeps the DA throttle and timeouts. Also: - doc comments on all 48 exported symbols (revive's exported rule, with checkPrivateReceivers, since most of app is exported methods on the unexported skunkyart type), plus package docs in new doc.go files so both the embed and non-embed builds are covered. - ST1003 naming: UrlBuilder -> URLBuilder, id_search -> idSearch, cache_config -> cacheConfig, TXT_RAW -> TxtRaw, mediaUrl -> mediaURL. - explicit json tags on structs that are unmarshaled (musttag); the hyphenated keys already had tags, the rest relied on case-insensitive fallback. Behaviour is unchanged. - modernization: range-over-int, WaitGroup.Go, stale +build lines, interface{} -> any, strings.Builder over string concatenation in a loop. --- app/wrapper.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'app/wrapper.go') diff --git a/app/wrapper.go b/app/wrapper.go index 9668ce0..7b4fe89 100755 --- a/app/wrapper.go +++ b/app/wrapper.go @@ -10,6 +10,8 @@ import ( "golang.org/x/net/html" ) +// GRUser renders a group or user page: the about tab, the gallery, or favourites, +// selected by the request's type argument. func (s skunkyart) GRUser() { if len(s.Query) < 1 { s.ReturnHTTPError(400) @@ -70,7 +72,7 @@ func (s skunkyart) GRUser() { case "cover_deviation": group.About.BGMeta = x.ModuleData.CoverDeviation.Deviation - group.About.BGMeta.Url = ConvertDeviantArtUrlToSkunkyArt(group.About.BGMeta.Url) + group.About.BGMeta.Url = ConvertDeviantArtURLToSkunkyArt(group.About.BGMeta.Url) group.About.BG = ParseMedia(group.About.BGMeta.Media) case "group_admins": var htm strings.Builder @@ -120,9 +122,9 @@ func (s skunkyart) GRUser() { if x.FolderId != -1 && x.Size != 0 { folders.WriteString(`
`) - if !(x.Thumb.NSFW && !CFG.Nsfw) { + if !x.Thumb.NSFW || CFG.Nsfw { folders.WriteString(``) folders.WriteString(x.Name) folders.WriteString(``) @@ -167,10 +169,11 @@ func (s skunkyart) GRUser() { } } -// posts +// Deviation renders a single artwork page, with its description, tags, comments +// and related work. It responds 403 for NSFW posts on instances that disallow them. func (s skunkyart) Deviation(author, postname string) { - id_search := regexp.MustCompile("[0-9]+").FindAllString(postname, -1) - if len(id_search) < 1 { + idSearch := regexp.MustCompile("[0-9]+").FindAllString(postname, -1) + if len(idSearch) < 1 { s.ReturnHTTPError(400) return } @@ -178,7 +181,7 @@ func (s skunkyart) Deviation(author, postname string) { var err devianter.Error post := &s.Templates.Deviation - id := id_search[len(id_search)-1] + id := idSearch[len(idSearch)-1] post.Post, err = devianter.GetDeviation(id, author) if err.RAW != nil { s.Error(err) @@ -188,7 +191,7 @@ func (s skunkyart) Deviation(author, postname string) { if post.Post.Deviation.NSFW && !CFG.Nsfw { s.Writer.WriteHeader(403) wr(s.Writer, `

NSFW content are disabled on this instance.

`) return } @@ -213,7 +216,7 @@ func (s skunkyart) Deviation(author, postname string) { for _, x := range post.Post.Deviation.Extended.Tags { var tag strings.Builder tag.WriteString(` #`) tag.WriteString(x.Name) tag.WriteString("") @@ -228,6 +231,7 @@ func (s skunkyart) Deviation(author, postname string) { s.ExecuteTemplate("deviantion.htm", "html", &s) } +// DD renders the Daily Deviations page, including each themed strip. func (s skunkyart) DD() { dd, err := devianter.GetDailyDeviations(s.Page) if err.RAW != nil { @@ -256,6 +260,8 @@ func (s skunkyart) DD() { } } +// Search renders search results for the request's query. Group search is scraped +// rather than fetched from the API, which DeviantArt does not expose to guests. func (s skunkyart) Search() { if s.Query == "" { s.ReturnHTTPError(400) @@ -305,7 +311,7 @@ func (s skunkyart) Search() { if l := len(usernames); l != 0 { ss.List += `
` - for x := 0; x < len(usernames); x++ { + for x := range len(usernames) { ss.List += BuildUserPlate(usernames[x]) } ss.List += `
` @@ -334,8 +340,10 @@ func (s skunkyart) Search() { s.ExecuteTemplate("search.htm", "html", &s) } +// Emojitar proxies a user's avatar or emoji image, selected by the request's +// type argument. func (s skunkyart) Emojitar(name string) { - if name == "" || !(s.Type == 'a' || s.Type == 'e') { + if name == "" || (s.Type != 'a' && s.Type != 'e') { s.ReturnHTTPError(400) return } -- cgit v1.2.3