You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
134 lines
2.9 KiB
134 lines
2.9 KiB
package jschan
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"jschan/app/models"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
type GetBoardsResponse struct {
|
|
Boards []models.Board `json:"boards"`
|
|
Page int `json:"page"`
|
|
MaxPage int `json:"maxPage"`
|
|
}
|
|
|
|
type GetBoardsPublicOptions struct {
|
|
Search string
|
|
Sort string
|
|
SortDirection string
|
|
Page int
|
|
LocalFirst bool
|
|
Sites []string
|
|
}
|
|
|
|
func (c *Client) GetBoardsPublic(ctx context.Context, options *GetBoardsPublicOptions) (*GetBoardsResponse, error) {
|
|
|
|
page := 1
|
|
search := ""
|
|
sort := "popularity"
|
|
direction := "desc"
|
|
local_first := false
|
|
sites := []string{}
|
|
if options != nil {
|
|
search = options.Search
|
|
sort = options.Sort
|
|
direction = options.SortDirection
|
|
local_first = options.LocalFirst
|
|
sites = options.Sites
|
|
page = options.Page
|
|
}
|
|
|
|
query := url.Values{}
|
|
query.Set("search", search)
|
|
query.Set("page", fmt.Sprintf("%d", page))
|
|
query.Set("sort", sort)
|
|
query.Set("direction", direction)
|
|
if local_first {
|
|
query.Set("local_first", "true")
|
|
}
|
|
for _, site := range sites {
|
|
query.Add("sites", site)
|
|
}
|
|
|
|
url := fmt.Sprintf("%s/boards.json?%s", c.BaseURL, query.Encode())
|
|
|
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
req = req.WithContext(ctx)
|
|
|
|
res := GetBoardsResponse{}
|
|
if err := c.sendRequest(req, &res, nil); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &res, nil
|
|
|
|
}
|
|
|
|
type GetBoardsGlobalmanageOptions struct {
|
|
Search string `json:"search"`
|
|
Sort string `json:"sort"`
|
|
SortDirection string `json:"direction"`
|
|
Page int `json:"page"`
|
|
FilterUnlisted bool `json:"filter_unlisted"`
|
|
FilterSfw bool `json:"filter_sfw"`
|
|
FilterAbandoned bool `json:"filter_abandoned"`
|
|
}
|
|
|
|
func (c *Client) GetBoardsGlobalmanage(ctx context.Context, options *GetBoardsGlobalmanageOptions) (*GetBoardsResponse, error) {
|
|
|
|
page := 1
|
|
search := ""
|
|
sort := "popularity"
|
|
direction := "desc"
|
|
filter_unlisted := false
|
|
filter_sfw := false
|
|
filter_abandoned := false
|
|
if options != nil {
|
|
search = options.Search
|
|
sort = options.Sort
|
|
direction = options.SortDirection
|
|
filter_unlisted = options.FilterUnlisted
|
|
filter_sfw = options.FilterSfw
|
|
filter_abandoned = options.FilterAbandoned
|
|
page = options.Page
|
|
}
|
|
|
|
query := url.Values{}
|
|
query.Set("search", search)
|
|
query.Set("page", fmt.Sprintf("%d", page))
|
|
query.Set("sort", sort)
|
|
query.Set("direction", direction)
|
|
if filter_unlisted {
|
|
query.Set("filter_unlisted", "true")
|
|
}
|
|
if filter_sfw {
|
|
query.Set("filter_sfw", "true")
|
|
}
|
|
if filter_abandoned {
|
|
query.Set("filter_abandoned", "true")
|
|
}
|
|
|
|
url := fmt.Sprintf("%s/boards.json?%s", c.BaseURL, query.Encode())
|
|
|
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
req = req.WithContext(ctx)
|
|
|
|
res := GetBoardsResponse{}
|
|
if err := c.sendRequest(req, &res, nil); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &res, nil
|
|
|
|
}
|
|
|