Commit 8f645d7ccb

8f645d7ccb01c15650958f2f9dd14f15f9afd72b

parent: fd031a255b

Unsigned

lost+skunk <skunky@macaw.me> · 2024-06-13 21:05 UTC

небольшие улучшения

Layout: unified · split

comments.go +4 −4
@@ -6,7 +6,7 @@ import (
66 "strings"
77)
88
9type comments struct {
9type Comments struct {
1010 Cursor string
1111 PrevOffset int
1212 HasMore, HasLess bool
@@ -33,12 +33,12 @@ type comments struct {
3333}
3434
3535// функция для обработки комментариев поста, пользователя, группы и многого другого
36func Comments(
36func CommentsFunc(
3737 postid string,
3838 cursor string,
3939 page int,
4040 typ int, // 1 - комментарии поста; 4 - комментарии на стене группы или пользователя
41) (cmmts comments) {
41) (cmmts Comments) {
4242 for x := 0; x <= page; x++ {
4343 ujson(
4444 "dashared/comments/thread?typeid="+strconv.Itoa(typ)+
@@ -55,7 +55,7 @@ func Comments(
5555 cmmts.Thread[i].Comment = m
5656
5757 // если начало строки {, а конец }, то срабатывает этот иф
58 if m[0] == 123 && m[l-1] == 125 {
58 if m[0] == '{' && m[l-1] == '}' {
5959 var content struct {
6060 Blocks []struct {
6161 Text string
deviantion.go +33 −20
@@ -3,6 +3,7 @@ package devianter
33import (
44 "encoding/json"
55 "strconv"
6 "strings"
67 timelib "time"
78)
89
@@ -20,7 +21,7 @@ func (t *time) UnmarshalJSON(b []byte) (err error) {
2021}
2122
2223// самая главная структура для поста
23type deviantion struct {
24type Deviation struct {
2425 Title, Url, License string
2526 PublishedTime time
2627
@@ -41,7 +42,7 @@ type deviantion struct {
4142 }
4243 DescriptionText text
4344 RelatedContent []struct {
44 Deviations []deviantion
45 Deviations []Deviation
4546 }
4647 }
4748 TextContent text
@@ -65,8 +66,8 @@ type text struct {
6566}
6667
6768// структура поста
68type Deviantion struct {
69 Deviation deviantion
69type Post struct {
70 Deviation Deviation
7071 Comments struct {
7172 Total int
7273 Cursor string
@@ -78,32 +79,44 @@ type Deviantion struct {
7879 Replies, Likes int
7980 }
8081
81 IMG, Desctiption string
82 IMG, Description string
83}
84
85// преобразование урла в правильный
86func UrlFromMedia(m media) string {
87 var url strings.Builder
88 for _, t := range m.Types {
89 if t.T == "fullview" {
90 url.WriteString(m.BaseUri)
91 if m.BaseUri[len(m.BaseUri)-3:] != "gif" && t.W*t.H < 33177600 {
92 url.WriteString("/v1/fill/w_")
93 url.WriteString(strconv.Itoa(t.W))
94 url.WriteString(",h_")
95 url.WriteString(strconv.Itoa(t.H))
96 url.WriteString("/")
97 url.WriteString("image")
98 url.WriteString(".gif")
99 }
100 url.WriteString("?token=")
101 url.WriteString(m.Token[0])
102 }
103 }
104 return url.String()
82105}
83106
84107// для работы функции нужно ID поста и имя пользователя.
85func Deviation(id string, user string) Deviantion {
86 var st Deviantion
108func DeviationFunc(id string, user string) Post {
109 var st Post
87110 ujson(
88111 "dadeviation/init?deviationid="+id+"&username="+user+"&type=art&include_session=false&expand=deviation.related&preload=true",
89112 &st,
90113 )
91114
92 // преобразование урла в правильный
93 for _, t := range st.Deviation.Media.Types {
94 if m := st.Deviation.Media; t.T == "fullview" {
95 if len(m.Token) > 0 {
96 st.IMG = m.BaseUri + "?token="
97 } else {
98 st.IMG = m.BaseUri + "/v1/fill/w_" + strconv.Itoa(t.W) + ",h_" + strconv.Itoa(t.H) + "/" + id + "_" + user + ".gif" + "?token="
99 }
100 st.IMG += m.Token[0]
101 }
102 }
115 st.IMG = UrlFromMedia(st.Deviation.Media)
103116
104117 // базовая обработка описания
105118 txt := st.Deviation.TextContent.Html.Markup
106 if len(txt) > 0 && txt[1] == 125 {
119 if len(txt) > 0 && txt[1] == '{' {
107120 var description struct {
108121 Blocks []struct {
109122 Text string
@@ -116,7 +129,7 @@ func Deviation(id string, user string) Deviantion {
116129 }
117130 }
118131
119 st.Desctiption = txt
132 st.Description = txt
120133
121134 return st
122135}
misc.go +7 −6
@@ -116,13 +116,13 @@ func AEmedia(name string, t rune) (string, error) {
116116}
117117
118118/* SEARCH */
119type search struct {
120 Total int `json:"estTotal"`
121 Pages int // only for 'a' and 'g' scope.
122 Results []deviantion `json:"deviations,results"`
119type Search struct {
120 Total int `json:"estTotal"`
121 Pages int // only for 'a' and 'g' scope.
122 Results []Deviation `json:"deviations,results"`
123123}
124124
125func Search(query string, page int, scope rune, user ...string) (ss search, e error) {
125func SearchFunc(query string, page int, scope rune, user ...string) (ss Search, e error) {
126126 var url strings.Builder
127127 e = nil
128128
@@ -159,7 +159,8 @@ func Search(query string, page int, scope rune, user ...string) (ss search, e er
159159 ujson(url.String(), &ss)
160160
161161 // расчёт, сколько всего страниц по запросу. без токена 417 страниц - максимум
162 for x := 0; x < int(math.Round(float64(ss.Total/25))); x++ {
162 totalfloat := int(math.Round(float64(ss.Total / 25)))
163 for x := 0; x < totalfloat; x++ {
163164 if x <= 417 {
164165 ss.Pages = x
165166 }
user-group.go +13 −7
@@ -6,7 +6,7 @@ import (
66)
77
88// структура группы или пользователя
9type Group struct {
9type GRuser struct {
1010 ErrorDescription string
1111 Owner struct {
1212 Group bool `json:"isGroup"`
@@ -30,7 +30,7 @@ type Group struct {
3030 }
3131 }
3232 CoverDeviation struct {
33 Deviation deviantion `json:"coverDeviation"`
33 Deviation Deviation `json:"coverDeviation"`
3434 }
3535
3636 // группы
@@ -56,7 +56,7 @@ type Group struct {
5656 Folder struct {
5757 Username string
5858 Pages int `json:"totalPageCount"`
59 Deviations []deviantion
59 Deviations []Deviation
6060 } `json:"folderDeviations"`
6161 }
6262 }
@@ -72,17 +72,23 @@ type Group struct {
7272 }
7373}
7474
75func UGroup(name string) (g Group) {
76 ujson("dauserprofile/init/about?username="+name, &g)
75type Group struct {
76 Name string // обязательно заполнить
77 Content GRuser
78}
79
80// подходит как группа, так и пользователь
81func (s Group) GroupFunc() (g Group) {
82 ujson("dauserprofile/init/about?username="+s.Name, &g)
7783
7884 return
7985}
8086
8187// гарелея пользователя или группы
82func Gallery(name string, page int) (g Group) {
88func (s Group) Gallery(page int) (g Group) {
8389 var url strings.Builder
8490 url.WriteString("dauserprofile/init/gallery?username=")
85 url.WriteString(name)
91 url.WriteString(s.Name)
8692 url.WriteString("&page=")
8793 url.WriteString(strconv.Itoa(page))
8894 url.WriteString("&deviations_limit=50&with_subfolders=false")