Skip to content
This repository has been archived by the owner on Aug 6, 2023. It is now read-only.

Commit

Permalink
Added Global Likes Disable option to config file (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-kraft authored Feb 15, 2021
1 parent 0c11120 commit 293b250
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions example-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions like/like.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down
15 changes: 9 additions & 6 deletions view/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 293b250

Please sign in to comment.