1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-17 10:56:24 -07:00

Add custom flag validation, as well as custom flag validation

This commit is contained in:
Eggbertx 2024-01-21 16:02:53 -08:00
parent 2007b90556
commit 51c884ae6b
11 changed files with 30 additions and 4 deletions

View file

@ -42,6 +42,17 @@
],
"DefaultStyle": "pipes.css",
"CustomFlags": [
{"Flag":"california.png", "Name": "California"},
{"Flag":"cia.png", "Name": "CIA"},
{"Flag":"lgbtq.png", "Name": "LGBTQ"},
{"Flag":"ms-dos.png", "Name": "MS-DOS"},
{"Flag":"stallman.png", "Name": "Stallman"},
{"Flag":"templeos.png", "Name": "TempleOS"},
{"Flag":"tux.png", "Name": "Linux"},
{"Flag":"windows9x.png", "Name": "Windows 9x"}
],
"Banners": [
{"Filename": "gochan_go-parody.png", "Width": 300, "Height": 100}
],

Binary file not shown.

After

Width:  |  Height:  |  Size: 915 B

BIN
html/static/flags/cia.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 748 B

BIN
html/static/flags/lgbtq.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 B

BIN
html/static/flags/ms-dos.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 700 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 B

BIN
html/static/flags/tux.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 425 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 504 B

View file

@ -12,6 +12,7 @@ import (
"github.com/Eggbertx/durationutil"
"github.com/gochan-org/gochan/pkg/gcutil"
"github.com/gochan-org/gochan/pkg/posting/geoip"
)
const (
@ -232,10 +233,21 @@ type BoardConfig struct {
ThreadsPerPage int
EnableGeoIP bool
EnableNoFlag bool
CustomFlags map[string]string
CustomFlags []geoip.Country
isGlobal bool
}
// CheckFlag returns true if the given flag and name are configured for
// the board (or are globally set)
func (bc *BoardConfig) CheckFlag(flag string, name string) bool {
for _, country := range bc.CustomFlags {
if flag == country.Flag && name == country.Name {
return true
}
}
return false
}
// IsGlobal returns true if this is the global configuration applied to all
// boards by default, or false if it is an explicitly configured board
func (bc *BoardConfig) IsGlobal() bool {

View file

@ -18,11 +18,14 @@ var (
ErrUnrecognized = errors.New("unrecognized GeoIP handler ID")
)
// Country represents the GeoIP data used by gochan (the country/flag name and
// country abbreviation/flag filename, accessible in /static/flags/{flag}).
// Country represents the country data (or custom flag data) used by gochan.
// For posts set to use the poster's country, `Flag` is the country's
// abbreviation, and `Name` is the country name. If a custom flag is selected,
// Flag is the filename accessible in /static/flags/{flag}, and Name is the
// configured flag name. This package does not handle custom flag validation.
type Country struct {
Name string
Flag string
Name string
}
// IsGeoIP is true of the country has a recognized abbreviation set as its