added covers to user comment page

This commit is contained in:
orangix
2023-08-15 19:52:47 +02:00
parent 3faef9aeb9
commit ab95ee5e2b
4 changed files with 59 additions and 45 deletions

View File

@@ -111,7 +111,7 @@ func (client *Client) FetchUserComments(username string, page string) ([]Comment
q := req.URL.Query()
q.Add("client_id", client.ClientID)
q.Add("filter[account]", "eq:wouldaponybyanyothernamebeasoffencive")
q.Add("filter[account]", "eq:"+username)
q.Add("include", "account,post")
q.Add("sort", "new")
@@ -150,20 +150,30 @@ func (client *Client) FetchUserComments(username string, page string) ([]Comment
}
func parseSubmission(value gjson.Result) Submission {
coverData := value.Get("images.#(id==\"" + value.Get("cover").String() + "\")")
cover := Media{
Id: value.Get("id").String(),
Description: value.Get("description").String(),
Type: strings.Split(value.Get("type").String(), "/")[0],
Url: strings.ReplaceAll(value.Get("link").String(), "https://i.imgur.com", ""),
}
if coverData.Exists() {
var cover Media
c := value.Get("cover")
coverData := value.Get("images.#(id==\"" + c.String() + "\")")
switch {
case c.Type == gjson.String && coverData.Exists():
cover = Media{
Id: coverData.Get("id").String(),
Description: coverData.Get("description").String(),
Type: strings.Split(coverData.Get("type").String(), "/")[0],
Url: strings.ReplaceAll(coverData.Get("link").String(), "https://i.imgur.com", ""),
}
// This case is when fetching comments
case c.Type != gjson.Null:
cover = Media{
Id: c.Get("id").String(),
Url: c.Get("url").String(),
}
default:
cover = Media{
Id: value.Get("id").String(),
Description: value.Get("description").String(),
Type: strings.Split(value.Get("type").String(), "/")[0],
Url: strings.ReplaceAll(value.Get("link").String(), "https://i.imgur.com", ""),
}
}
id := value.Get("id").String()