diff options
author | FChannel <> | 2021-07-13 21:10:39 -0700 |
---|---|---|
committer | FChannel <> | 2021-07-13 21:10:39 -0700 |
commit | 05bfa634cf8c42123c8c0a19e65aff7320dadf41 (patch) | |
tree | bf838eec3a2ba77e61261d9c2cc28e04f1725cad /database.go | |
parent | 6ba4ff0a930f3a3c053af2553950fcfe5b5ad180 (diff) |
added regex blacklist for posts in admin page
Diffstat (limited to 'database.go')
-rw-r--r-- | database.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/database.go b/database.go index 5668a4d..0e53142 100644 --- a/database.go +++ b/database.go @@ -1598,3 +1598,54 @@ func WriteNewsToDB(db *sql.DB, news NewsItem) { CheckError(err, "error writing news item") } + +func WriteRegexBlacklistDB(db *sql.DB, regex string) { + query := `select from postblacklist where regex=$1` + + rows, err := db.Query(query, regex) + + CheckError(err, "error select from postblacklist db") + + var re string + defer rows.Close() + rows.Next() + rows.Scan(&re) + + if re != "" { + return + } + + query = `insert into postblacklist (regex) values ($1)` + + _, err = db.Exec(query, regex) + + CheckError(err, "error inserting postblacklist into db") +} + +func GetRegexBlacklistDB(db *sql.DB) []PostBlacklist { + query := `select id, regex from postblacklist` + + rows, err := db.Query(query) + + CheckError(err, "error with select all from postblacklist db") + + var List []PostBlacklist + + defer rows.Close() + for rows.Next() { + var temp PostBlacklist + rows.Scan(&temp.Id, &temp.Regex) + + List = append(List, temp) + } + + return List +} + +func DeleteRegexBlacklistDB(db *sql.DB, id int) { + query := `delete from postblacklist where id=$1` + + _, err := db.Exec(query, id) + + CheckError(err, "error with delete from postblacklist") +} |