...
1 package jschan
2
3 import (
4 "context"
5 "fmt"
6 "jschan/app/models"
7 "net/http"
8 "net/url"
9 "strings"
10 )
11
12
13 type GetGlobalSettingsResponse struct {
14 *models.GlobalSettings
15 }
16
17 func (c *Client) GetGlobalSettings(ctx context.Context) (*CatalogResponse, error) {
18
19 url := fmt.Sprintf("%s/settings.json", c.BaseURL)
20
21 req, err := http.NewRequest(http.MethodGet, url, nil)
22 if err != nil {
23 return nil, err
24 }
25
26 req = req.WithContext(ctx)
27
28 res := CatalogResponse{}
29 if err := c.sendRequest(req, &res, nil); err != nil {
30 return nil, err
31 }
32
33 return &res, nil
34
35 }
36
37 type GlobalClearTables string
38
39 const (
40 Sessions GlobalClearTables = "sessions"
41 Blockbypass GlobalClearTables = "blockbypass"
42 )
43
44 type GlobalClearOptions struct {
45 Table GlobalClearTables
46 Confirm bool
47 }
48
49 func (e GlobalClearTables) String() string {
50 return string(e)
51 }
52
53 func (c *Client) GlobalClear(ctx context.Context, options *GlobalClearOptions) error {
54
55 formData := url.Values{}
56 formData.Set("table", options.Table.String())
57 if (options.Confirm) {
58 formData.Set("confirm", "1")
59 }
60 encodedBody := strings.NewReader(formData.Encode())
61
62 url := fmt.Sprintf("%s/forms/global/clear", c.BaseURL)
63
64 req, err := http.NewRequest(http.MethodPost, url, encodedBody)
65 if err != nil {
66 return err
67 }
68
69 req = req.WithContext(ctx)
70
71 if err := c.sendRequest(req, nil, nil); err != nil {
72 return err
73 }
74
75 return nil
76
77 }
78
View as plain text