File: internal.go

package info (click to toggle)
golang-github-henrybear327-go-proton-api 1.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,088 kB
  • sloc: sh: 55; makefile: 26
file content (34 lines) | stat: -rw-r--r-- 916 bytes parent folder | download
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
package proton

import (
	"bytes"
	"context"
	"strings"

	"github.com/PuerkitoBio/goquery"
	"golang.org/x/net/html"
)

// Quark runs a quark command.
func (m *Manager) Quark(ctx context.Context, command string, args ...string) error {
	if _, err := m.r(ctx).SetQueryParam("strInput", strings.Join(args, " ")).Get("/internal/quark/" + command); err != nil {
		return err
	}

	return nil
}

// QuarkRes is the same as Quark, but returns the content extracted from the response body.
func (m *Manager) QuarkRes(ctx context.Context, command string, args ...string) ([]byte, error) {
	res, err := m.r(ctx).SetQueryParam("strInput", strings.Join(args, " ")).Get("/internal/quark/" + command)
	if err != nil {
		return nil, err
	}

	doc, err := html.Parse(bytes.NewReader(res.Body()))
	if err != nil {
		return nil, err
	}

	return []byte(strings.TrimSpace(goquery.NewDocumentFromNode(doc).Find(".content").Text())), nil
}