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