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