-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.go
163 lines (124 loc) · 3.33 KB
/
example.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package main
import (
"context"
"fmt"
"os"
jschan "github.com/jackbekket/jschan_go_api/app"
"github.com/joho/godotenv"
)
func main() {
_ = godotenv.Load() // load .env file locally
board_password := os.Getenv("PASSWORD") // get value from .env
b_endpoint := os.Getenv("ENDPOINT")
// test
println("endpoint: ",b_endpoint)
//println("password: ",board_password)
//client := jschan.NewClient("http://dev-jschan.lan")
client := jschan.NewClient(b_endpoint)
ctx := context.Background()
//client.BaseURL
loginOptions := &jschan.PostLoginOptions{
//Credentials for a private dev jschan
Username: "admin",
Password: board_password,
}
err := client.Login(ctx, loginOptions)
if err != nil {
fmt.Println(err)
return
}
if client.SessionCookie != "" {
fmt.Printf("Logged in as user %s\n", loginOptions.Username)
if _, err := client.GetCSRFToken(ctx); err != nil {
fmt.Println(err)
return
}
}
//GetBanners(*client,ctx)
//GetBoards(*client,ctx,"b")
//GetBoardIndexPages(*client,ctx,"b")
GetRecentPosts(*client,ctx,"b")
}
func GetReports(ip string, board_name string,client jschan.Client, ctx context.Context) {
manageReportsOptions := &jschan.GetManageReportsOptions{
Page: 0,
IP: ip,
Board: board_name,
}
reports, err2 := client.GetManageReports(ctx, manageReportsOptions)
if err2 != nil {
fmt.Println(err2)
return
}
fmt.Printf("Fetched %d reports\n", len(reports.Reports))
}
// stuff only
func GetRecentPosts(client jschan.Client, ctx context.Context, board_name string) {
getRecentOptions := &jschan.GetManageRecentOptions{
Board: board_name,
}
recent, err := client.GetManageRecent(ctx, getRecentOptions)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%+v", recent)
}
// Get /b/
func GetBoards(client jschan.Client, ctx context.Context, search_request string) {
getBoardsPublicOptions := &jschan.GetBoardsPublicOptions{
Search: search_request,
}
boards, err := client.GetBoardsPublic(ctx, getBoardsPublicOptions)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%+v", boards)
}
func GetBoardIndexPages(client jschan.Client, ctx context.Context, board_name string) {
getIndexOptions := &jschan.GetIndexOptions{
Board: board_name,
Page: 1,
}
index, err := client.GetIndex(ctx, getIndexOptions)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%+v", index)
}
func GetAllThreadsBoard(client jschan.Client, ctx context.Context, board_name string) {
getCatalogOptions := &jschan.GetCatalogOptions{
Board: board_name,
}
catalog, err := client.GetCatalog(ctx, getCatalogOptions)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%+v", catalog)
}
func GetCustomPage(client jschan.Client, ctx context.Context,board_name string,page_name string) {
getCustomPageOptions := &jschan.GetCustomPageOptions{
Board: board_name,
CustomPage: page_name,
}
custompage, err := client.GetCustomPage(ctx, getCustomPageOptions)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%+v", custompage)
}
func GetBanners(client jschan.Client, ctx context.Context, board_name string) {
getBannersOptions := &jschan.GetBannersOptions{
Board: board_name,
}
banners, err := client.GetBanners(ctx, getBannersOptions)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%+v", banners)
}