`)
strips.WriteString(s.DeviationList(x.Deviations, false))
}
s.Templates.DDStrips = strips.String()
s.Templates.SomeList = s.DeviationList(dd.Deviations, true, DeviationList{
Pages: 0,
More: dd.HasMore,
})
if !s.Atom {
s.ExecuteTemplate("daily.htm", "html", &s)
}
}
// 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)
return
}
var err error
var daError devianter.Error
ss := &s.Templates.Search
switch s.Type {
case 'a', 't':
ss.Content, daError, err = devianter.PerformSearch(s.Query, s.Page, s.Type)
case 'g', 'f':
ss.Content, daError, err = devianter.PerformSearch(s.Query, s.Page, s.Type, s.Args.Get("usr"))
case 'r': // scraper, since DeviantArt withholds the guest API for group search
var (
usernames = make(map[int]string)
url strings.Builder
num int
)
s.Page++
url.WriteString("https://www.deviantart.com/groups/?q=")
url.WriteString(s.Query)
if s.Page > 1 {
url.WriteString("&offset=")
url.WriteString(strconv.Itoa(10 * s.Page))
}
dwnld := Download(url.String())
for z := html.NewTokenizer(strings.NewReader(string(dwnld.Body))); ; {
if n, token := z.Next(), z.Token(); n == html.StartTagToken && token.Data == "a" {
for _, x := range token.Attr {
if x.Key == "class" && x.Val == "u regular username" {
usernames[num] = GetValueOfTag(z)
num++
}
}
} else if n == 0 {
break
} else {
continue
}
}
if len(usernames) != 0 {
ss.List += `
`
for x := range len(usernames) {
ss.List += BuildUserPlate(s.Host, usernames[x])
}
ss.List += `
`
ss.List += s.NavBase(DeviationList{
More: true,
})
}
default:
s.ReturnHTTPError(400)
return
}
try(err)
if s.Type != 'r' {
if daError.RAW != nil {
s.Error(daError)
return
}
ss.List = s.DeviationList(ss.Content.Results, false, DeviationList{
Pages: ss.Content.Pages,
More: ss.Content.HasMore,
})
}
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') {
s.ReturnHTTPError(400)
return
}
ae, e := devianter.AEmedia(name, s.Type)
if e != nil {
s.ReturnHTTPError(404)
}
wr(s.Writer, ae)
}