Add most stuff under the "public endpoints" api section

master
Thomas Lynch 1 year ago
parent 4b5a75477a
commit fe38d8cf7a
  1. 83
      app/board.go
  2. 32
      app/global.go
  3. 6
      app/models/common.go
  4. 15
      app/models/custompage.go
  5. 43
      app/models/settings.go
  6. 30
      app/models/webring.go
  7. 50
      app/post.go

@ -120,3 +120,86 @@ func (c *Client) GetLogs(ctx context.Context, options *GetLogsOptions) (GetLogsR
return res, nil
}
type GetCustomPageOptions struct {
Board string
CustomPage string
}
type GetCustomPageResponse struct {
*models.CustomPage
}
func (c *Client) GetCustomPage(ctx context.Context, options *GetCustomPageOptions) (*GetCustomPageResponse, error) {
url := fmt.Sprintf("%s/%s/custompage/%s.json", c.BaseURL, options.Board, options.CustomPage)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
res := GetCustomPageResponse{}
if err := c.sendRequest(req, &res, nil); err != nil {
return nil, err
}
return &res, nil
}
type GetBannersOptions struct {
Board string
}
type GetBannersResponse []string
func (c *Client) GetBanners(ctx context.Context, options *GetBannersOptions) (GetBannersResponse, error) {
url := fmt.Sprintf("%s/%s/banners.json", c.BaseURL, options.Board)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
res := GetBannersResponse{}
if err := c.sendRequest(req, &res, nil); err != nil {
return nil, err
}
return res, nil
}
type GetSettingsOptions struct {
Board string
}
type GetSettingsResponse struct {
*models.CustomPage
}
func (c *Client) GetSettings(ctx context.Context, options *GetSettingsOptions) (*GetSettingsResponse, error) {
url := fmt.Sprintf("%s/%s/settings.json", c.BaseURL, options.Board)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
res := GetSettingsResponse{}
if err := c.sendRequest(req, &res, nil); err != nil {
return nil, err
}
return &res, nil
}

@ -0,0 +1,32 @@
package jschan
import (
"context"
"fmt"
"jschan/app/models"
"net/http"
)
type GetGlobalSettingsResponse struct {
*models.GlobalSettings
}
func (c *Client) GetGlobalSettings(ctx context.Context) (*CatalogResponse, error) {
url := fmt.Sprintf("%s/settings.json", c.BaseURL)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
res := CatalogResponse{}
if err := c.sendRequest(req, &res, nil); err != nil {
return nil, err
}
return &res, nil
}

@ -0,0 +1,6 @@
package models
type RawAndMarkdownMessage struct {
Raw string `json:"raw"`
Markdown string `json:"markdown"`
}

@ -0,0 +1,15 @@
package models
import (
"time"
)
type CustomPage struct {
Board string `json:"board"`
Page string `json:"page"`
Title string `json:"title"`
Message RawAndMarkdownMessage `json:"message"`
Date time.Time `json:"date"`
Edited interface{} `json:"edited"`
ID string `json:"_id"`
}

@ -0,0 +1,43 @@
package models
type BoardSettings struct {
CustomPages []string `json:"customPages"`
Announcement RawAndMarkdownMessage `json:"announcement"`
AllowedFileTypes AllowedFileTypes `json:"allowedFileTypes"`
MaxFiles int `json:"maxFiles"`
CaptchaMode int `json:"captchaMode"`
ForceAnon bool `json:"forceAnon"`
SageOnlyEmail bool `json:"sageOnlyEmail"`
CustomFlags bool `json:"customFlags"`
ForceThreadMessage bool `json:"forceThreadMessage"`
ForceThreadFile bool `json:"forceThreadFile"`
ForceThreadSubject bool `json:"forceThreadSubject"`
DisableReplySubject bool `json:"disableReplySubject"`
MinThreadMessageLength int `json:"minThreadMessageLength"`
MinReplyMessageLength int `json:"minReplyMessageLength"`
MaxThreadMessageLength int `json:"maxThreadMessageLength"`
MaxReplyMessageLength int `json:"maxReplyMessageLength"`
DefaultName string `json:"defaultName"`
}
type AllowedFileTypes struct {
AnimatedImage bool `json:"animatedImage"`
Image bool `json:"image"`
Video bool `json:"video"`
Audio bool `json:"audio"`
Other bool `json:"other"`
}
type GlobalSettings struct {
CaptchaOptions CaptchaOptions `json:"captchaOptions"`
}
type CaptchaOptions struct {
Type string `json:"type"`
Grid Grid `json:"grid,omitempty"`
}
type Grid struct {
Size int `json:"size"`
Question string `json:"question"`
}

@ -0,0 +1,30 @@
package models
import (
"time"
)
type Webring struct {
Name string `json:"name"`
URL string `json:"url"`
Endpoint string `json:"endpoint"`
Logo []string `json:"logo"`
Following []string `json:"following"`
Blacklist []string `json:"blacklist"`
Known []string `json:"known"`
Boards []WebringBoard `json:"boards"`
}
type WebringBoard struct {
URI string `json:"uri"`
Title string `json:"title"`
Subtitle string `json:"subtitle"`
Path string `json:"path"`
PostsPerHour int `json:"postsPerHour"`
PostsPerDay int `json:"postsPerDay"`
TotalPosts int `json:"totalPosts"`
UniqueUsers int `json:"uniqueUsers"`
Nsfw bool `json:"nsfw"`
Tags []string `json:"tags"`
LastPostTimestamp time.Time `json:"lastPostTimestamp"`
}

@ -0,0 +1,50 @@
package jschan
import (
"context"
"fmt"
"net/http"
"net/url"
"strings"
)
type PostMakePostOptions struct {
Board string
Thread int
Name string
Message string
Subject string
Email string
PostPassword string
//TODO: Files
Spoiler []string
SpoilerAll bool
StripFilename []string
CustomFlag string
//Array for grid captcha, submitted as single param if len()==1
Captcha []string
}
func (c *Client) MakePost(ctx context.Context, options *PostMakePostOptions) error {
formData := url.Values{}
//TODO: post params
endodedBody := strings.NewReader(formData.Encode())
url := fmt.Sprintf("%s/forms/%s/post", c.BaseURL, options.Board)
req, err := http.NewRequest(http.MethodPost, url, endodedBody)
if err != nil {
return err
}
req = req.WithContext(ctx)
if err := c.sendRequest(req, nil, nil); err != nil {
return err
}
return nil
}
Loading…
Cancel
Save