Browse Source

Support blacklist for terms that prevent a public post

This adds a BLACKLIST_TERMS configuration value that contains a
comma-separated list of terms that indicate spam posts and will prevent
a link from being showcased on the Browse page, tweeted out, etc.
pull/4/head
Matt Baer 6 years ago
parent
commit
2caebcfecf
4 changed files with 19 additions and 1 deletions
  1. +1
    -0
      README.md
  2. +11
    -0
      config.go
  3. +1
    -1
      construction.go
  4. +6
    -0
      filter.go

+ 1
- 0
README.md View File

@@ -55,6 +55,7 @@ DB_USER=dbuser DB_PASSWORD=pass DB_DB=htmlhouse PRIVATE_KEY=keys/dev PUBLIC_KEY=
| `PREVIEWS_HOST` | Fully-qualified URL (without trailing slash) of screenshot server | None. |
| `ADMIN_PASS` | Password to perform admin functions via API | `uhoh` |
| `BROWSE_ITEMS` | Number of items to show on Browse page | 10 |
| `BLACKLIST_TERMS` | Comma-separated list of terms to prevent a post from being made public | None. |
| `TWITTER_KEY` | Twitter consumer key | `notreal` |
| `TWITTER_SECRET` | Twitter consumer secret | `notreal` |
| `TWITTER_TOKEN` | Twitter access token of the posting Twitter account | `notreal` |


+ 11
- 0
config.go View File

@@ -2,6 +2,8 @@ package htmlhouse

import (
"github.com/danryan/env"
"regexp"
"strings"
)

type config struct {
@@ -23,6 +25,9 @@ type config struct {
AdminPass string `env:"key=ADMIN_PASS default=uhoh"`
BrowseItems int `env:"key=BROWSE_ITEMS default=10"`

BlacklistTerms string `env:"key=BLACKLIST_TERMS"`
BlacklistReg *regexp.Regexp

// Twitter configuration
TwitterConsumerKey string `env:"key=TWITTER_KEY default=notreal"`
TwitterConsumerSecret string `env:"key=TWITTER_SECRET default=notreal"`
@@ -36,5 +41,11 @@ func newConfig() (*config, error) {
return cfg, err
}

// Process anything
termsReg := `(?i)\b` + cfg.BlacklistTerms + `\b`
termsReg = strings.Replace(termsReg, ",", `\b|\b`, -1)
cfg.BlacklistReg = regexp.MustCompile(termsReg)

// Return result
return cfg, nil
}

+ 1
- 1
construction.go View File

@@ -39,7 +39,7 @@ func createHouse(app *app, w http.ResponseWriter, r *http.Request) error {

resUser := newSessionInfo(houseID)

if public {
if public && passesPublicFilter(app, html) {
go addPublicAccess(app, houseID, html)
}



+ 6
- 0
filter.go View File

@@ -0,0 +1,6 @@
package htmlhouse

func passesPublicFilter(app *app, html string) bool {
spam := app.cfg.BlacklistReg.MatchString(html)
return !spam
}

Loading…
Cancel
Save