ошибки
This commit is contained in:
parent
4487cdcbe9
commit
b3c99749f1
@ -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) {
|
||||
@ -108,14 +109,15 @@ func UrlFromMedia(m Media, thumb ...int) string {
|
||||
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
|
||||
}
|
||||
|
11
misc.go
11
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 {
|
||||
@ -90,7 +89,7 @@ func PerformSearch(query string, page int, scope rune, user ...string) (ss Searc
|
||||
buildurl.WriteString("dabrowse/networkbar/tag/deviations?tag=")
|
||||
case 'g', 'f': // поиск артов пользователя или группы
|
||||
if user == nil {
|
||||
e = errors.New("missing username (last argument)")
|
||||
err = errors.New("missing username (last argument)")
|
||||
return
|
||||
}
|
||||
|
||||
@ -116,7 +115,7 @@ 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 ss.Results == nil {
|
||||
ss.Results = ss.ResultsGalleryTemp
|
||||
|
@ -75,16 +75,16 @@ type Group struct {
|
||||
}
|
||||
|
||||
// подходит как группа, так и пользователь
|
||||
func (s Group) Get() (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) {
|
||||
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 {
|
||||
@ -105,14 +105,14 @@ func (s Group) Favourites(page int, all bool, folderid ...int) (g Group) {
|
||||
url.WriteString("&with_subfolders=true&offset=")
|
||||
url.WriteString(strconv.Itoa(page * 50))
|
||||
|
||||
ujson(url.String(), &g.Content)
|
||||
err = ujson(url.String(), &g.Content)
|
||||
return
|
||||
}
|
||||
|
||||
// гарелея пользователя или группы
|
||||
func (s Group) Gallery(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
|
||||
@ -135,7 +135,7 @@ func (s Group) Gallery(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