parent
4b5a75477a
commit
fe38d8cf7a
7 changed files with 259 additions and 0 deletions
@ -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…
Reference in new issue