| 1 |
package proton |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytes" |
| 5 |
"context" |
| 6 |
"strings" |
| 7 |
|
| 8 |
"github.com/PuerkitoBio/goquery" |
| 9 |
"golang.org/x/net/html" |
| 10 |
) |
| 11 |
|
| 12 |
// Quark runs a quark command. |
| 13 |
func (m *Manager) Quark(ctx context.Context, command string, args ...string) error { |
| 14 |
if _, err := m.r(ctx).SetQueryParam("strInput", strings.Join(args, " ")).Get("/internal/quark/" + command); err != nil { |
| 15 |
return err |
| 16 |
} |
| 17 |
|
| 18 |
return nil |
| 19 |
} |
| 20 |
|
| 21 |
// QuarkRes is the same as Quark, but returns the content extracted from the response body. |
| 22 |
func (m *Manager) QuarkRes(ctx context.Context, command string, args ...string) ([]byte, error) { |
| 23 |
res, err := m.r(ctx).SetQueryParam("strInput", strings.Join(args, " ")).Get("/internal/quark/" + command) |
| 24 |
if err != nil { |
| 25 |
return nil, err |
| 26 |
} |
| 27 |
|
| 28 |
doc, err := html.Parse(bytes.NewReader(res.Body())) |
| 29 |
if err != nil { |
| 30 |
return nil, err |
| 31 |
} |
| 32 |
|
| 33 |
return []byte(strings.TrimSpace(goquery.NewDocumentFromNode(doc).Find(".content").Text())), nil |
| 34 |
} |