aboutsummaryrefslogtreecommitdiff
path: root/hotline
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2025-11-18 19:51:02 -0800
committerJeff Halter <868228+jhalter@users.noreply.github.com>2025-11-18 19:52:02 -0800
commit16f0a8527a0b9b736afbd4e71e6aac55e31b60e8 (patch)
treeaf793d94f0bebcbc590fb7fcfe67bae81c1fbb37 /hotline
parent331edfa762e2e53fa0d5bd09fc1e4977f6c9de43 (diff)
Add support for GIF banners with validation and improved error messages
- Add custom validator for banner file extensions (.jpg, .jpeg, .gif) - Update HandleTranAgreed to dynamically detect banner type from file extension - Export FileTypeFromFilename function for use across packages - Add comprehensive test coverage for banner validation and type detection - Improve error messages to clearly communicate allowed file extensions
Diffstat (limited to 'hotline')
-rw-r--r--hotline/config.go2
-rw-r--r--hotline/files.go8
2 files changed, 5 insertions, 5 deletions
diff --git a/hotline/config.go b/hotline/config.go
index a7bd81e..75d5c4d 100644
--- a/hotline/config.go
+++ b/hotline/config.go
@@ -3,7 +3,7 @@ package hotline
type Config struct {
Name string `yaml:"Name" validate:"required,max=50"` // Name used for Tracker registration
Description string `yaml:"Description" validate:"required,max=200"` // Description used for Tracker registration
- BannerFile string `yaml:"BannerFile"` // Path to Banner jpg
+ BannerFile string `yaml:"BannerFile" validate:"omitempty,bannerext"` // Path to Banner jpg or gif
FileRoot string `yaml:"FileRoot" validate:"required"` // Path to Files
EnableTrackerRegistration bool `yaml:"EnableTrackerRegistration"` // Toggle Tracker Registration
Trackers []string `yaml:"Trackers" validate:"dive,hostname_port"` // List of trackers that the server should register with
diff --git a/hotline/files.go b/hotline/files.go
index a1db329..e9f7b4f 100644
--- a/hotline/files.go
+++ b/hotline/files.go
@@ -12,7 +12,7 @@ import (
"strings"
)
-func fileTypeFromFilename(filename string) fileType {
+func FileTypeFromFilename(filename string) fileType {
fileExt := strings.ToLower(filepath.Ext(filename))
ft, ok := fileTypes[fileExt]
if ok {
@@ -26,7 +26,7 @@ func fileTypeFromInfo(info fs.FileInfo) (ft fileType, err error) {
ft.CreatorCode = "n/a "
ft.TypeCode = "fldr"
} else {
- ft = fileTypeFromFilename(info.Name())
+ ft = FileTypeFromFilename(info.Name())
}
return ft, nil
@@ -87,8 +87,8 @@ func GetFileNameList(path string, ignoreList []string) (fields []Field, err erro
copy(fnwi.Creator[:], fileCreator)
} else {
binary.BigEndian.PutUint32(fnwi.FileSize[:], uint32(rFile.Size()))
- copy(fnwi.Type[:], fileTypeFromFilename(rFile.Name()).TypeCode)
- copy(fnwi.Creator[:], fileTypeFromFilename(rFile.Name()).CreatorCode)
+ copy(fnwi.Type[:], FileTypeFromFilename(rFile.Name()).TypeCode)
+ copy(fnwi.Creator[:], FileTypeFromFilename(rFile.Name()).CreatorCode)
}
} else if file.IsDir() {
dir, err := os.ReadDir(filepath.Join(path, file.Name()))