Allow fetching global by not passing or passing empty board options to getmanagerecent, improve the returned post struct and nested reports, etc

master
Thomas Lynch 2 years ago
parent 71f2ff6f87
commit 0d1d3a54dc
  1. 55
      app/manage.go
  2. 28
      app/models/post.go
  3. 4
      example.go

@ -3,63 +3,22 @@ package jschan
import (
"context"
"fmt"
// "jschan/app/models"
"jschan/app/models"
"net/http"
"time"
)
type GetManageRecentOptions struct {
Board string
Global bool
Board string
}
type AutoGenerated struct {
ID string `json:"_id"`
Date time.Time `json:"date"`
U int64 `json:"u"`
Name string `json:"name"`
Country interface{} `json:"country"`
Board string `json:"board"`
Tripcode interface{} `json:"tripcode"`
Capcode interface{} `json:"capcode"`
Subject string `json:"subject"`
Message string `json:"message"`
Messagehash string `json:"messagehash"`
Nomarkup string `json:"nomarkup"`
Thread int `json:"thread"`
Email string `json:"email"`
Spoiler bool `json:"spoiler"`
Banmessage interface{} `json:"banmessage"`
UserID string `json:"userId"`
IP struct {
Raw string `json:"raw"`
Cloak string `json:"cloak"`
Pruned bool `json:"pruned,omitempty"`
} `json:"ip,omitempty"`
Files []interface{} `json:"files"`
Reports []interface{} `json:"reports"`
Quotes []struct {
ID string `json:"_id"`
Thread int `json:"thread"`
PostID int `json:"postId"`
} `json:"quotes"`
Crossquotes []interface{} `json:"crossquotes"`
Backlinks []interface{} `json:"backlinks"`
PostID int `json:"postId"`
Bumped time.Time `json:"bumped,omitempty"`
Replyfiles int `json:"replyfiles,omitempty"`
Replyposts int `json:"replyposts,omitempty"`
Sticky int `json:"sticky,omitempty"`
Locked int `json:"locked,omitempty"`
Bumplocked int `json:"bumplocked,omitempty"`
Cyclic int `json:"cyclic,omitempty"`
}
type GetManageRecentResponse []AutoGenerated
type GetManageRecentResponse []models.Post
func (c *Client) GetManageRecent(ctx context.Context, options *GetManageRecentOptions) (GetManageRecentResponse, error) {
url := fmt.Sprintf("%s/%s/manage/recent.json", c.BaseURL, options.Board)
url := "/globalmanage/recent.json"
if options != nil && options.Board != "" {
url = fmt.Sprintf("%s/%s/manage/recent.json", c.BaseURL, options.Board)
}
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {

@ -19,19 +19,19 @@ type Post struct {
Date ScuffedTime `json:"date"`
U int64 `json:"u"`
Name string `json:"name"`
Country interface{} `json:"country"`
Country Country `json:"country"`
Board string `json:"board"`
Tripcode interface{} `json:"tripcode"`
Tripcode string `json:"tripcode"`
Capcode string `json:"capcode"`
Subject string `json:"subject"`
Message string `json:"message"`
Messagehash string `json:"messagehash"`
Nomarkup string `json:"nomarkup"`
Thread interface{} `json:"thread"`
Thread int `json:"thread"`
Email string `json:"email"`
Spoiler bool `json:"spoiler"`
Banmessage interface{} `json:"banmessage"`
UserID interface{} `json:"userId"`
Banmessage string `json:"banmessage"`
UserID string `json:"userId"`
Files []Files `json:"files"`
Quotes []interface{} `json:"quotes"`
Crossquotes []interface{} `json:"crossquotes"`
@ -45,10 +45,26 @@ type Post struct {
Bumped ScuffedTime `json:"bumped,omitempty"`
PostID int `json:"postId"`
Replies []Post `json:"replies,omitempty"`
Previewbacklinks []interface{} `json:"previewbacklinks,omitempty"`
Previewbacklinks []Backlinks `json:"previewbacklinks,omitempty"`
Omittedfiles int `json:"omittedfiles,omitempty"`
Omittedposts int `json:"omittedposts,omitempty"`
Edited Edited `json:"edited,omitempty"`
Reports []Report `json:"reports"`
GlobalReports []Report `json:"globalreports"`
IP IP `json:"ip,omitempty"`
}
type Report struct {
ID string `json:"id"`
Reason string `json:"reason"`
Date time.Time `json:"date"`
IP IP `json:"ip"`
}
type IP struct {
Raw string `json:"raw"`
Cloak string `json:"cloak"`
Pruned bool `json:"pruned"`
}
type Files struct {

@ -14,8 +14,8 @@ func main() {
ctx := context.Background()
loginOptions := &jschan.PostLoginOptions{
Username: "",
Password: "",
Username: "123",
Password: "123",
Twofactor: "",
}
err := jschanClient.Login(ctx, loginOptions)

Loading…
Cancel
Save