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