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