all repos — honk @ 7c31c81900be29458c243fe9558f51c1b9243948

my fork of honk

masto.go (view raw)

 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
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
package main

import (
	"fmt"
	"net/http"

	"humungus.tedunangst.com/r/webs/junk"
)

func badjunk(rw http.ResponseWriter, j junk.Junk, path string) {
	elog.Printf("%s: bad junk: %s", path, j.ToString())
	http.Error(rw, fmt.Sprintf("%s: bad junk", path), http.StatusBadRequest)
}

// https://docs.joinmastodon.org/methods/apps/#create
func apiapps(rw http.ResponseWriter, r *http.Request) {
	if err := r.ParseForm(); err != nil {
		http.Error(rw, "invalid input", http.StatusBadRequest)
		return
	}
	clientName := r.Form.Get("client_name")
	redirectUris := r.Form.Get("redirect_uris")
	scopes := r.Form.Get("scopes")
	web := r.Form.Get("website")

	dlog.Println(clientName, redirectUris, scopes, web)
}

// https://docs.joinmastodon.org/methods/oauth/#authorize
func oauthorize(rw http.ResponseWriter, r *http.Request) {
	dlog.Println(r.URL.RawQuery)
}

// https://docs.joinmastodon.org/methods/instance/#v2
func instance(rw http.ResponseWriter, r *http.Request) {
	j := junk.New()

	var servername string
	if err := getconfig("servername", &servername); err != nil {
		http.Error(rw, "getting servername", http.StatusInternalServerError)
		return
	}

	j["uri"] = servername
	j["title"] = "honk"
	j["description"] = "federated honk conveyance"
	j["version"] = "develop"

	thumbnail := junk.New()
	thumbnail["url"] = fmt.Sprintf("https://%s/icon.png", servername)
	j["thumbnail"] = thumbnail
	j["languages"] = []string{"en"}

	config := junk.New()

	a := junk.New()
	a["max_featured_tags"] = 10
	config["accounts"] = a

	s := junk.New()
	s["max_characters"] = 5000
	s["max_media_attachments"] = 1
	s["characters_reserved_per_url"] = 23
	config["statuses"] = s

	m := junk.New()
	m["supported_mime_types"] = []string{
		"image/jpeg",
		"image/png",
		"image/gif",
		"image/heic",
		"image/heif",
		"image/webp",
		"image/avif",
		"video/webm",
		"video/mp4",
		"video/quicktime",
		"video/ogg",
		"audio/wave",
		"audio/wav",
		"audio/x-wav",
		"audio/x-pn-wave",
		"audio/vnd.wave",
		"audio/ogg",
		"audio/vorbis",
		"audio/mpeg",
		"audio/mp3",
		"audio/webm",
		"audio/flac",
		"audio/aac",
		"audio/m4a",
		"audio/x-m4a",
		"audio/mp4",
		"audio/3gpp",
		"video/x-ms-asf",
	}

	m["image_size_limit"] = 10485760
	m["image_matrix_limit"] = 16777216
	m["video_size_limit"] = 41943040
	m["video_frame_rate_limit"] = 60
	m["video_matrix_limit"] = 2304000
	j["media_attachments"] = m

	err := j.Write(rw)
	if err != nil {
		http.Error(rw, "writing json", http.StatusInternalServerError)
	}
	return
}