diff --git a/example-config.toml b/example-config.toml index bd472f2..62ab4e5 100644 --- a/example-config.toml +++ b/example-config.toml @@ -21,3 +21,7 @@ dirs = ["/var/gemini", "/var/gemini/my_gemlog"] max_comments = 5 # If this is missing, or is 0 or < -1, then 5 is the default. # Setting it to -1 disables comments globally. + +# Disables Likes for all files +disable_likes = false +# Must be true or false \ No newline at end of file diff --git a/like/like.go b/like/like.go index 4dbb641..b01375e 100644 --- a/like/like.go +++ b/like/like.go @@ -64,6 +64,12 @@ func main() { shared.RespondError("File not valid for liking.") return } + + if shared.LikesDisabled { + shared.RespondError("Likes have been disabled.") + return + } + already, err := hasLikedAlready(file, ip) shared.HandleErr(err) if already { diff --git a/shared/shared.go b/shared/shared.go index 767afd7..217e9e1 100644 --- a/shared/shared.go +++ b/shared/shared.go @@ -13,6 +13,7 @@ import ( ) var ErrConfigDir = errors.New("config dir invalid or not set") +var LikesDisabled = false func PathExists(path string) bool { _, err := os.Stat(path) @@ -88,6 +89,10 @@ func SafeInit() error { // No remote addr return errors.New("no REMOTE_ADDR specified, server CGI error") } + // Get config "disable_likes" variable + if config.Get("disable_likes") != nil { + LikesDisabled = config.Get("disable_likes").(bool) + } return nil } diff --git a/view/view.go b/view/view.go index 8a566c7..8263a44 100644 --- a/view/view.go +++ b/view/view.go @@ -45,13 +45,16 @@ func main() { } // Display likes - likes, err := numLikes(file) - shared.HandleErr(err) - likesStr := "likes! 💖" - if likes == 1 { - likesStr = "like. 💖" + likesResponse := "" + if !shared.LikesDisabled { + likes, err := numLikes(file) + shared.HandleErr(err) + likesStr := "likes! 💖" + if likes == 1 { + likesStr = "like. 💖" + } + likesResponse = fmt.Sprintf("# %s\n\n%d %s\n=> like?%s Add yours\n\n", file, likes, likesStr, shared.PathEscape(file)) } - likesResponse := fmt.Sprintf("# %s\n\n%d %s\n=> like?%s Add yours\n\n", file, likes, likesStr, shared.PathEscape(file)) // Display comments