feat: Persist domain blacklist to blacklist.json

This commit is contained in:
verssache
2026-03-11 00:28:06 +07:00
parent 22ebda8acb
commit d9c6645ce3
2 changed files with 45 additions and 2 deletions

2
.gitignore vendored
View File

@@ -6,3 +6,5 @@ chatgpt-creator
# Config and Results # Config and Results
results.txt results.txt
blacklist.json
results.txt

View File

@@ -1,9 +1,11 @@
package email package email
import ( import (
"encoding/json"
"fmt" "fmt"
"math/rand" "math/rand"
"net/http" "net/http"
"os"
"regexp" "regexp"
"strings" "strings"
"sync" "sync"
@@ -19,13 +21,52 @@ import (
"github.com/verssache/chatgpt-creator/internal/util" "github.com/verssache/chatgpt-creator/internal/util"
) )
var blacklistedDomains sync.Map var (
blacklistedDomains sync.Map
blacklistMutex sync.Mutex
)
func init() {
data, err := os.ReadFile("blacklist.json")
if err != nil {
return // File might not exist yet
}
var domains []string
if err := json.Unmarshal(data, &domains); err != nil {
return
}
for _, domain := range domains {
blacklistedDomains.Store(domain, true)
}
}
func saveBlacklist() {
blacklistMutex.Lock()
defer blacklistMutex.Unlock()
var domains []string
blacklistedDomains.Range(func(key, value any) bool {
if domain, ok := key.(string); ok {
domains = append(domains, domain)
}
return true
})
data, err := json.MarshalIndent(domains, "", " ")
if err != nil {
return
}
_ = os.WriteFile("blacklist.json", data, 0644)
}
// AddBlacklistDomain adds a domain to the global blacklist. // AddBlacklistDomain adds a domain to the global blacklist.
func AddBlacklistDomain(domain string) { func AddBlacklistDomain(domain string) {
blacklistedDomains.Store(domain, true) blacklistedDomains.Store(domain, true)
saveBlacklist()
} }
// CreateTempEmail fetches a new temp email using a random profile and gofakeit names. // CreateTempEmail fetches a new temp email using a random profile and gofakeit names.
func CreateTempEmail(defaultDomain string) (string, error) { func CreateTempEmail(defaultDomain string) (string, error) {
// If defaultDomain is set, skip fetching from generator.email // If defaultDomain is set, skip fetching from generator.email