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 (
6 "strings" 6 "strings"
7) 7)
8 8
9type comments struct { 9type Comments struct {
10 Cursor string 10 Cursor string
11 PrevOffset int 11 PrevOffset int
12 HasMore, HasLess bool 12 HasMore, HasLess bool
@@ -33,12 +33,12 @@ type comments struct {
33} 33}
34 34
35// функция для обработки комментариев поста, пользователя, группы и многого другого 35// функция для обработки комментариев поста, пользователя, группы и многого другого
36func Comments( 36func CommentsFunc(
37 postid string, 37 postid string,
38 cursor string, 38 cursor string,
39 page int, 39 page int,
40 typ int, // 1 - комментарии поста; 4 - комментарии на стене группы или пользователя 40 typ int, // 1 - комментарии поста; 4 - комментарии на стене группы или пользователя
41) (cmmts comments) { 41) (cmmts Comments) {
42 for x := 0; x <= page; x++ { 42 for x := 0; x <= page; x++ {
43 ujson( 43 ujson(
44 "dashared/comments/thread?typeid="+strconv.Itoa(typ)+ 44 "dashared/comments/thread?typeid="+strconv.Itoa(typ)+
@@ -55,7 +55,7 @@ func Comments(
55 cmmts.Thread[i].Comment = m 55 cmmts.Thread[i].Comment = m
56 56
57 // если начало строки {, а конец }, то срабатывает этот иф 57 // если начало строки {, а конец }, то срабатывает этот иф
58 if m[0] == 123 && m[l-1] == 125 { 58 if m[0] == '{' && m[l-1] == '}' {
59 var content struct { 59 var content struct {
60 Blocks []struct { 60 Blocks []struct {
61 Text string 61 Text string
deviantion.go +33 −20
@@ -3,6 +3,7 @@ package devianter
3import ( 3import (
4 "encoding/json" 4 "encoding/json"
5 "strconv" 5 "strconv"
6 "strings"
6 timelib "time" 7 timelib "time"
7) 8)
8 9
@@ -20,7 +21,7 @@ func (t *time) UnmarshalJSON(b []byte) (err error) {
20} 21}
21 22
22// самая главная структура для поста 23// самая главная структура для поста
23type deviantion struct { 24type Deviation struct {
24 Title, Url, License string 25 Title, Url, License string
25 PublishedTime time 26 PublishedTime time
26 27
@@ -41,7 +42,7 @@ type deviantion struct {
41 } 42 }
42 DescriptionText text 43 DescriptionText text
43 RelatedContent []struct { 44 RelatedContent []struct {
44 Deviations []deviantion 45 Deviations []Deviation
45 } 46 }
46 } 47 }
47 TextContent text 48 TextContent text
@@ -65,8 +66,8 @@ type text struct {
65} 66}
66 67
67// структура поста 68// структура поста
68type Deviantion struct { 69type Post struct {
69 Deviation deviantion 70 Deviation Deviation
70 Comments struct { 71 Comments struct {
71 Total int 72 Total int
72 Cursor string 73 Cursor string
@@ -78,32 +79,44 @@ type Deviantion struct {
78 Replies, Likes int 79 Replies, Likes int
79 } 80 }
80 81
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()
82} 105}
83 106
84// для работы функции нужно ID поста и имя пользователя. 107// для работы функции нужно ID поста и имя пользователя.
85func Deviation(id string, user string) Deviantion { 108func DeviationFunc(id string, user string) Post {
86 var st Deviantion 109 var st Post
87 ujson( 110 ujson(
88 "dadeviation/init?deviationid="+id+"&username="+user+"&type=art&include_session=false&expand=deviation.related&preload=true", 111 "dadeviation/init?deviationid="+id+"&username="+user+"&type=art&include_session=false&expand=deviation.related&preload=true",
89 &st, 112 &st,
90 ) 113 )
91 114
92 // преобразование урла в правильный 115 st.IMG = UrlFromMedia(st.Deviation.Media)
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 }
103 116
104 // базовая обработка описания 117 // базовая обработка описания
105 txt := st.Deviation.TextContent.Html.Markup 118 txt := st.Deviation.TextContent.Html.Markup
106 if len(txt) > 0 && txt[1] == 125 { 119 if len(txt) > 0 && txt[1] == '{' {
107 var description struct { 120 var description struct {
108 Blocks []struct { 121 Blocks []struct {
109 Text string 122 Text string
@@ -116,7 +129,7 @@ func Deviation(id string, user string) Deviantion {
116 } 129 }
117 } 130 }
118 131
119 st.Desctiption = txt 132 st.Description = txt
120 133
121 return st 134 return st
122} 135}
misc.go +7 −6
@@ -116,13 +116,13 @@ func AEmedia(name string, t rune) (string, error) {
116} 116}
117 117
118/* SEARCH */ 118/* SEARCH */
119type search struct { 119type Search struct {
120 Total int `json:"estTotal"` 120 Total int `json:"estTotal"`
121 Pages int // only for 'a' and 'g' scope. 121 Pages int // only for 'a' and 'g' scope.
122 Results []deviantion `json:"deviations,results"` 122 Results []Deviation `json:"deviations,results"`
123} 123}
124 124
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) {
126 var url strings.Builder 126 var url strings.Builder
127 e = nil 127 e = nil
128 128
@@ -159,7 +159,8 @@ func Search(query string, page int, scope rune, user ...string) (ss search, e er
159 ujson(url.String(), &ss) 159 ujson(url.String(), &ss)
160 160
161 // расчёт, сколько всего страниц по запросу. без токена 417 страниц - максимум 161 // расчёт, сколько всего страниц по запросу. без токена 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++ {
163 if x <= 417 { 164 if x <= 417 {
164 ss.Pages = x 165 ss.Pages = x
165 } 166 }
user-group.go +13 −7
@@ -6,7 +6,7 @@ import (
6) 6)
7 7
8// структура группы или пользователя 8// структура группы или пользователя
9type Group struct { 9type GRuser struct {
10 ErrorDescription string 10 ErrorDescription string
11 Owner struct { 11 Owner struct {
12 Group bool `json:"isGroup"` 12 Group bool `json:"isGroup"`
@@ -30,7 +30,7 @@ type Group struct {
30 } 30 }
31 } 31 }
32 CoverDeviation struct { 32 CoverDeviation struct {
33 Deviation deviantion `json:"coverDeviation"` 33 Deviation Deviation `json:"coverDeviation"`
34 } 34 }
35 35
36 // группы 36 // группы
@@ -56,7 +56,7 @@ type Group struct {
56 Folder struct { 56 Folder struct {
57 Username string 57 Username string
58 Pages int `json:"totalPageCount"` 58 Pages int `json:"totalPageCount"`
59 Deviations []deviantion 59 Deviations []Deviation
60 } `json:"folderDeviations"` 60 } `json:"folderDeviations"`
61 } 61 }
62 } 62 }
@@ -72,17 +72,23 @@ type Group struct {
72 } 72 }
73} 73}
74 74
75func UGroup(name string) (g Group) { 75type Group struct {
76 ujson("dauserprofile/init/about?username="+name, &g) 76 Name string // обязательно заполнить
77 Content GRuser
78}
79
80// подходит как группа, так и пользователь
81func (s Group) GroupFunc() (g Group) {
82 ujson("dauserprofile/init/about?username="+s.Name, &g)
77 83
78 return 84 return
79} 85}
80 86
81// гарелея пользователя или группы 87// гарелея пользователя или группы
82func Gallery(name string, page int) (g Group) { 88func (s Group) Gallery(page int) (g Group) {
83 var url strings.Builder 89 var url strings.Builder
84 url.WriteString("dauserprofile/init/gallery?username=") 90 url.WriteString("dauserprofile/init/gallery?username=")
85 url.WriteString(name) 91 url.WriteString(s.Name)
86 url.WriteString("&page=") 92 url.WriteString("&page=")
87 url.WriteString(strconv.Itoa(page)) 93 url.WriteString(strconv.Itoa(page))
88 url.WriteString("&deviations_limit=50&with_subfolders=false") 94 url.WriteString("&deviations_limit=50&with_subfolders=false")