2023-07-03 15:30:14 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2023 Laura Kalb <dev@lauka.net>
|
|
|
|
* The code of this project is available under the MIT license. See the LICENSE file for more info.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
package misc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/microcosm-cc/bluemonday"
|
2023-07-07 09:32:01 +02:00
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"github.com/spf13/viper"
|
2023-07-03 15:30:14 +02:00
|
|
|
"html"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Sanitize(d string) string {
|
|
|
|
p := bluemonday.StrictPolicy()
|
|
|
|
return html.UnescapeString(p.Sanitize(d))
|
|
|
|
}
|
2023-07-07 09:32:01 +02:00
|
|
|
|
|
|
|
func CheckConfig() {
|
|
|
|
visibility := viper.GetString("mastodon.visibility")
|
|
|
|
visibilityallowed := []string{"public", "unlisted", "private"}
|
|
|
|
|
|
|
|
if !isValueInList(visibility, visibilityallowed) {
|
|
|
|
log.Fatal().Str("component", "config").Str("config_item", "mastodon.visibility").
|
|
|
|
Msgf("Config value must be one of [public, unlisted, private]: %q", visibility)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func isValueInList(value string, list []string) bool {
|
|
|
|
for _, v := range list {
|
|
|
|
if v == value {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|