Comments in user profile
This commit is contained in:
parent
69e184f661
commit
582f870578
|
@ -6,7 +6,7 @@ SkunkyArt - альтернативный и легковесный фронте
|
|||
- [ ] Изображения в комментариях
|
||||
- [x] Ежедневные арты/посты
|
||||
- [x] Профили и галереи пользователей
|
||||
- [ ] Комментарии в профилях пользователей
|
||||
- [x] Комментарии в профилях пользователей
|
||||
- [ ] Группы
|
||||
- [x] Эмоджи и аватарки
|
||||
- [ ] Награды
|
||||
|
|
17
main.go
17
main.go
|
@ -36,6 +36,9 @@ func main() {
|
|||
e, p := endpoint(r.URL.Path)
|
||||
c := make(chan string, 100)
|
||||
|
||||
page, _ := strconv.ParseInt(r.URL.Query().Get("p"), 10, 32)
|
||||
q := url.QueryEscape(r.URL.Query().Get("q"))
|
||||
|
||||
switch e {
|
||||
case "image":
|
||||
fmt.Fprintln(w, misc.Getimage(p, url.QueryEscape(r.URL.Query().Get("t"))))
|
||||
|
@ -55,26 +58,22 @@ func main() {
|
|||
fmt.Fprintln(w, "Groups is not implemented yet :(")
|
||||
|
||||
case "user":
|
||||
fmt.Fprintln(w, user.Get(p, r.URL.Query().Get("a"), r.URL.Query().Get("p"), url.QueryEscape(r.URL.Query().Get("q"))))
|
||||
fmt.Fprintln(w, user.Get(p, r.URL.Query().Get("a"), q, int(page)))
|
||||
|
||||
case "post":
|
||||
intt, _ := strconv.ParseInt(r.URL.Query().Get("page"), 10, 32)
|
||||
|
||||
go post.Get(p, int(intt)+1, c)
|
||||
go post.Get(p, int(page)+1, c)
|
||||
fmt.Fprintln(w, <-c)
|
||||
|
||||
case "dd":
|
||||
intt, _ := strconv.ParseInt(r.URL.Query().Get("p"), 10, 32)
|
||||
|
||||
go misc.DD(int(intt), c)
|
||||
go misc.DD(int(page), c)
|
||||
fmt.Fprintln(w, <-c)
|
||||
|
||||
case "search":
|
||||
go misc.Search(url.QueryEscape(r.URL.Query().Get("q")), r.URL.Query().Get("p"), r.URL.Query().Get("scope"), c)
|
||||
go misc.Search(q, r.URL.Query().Get("p"), r.URL.Query().Get("scope"), c)
|
||||
fmt.Fprintln(w, <-c)
|
||||
|
||||
case "about":
|
||||
fmt.Fprintln(w, "Its an alternative frontend for deviantart.com. Compiled with Go:", runtime.Version())
|
||||
fmt.Fprintln(w, "Its an alternative frontend for deviantart.com.\nCompiled with Go:", runtime.Version())
|
||||
|
||||
case "static":
|
||||
file, err := os.ReadFile("static/" + p)
|
||||
|
|
|
@ -29,7 +29,7 @@ type Comments struct {
|
|||
}
|
||||
|
||||
// json
|
||||
func js(c string, cc int, id []string) (*string, bool, bool) {
|
||||
func js(c string, cc int, id []string, t int) (*string, bool, bool) {
|
||||
var result string
|
||||
|
||||
var j struct {
|
||||
|
@ -37,9 +37,13 @@ func js(c string, cc int, id []string) (*string, bool, bool) {
|
|||
PrevOffset int
|
||||
HasMore, HasLess bool
|
||||
}
|
||||
|
||||
for x := 0; x < cc; x++ {
|
||||
p := "dashared/comments/thread?typeid=1&itemid=" + id[len(id)-1] + "&maxdepth=1000&order=newest"
|
||||
/*
|
||||
1: comments of the post;
|
||||
4: comments on userpage
|
||||
*/
|
||||
|
||||
p := "dashared/comments/thread?typeid=" + strconv.Itoa(t) + "&itemid=" + id[len(id)-1] + "&maxdepth=1000&order=newest"
|
||||
result = util.Puppy(p + "&limit=50&cursor=" + strings.ReplaceAll(c, "+", `%2B`))
|
||||
|
||||
json.Unmarshal([]byte(result), &j)
|
||||
|
@ -53,9 +57,9 @@ func js(c string, cc int, id []string) (*string, bool, bool) {
|
|||
}
|
||||
|
||||
// comments!!
|
||||
func comments(uri string, user string, page int, cursor string, id []string) *string {
|
||||
func GetComments(uri, cursor string, page, typ int, id []string) *string {
|
||||
var comments Comments
|
||||
rawjson, next, prev := js(cursor, page, id)
|
||||
rawjson, next, prev := js(cursor, page, id, typ)
|
||||
|
||||
err := json.Unmarshal([]byte(*rawjson), &comments)
|
||||
if err != nil {
|
||||
|
@ -124,10 +128,10 @@ func comments(uri string, user string, page int, cursor string, id []string) *st
|
|||
htm = "<h2 id=\"comments\">Comments (" + strconv.Itoa(comments.Total) + ")</h2>" + htm
|
||||
uri = uri[strings.LastIndex(uri, "/")+1:]
|
||||
if prev {
|
||||
htm += "<a href=\"" + uri + "?page=" + strconv.Itoa(page-2) + "#comments\"><-- Back</a> "
|
||||
htm += "<a href=\"" + uri + "?p=" + strconv.Itoa(page-2) + "#comments\"><-- Back</a> "
|
||||
}
|
||||
if next {
|
||||
htm += "<a href=\"" + uri + "?page=" + strconv.Itoa(page) + "#comments\">Next --></a>"
|
||||
htm += "<a href=\"" + uri + "?p=" + strconv.Itoa(page) + "#comments\">Next --></a>"
|
||||
}
|
||||
} else {
|
||||
htm = "<p>There is no comments.</p>"
|
||||
|
|
|
@ -99,7 +99,7 @@ func _post(id []string, author string, url string, page int) string {
|
|||
|
||||
tmp.Comments = ""
|
||||
if j.Comments.Total > 0 {
|
||||
tmp.Comments = *comments(url, tmp.Author, page, strconv.Itoa(j.Comments.Cursor), id)
|
||||
tmp.Comments = *GetComments(url, strconv.Itoa(j.Comments.Cursor), page, 1, id)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
{{define "D"}}
|
||||
<h2>About me</h2>
|
||||
<p>{{.}}</p>
|
||||
{{end}}
|
||||
{{define "C"}}
|
||||
{{.}}
|
||||
</body>
|
||||
</html>
|
||||
{{end}}
|
|
@ -5,7 +5,9 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"skunkyart/post"
|
||||
"skunkyart/util"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -14,8 +16,9 @@ type Tmp struct {
|
|||
Name, Description, Bg, Bgname, Country, RegDate, Gender, Site, SiteTitle, Social, Interests, Status string
|
||||
}
|
||||
|
||||
func about(name *string, output chan string) {
|
||||
func about(name *string, page int, output chan string) {
|
||||
ums := time.Now().Unix()
|
||||
uid := make([]string, 1)
|
||||
|
||||
var buf bytes.Buffer
|
||||
{
|
||||
|
@ -42,6 +45,7 @@ func about(name *string, output chan string) {
|
|||
}
|
||||
j.ErrorDescription = ""
|
||||
|
||||
uid[0] = strconv.Itoa(j.Gruser.GruserId)
|
||||
for _, a := range j.Gruser.Page.Modules {
|
||||
if a.ModuleData.About.Country != "" {
|
||||
tmp.Country = a.ModuleData.About.Country
|
||||
|
@ -121,6 +125,7 @@ func about(name *string, output chan string) {
|
|||
tmpl.ExecuteTemplate(&buf, "S", template.HTML(tmp.Social))
|
||||
tmpl.ExecuteTemplate(&buf, "I", template.HTML(tmp.Interests))
|
||||
tmpl.ExecuteTemplate(&buf, "D", template.HTML(tmp.Description))
|
||||
tmpl.ExecuteTemplate(&buf, "C", template.HTML(*post.GetComments("user/"+tmp.Name, "", page+1, 4, uid)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
13
user/main.go
13
user/main.go
|
@ -2,21 +2,20 @@ package user
|
|||
|
||||
import "strconv"
|
||||
|
||||
func Get(name, action, page, query string) string {
|
||||
func Get(name, action, query string, page int) string {
|
||||
c := make(chan string, 100)
|
||||
|
||||
switch action {
|
||||
case "":
|
||||
go about(&name, c)
|
||||
go about(&name, page, c)
|
||||
case "gallery":
|
||||
if page == "" {
|
||||
page = "1"
|
||||
if page == 0 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
go gallery(&name, c, page)
|
||||
go gallery(&name, c, strconv.Itoa(page))
|
||||
case "search":
|
||||
p, _ := strconv.ParseInt(page, 10, 32)
|
||||
go search(&name, &query, int(p), c)
|
||||
go search(&name, &query, page, c)
|
||||
}
|
||||
return <-c
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@ type ab struct {
|
|||
Username string
|
||||
}
|
||||
Gruser struct {
|
||||
Page struct {
|
||||
GruserId int
|
||||
Page struct {
|
||||
Modules []struct {
|
||||
Name string
|
||||
ModuleData struct {
|
||||
|
|
Loading…
Reference in New Issue