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