Compare commits
2 Commits
42ea2980f9
...
b3c99749f1
Author | SHA1 | Date | |
---|---|---|---|
b3c99749f1 | |||
4487cdcbe9 |
@ -35,9 +35,9 @@ type Comments struct {
|
||||
}
|
||||
|
||||
// 1 - комментарии поста; 4 - комментарии на стене группы или пользователя
|
||||
func GetComments(postid string, cursor string, page int, typ int) (cmmts Comments) {
|
||||
func GetComments(postid string, cursor string, page int, typ int) (cmmts Comments, err Error) {
|
||||
for x := 0; x <= page; x++ {
|
||||
ujson(
|
||||
err = ujson(
|
||||
"dashared/comments/thread?typeid="+strconv.Itoa(typ)+
|
||||
"&itemid="+postid+"&maxdepth=1000&order=newest"+
|
||||
"&limit=50&cursor="+url.QueryEscape(cursor),
|
||||
|
@ -58,6 +58,7 @@ type Deviation struct {
|
||||
// её выпердыши
|
||||
type Media struct {
|
||||
BaseUri string
|
||||
Name string `json:"prettyName"`
|
||||
Token []string
|
||||
Types []struct {
|
||||
T string
|
||||
@ -90,7 +91,7 @@ type Post struct {
|
||||
}
|
||||
|
||||
// преобразование урла в правильный
|
||||
func UrlFromMedia(m Media, thumb ...int) string {
|
||||
func UrlFromMedia(m Media, thumb ...int) (urlParsed, wellFormattedFilename string) {
|
||||
var url strings.Builder
|
||||
|
||||
subtractWidthHeight := func(to int, target ...*int) {
|
||||
@ -104,18 +105,19 @@ func UrlFromMedia(m Media, thumb ...int) string {
|
||||
for _, t := range m.Types {
|
||||
if t.T == "fullview" {
|
||||
url.WriteString(m.BaseUri)
|
||||
if m.BaseUri[len(m.BaseUri)-3:] != "gif" && t.W*t.H < 33177600 {
|
||||
if l := len(m.BaseUri); l != 0 && (m.BaseUri[l-3:] != "gif" && t.W*t.H < 33177600) {
|
||||
if len(thumb) != 0 {
|
||||
subtractWidthHeight(thumb[0], &t.W, &t.H)
|
||||
}
|
||||
wellFormattedFilename = m.Name + m.BaseUri[l-4:]
|
||||
|
||||
url.WriteString("/v1/fit/w_")
|
||||
url.WriteString(strconv.Itoa(t.W))
|
||||
url.WriteString(",h_")
|
||||
url.WriteString(strconv.Itoa(t.H))
|
||||
url.WriteString("/")
|
||||
url.WriteString("image")
|
||||
url.WriteString(".gif")
|
||||
url.WriteString(wellFormattedFilename)
|
||||
|
||||
}
|
||||
if len(m.Token) > 0 {
|
||||
url.WriteString("?token=")
|
||||
@ -124,18 +126,19 @@ func UrlFromMedia(m Media, thumb ...int) string {
|
||||
}
|
||||
}
|
||||
|
||||
return url.String()
|
||||
urlParsed = url.String()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// для работы функции нужно ID поста и имя пользователя.
|
||||
func GetDeviation(id string, user string) Post {
|
||||
var st Post
|
||||
ujson(
|
||||
func GetDeviation(id string, user string) (st Post, err Error) {
|
||||
err = ujson(
|
||||
"dadeviation/init?deviationid="+id+"&username="+user+"&type=art&include_session=false&expand=deviation.related&preload=true",
|
||||
&st,
|
||||
)
|
||||
|
||||
st.IMG = UrlFromMedia(st.Deviation.Media)
|
||||
st.IMG, _ = UrlFromMedia(st.Deviation.Media)
|
||||
|
||||
// базовая обработка описания
|
||||
txt := st.Deviation.TextContent.Html.Markup
|
||||
@ -151,8 +154,7 @@ func GetDeviation(id string, user string) Post {
|
||||
txt = a.Text
|
||||
}
|
||||
}
|
||||
|
||||
st.Description = txt
|
||||
|
||||
return st
|
||||
|
||||
return
|
||||
}
|
||||
|
35
misc.go
35
misc.go
@ -64,8 +64,8 @@ type DailyDeviations struct {
|
||||
Deviations []Deviation
|
||||
}
|
||||
|
||||
func GetDailyDeviations(page int) (dd DailyDeviations) {
|
||||
ujson("dabrowse/networkbar/rfy/deviations?page="+strconv.Itoa(page), &dd)
|
||||
func GetDailyDeviations(page int) (dd DailyDeviations, err Error) {
|
||||
err = ujson("dabrowse/networkbar/rfy/deviations?page="+strconv.Itoa(page), &dd)
|
||||
return
|
||||
}
|
||||
|
||||
@ -78,9 +78,8 @@ type Search struct {
|
||||
ResultsGalleryTemp []Deviation `json:"results"`
|
||||
}
|
||||
|
||||
func PerformSearch(query string, page int, scope rune, user ...string) (ss Search, e error) {
|
||||
func PerformSearch(query string, page int, scope rune, user ...string) (ss Search, err error, daError Error) {
|
||||
var buildurl strings.Builder
|
||||
e = nil
|
||||
|
||||
// о5 построение ссылок.
|
||||
switch scope {
|
||||
@ -88,17 +87,23 @@ func PerformSearch(query string, page int, scope rune, user ...string) (ss Searc
|
||||
buildurl.WriteString("dabrowse/search/all?q=")
|
||||
case 't': // поиск артов по тегам
|
||||
buildurl.WriteString("dabrowse/networkbar/tag/deviations?tag=")
|
||||
case 'g': // поиск артов пользователя или группы
|
||||
if user != nil {
|
||||
buildurl.WriteString("dashared/gallection/search?username=")
|
||||
buildurl.WriteString(user[0])
|
||||
buildurl.WriteString("&type=gallery&order=most-recent&init=true&limit=50&q=")
|
||||
} else {
|
||||
e = errors.New("missing username (last argument)")
|
||||
case 'g', 'f': // поиск артов пользователя или группы
|
||||
if user == nil {
|
||||
err = errors.New("missing username (last argument)")
|
||||
return
|
||||
}
|
||||
|
||||
buildurl.WriteString("dashared/gallection/search?username=")
|
||||
buildurl.WriteString(user[0])
|
||||
buildurl.WriteString("&type=")
|
||||
if scope == 'g' {
|
||||
buildurl.WriteString("gallery")
|
||||
} else {
|
||||
buildurl.WriteString("collection")
|
||||
}
|
||||
buildurl.WriteString("&order=most-recent&init=true&limit=50&q=")
|
||||
default:
|
||||
log.Fatalln("Invalid type.\n- 'a' -- all;\n- 't' -- tag;\n- 'g' - gallery.")
|
||||
log.Fatalln("Invalid type.\n- 'a' -- all;\n- 't' -- tag;\n- 'g' - gallery\n- 'f' - folders.")
|
||||
}
|
||||
|
||||
buildurl.WriteString(url.QueryEscape(query))
|
||||
@ -110,13 +115,13 @@ func PerformSearch(query string, page int, scope rune, user ...string) (ss Searc
|
||||
}
|
||||
buildurl.WriteString(strconv.Itoa(page))
|
||||
|
||||
ujson(buildurl.String(), &ss)
|
||||
daError = ujson(buildurl.String(), &ss)
|
||||
|
||||
if scope == 'g' {
|
||||
if ss.Results == nil {
|
||||
ss.Results = ss.ResultsGalleryTemp
|
||||
}
|
||||
|
||||
// расчёт, сколько всего страниц по запросу. без токена 417 страниц - максимум
|
||||
// расчёт, сколько всего страниц по запросу. без токена, 417 страниц - максимум
|
||||
totalfloat := int(math.Round(float64(ss.Total / 25)))
|
||||
for x := 0; x < totalfloat; x++ {
|
||||
if x <= 417 {
|
||||
|
@ -46,10 +46,11 @@ type Gallery struct {
|
||||
Folders struct {
|
||||
HasMore bool
|
||||
Results []struct {
|
||||
FolderId int
|
||||
Size int
|
||||
Name string
|
||||
Thumb Deviation
|
||||
Deviations int `json:"totalItemCount"`
|
||||
FolderId int
|
||||
Size int
|
||||
Name string
|
||||
Thumb Deviation
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,19 +75,44 @@ type Group struct {
|
||||
}
|
||||
|
||||
// подходит как группа, так и пользователь
|
||||
func (s Group) GetGroup() (g GRuser, err error) {
|
||||
func (s Group) Get() (g GRuser, err error, daError Error) {
|
||||
if s.Name == "" {
|
||||
return g, errors.New("missing Name field")
|
||||
return g, errors.New("missing Name field"), daError
|
||||
}
|
||||
ujson("dauserprofile/init/about?username="+s.Name, &g)
|
||||
daError = ujson("dauserprofile/init/about?username="+s.Name, &g)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (s Group) Favourites(page int, all bool, folderid ...int) (g Group, err Error) {
|
||||
var url strings.Builder
|
||||
|
||||
if fid := folderid[0]; fid > 0 || all {
|
||||
url.WriteString("dashared/gallection/contents")
|
||||
if all {
|
||||
url.WriteString("?all_folder=true")
|
||||
} else {
|
||||
url.WriteString("?folderid=")
|
||||
url.WriteString(strconv.Itoa(fid))
|
||||
}
|
||||
url.WriteString("&type=collection&")
|
||||
} else {
|
||||
url.WriteString("dauserprofile/init/favourites?deviations_")
|
||||
}
|
||||
|
||||
url.WriteString("limit=50&username=")
|
||||
url.WriteString(s.Name)
|
||||
url.WriteString("&with_subfolders=true&offset=")
|
||||
url.WriteString(strconv.Itoa(page * 50))
|
||||
|
||||
err = ujson(url.String(), &g.Content)
|
||||
return
|
||||
}
|
||||
|
||||
// гарелея пользователя или группы
|
||||
func (s Group) GetGallery(page int, folderid ...int) (g Group, err error) {
|
||||
func (s Group) Gallery(page int, folderid ...int) (g Group, err error, daError Error) {
|
||||
if s.Name == "" {
|
||||
return g, errors.New("missing Name field")
|
||||
return g, errors.New("missing Name field"), daError
|
||||
}
|
||||
|
||||
var url strings.Builder
|
||||
@ -109,7 +135,7 @@ func (s Group) GetGallery(page int, folderid ...int) (g Group, err error) {
|
||||
url.WriteString("limit=50")
|
||||
url.WriteString("&with_subfolders=false")
|
||||
|
||||
ujson(url.String(), &g.Content)
|
||||
daError = ujson(url.String(), &g.Content)
|
||||
return
|
||||
}
|
||||
|
||||
|
22
util.go
22
util.go
@ -15,11 +15,25 @@ func try(txt error) {
|
||||
}
|
||||
}
|
||||
|
||||
// сокращение для вызова щенка и парсинга жсона
|
||||
func ujson(data string, output any) {
|
||||
func ujson(data string, output any) Error {
|
||||
input, err := puppy(data)
|
||||
try(err)
|
||||
try(json.Unmarshal([]byte(input), output))
|
||||
if err == nil {
|
||||
try(json.Unmarshal([]byte(input), output))
|
||||
}
|
||||
return APIError(err)
|
||||
}
|
||||
|
||||
type Error struct {
|
||||
Reason string `json:"error"`
|
||||
Error string `json:"errorDescription"`
|
||||
RAW []byte `json:"-"`
|
||||
}
|
||||
func APIError(inputError error) (err Error) {
|
||||
if inputError != nil {
|
||||
err.RAW = []byte(inputError.Error())
|
||||
try(json.Unmarshal(err.RAW, &err))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
/* REQUEST SECTION */
|
||||
|
Loading…
Reference in New Issue
Block a user