~handlerug/handlebot

ref: e2138e35984f582b50a481b58c332afae2841b1f handlebot/urlpreview/wolframalpha.go -rw-r--r-- 582 bytes
e2138e35Umar Getagazov urlpreview: Parse Content-Disposition 5 months ago
                                                                                
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
package urlpreview

import (
	"context"
	"net/url"
	"strings"

	"git.sr.ht/~handlerug/handlebot/presentation"
	"git.sr.ht/~handlerug/handlebot/wolframalpha"
)

func (p *Previewer) wolframalpha(ctx context.Context, u *url.URL) (string, error) {
	if !strings.HasSuffix(u.Host, "wolframalpha.com") ||
		u.Path != "/input" || !u.Query().Has("i") {
		return "", nil
	}

	client := wolframalpha.ForContext(ctx)
	if client == nil {
		return "", nil
	}

	resp, err := client.Query(ctx, u.Query().Get("i"))
	if err != nil {
		return "", nil
	}
	return presentation.WolframAlpha(resp), nil
}