masto.go (view raw)
1package main
2
3import (
4 "fmt"
5 "net/http"
6
7 "humungus.tedunangst.com/r/webs/junk"
8)
9
10func badjunk(rw http.ResponseWriter, j junk.Junk) {
11 elog.Printf("oauthorize: bad junk: %s", j.ToString())
12 http.Error(rw, "oauthorize: bad junk", http.StatusBadRequest)
13}
14
15// https://docs.joinmastodon.org/methods/apps/#create
16func apiapps(rw http.ResponseWriter, r *http.Request) {
17 j, err := junk.Read(r.Body)
18 if err != nil {
19 badjunk(rw, j)
20 return
21 }
22
23 dlog.Println(j)
24
25}
26
27// https://docs.joinmastodon.org/methods/oauth/#authorize
28func oauthorize(rw http.ResponseWriter, r *http.Request) {
29 dlog.Println(r.URL.RawQuery)
30}
31
32// https://docs.joinmastodon.org/methods/instance/#v2
33func instance(rw http.ResponseWriter, r *http.Request) {
34 j := junk.New()
35
36 var servername string
37 if err := getconfig("servername", &servername); err != nil {
38 http.Error(rw, "getting servername", http.StatusInternalServerError)
39 return
40 }
41
42 j["uri"] = servername
43 j["title"] = "honk"
44 j["description"] = "federated honk conveyance"
45 j["version"] = "develop"
46
47 thumbnail := junk.New()
48 thumbnail["url"] = fmt.Sprintf("https://%s/icon.png", servername)
49 j["thumbnail"] = thumbnail
50 j["languages"] = []string{"en"}
51
52 config := junk.New()
53
54 a := junk.New()
55 a["max_featured_tags"] = 10
56 config["accounts"] = a
57
58 s := junk.New()
59 s["max_characters"] = 5000
60 s["max_media_attachments"] = 1
61 s["characters_reserved_per_url"] = 23
62 config["statuses"] = s
63
64 m := junk.New()
65 m["supported_mime_types"] = []string{
66 "image/jpeg",
67 "image/png",
68 "image/gif",
69 "image/heic",
70 "image/heif",
71 "image/webp",
72 "image/avif",
73 "video/webm",
74 "video/mp4",
75 "video/quicktime",
76 "video/ogg",
77 "audio/wave",
78 "audio/wav",
79 "audio/x-wav",
80 "audio/x-pn-wave",
81 "audio/vnd.wave",
82 "audio/ogg",
83 "audio/vorbis",
84 "audio/mpeg",
85 "audio/mp3",
86 "audio/webm",
87 "audio/flac",
88 "audio/aac",
89 "audio/m4a",
90 "audio/x-m4a",
91 "audio/mp4",
92 "audio/3gpp",
93 "video/x-ms-asf",
94 }
95
96 m["image_size_limit"] = 10485760
97 m["image_matrix_limit"] = 16777216
98 m["video_size_limit"] = 41943040
99 m["video_frame_rate_limit"] = 60
100 m["video_matrix_limit"] = 2304000
101 j["media_attachments"] = m
102
103 err := j.Write(rw)
104 if err != nil {
105 http.Error(rw, "writing json", http.StatusInternalServerError)
106 }
107 return
108}