From 899ac49336e958d98500ad8c65f45d0bc602883f Mon Sep 17 00:00:00 2001 From: "Felipe M." Date: Sun, 15 Jun 2025 13:03:52 +0200 Subject: [PATCH] chore: split plugin configuration templates --- internal/admin/admin.go | 26 ++++++++++++++-- .../templates/channel_plugin_config.html | 31 ++----------------- .../plugins/security.domainblock.html | 12 +++++++ .../templates/plugins/social.instagram.html | 11 +++++++ .../templates/plugins/social.twitter.html | 11 +++++++ 5 files changed, 60 insertions(+), 31 deletions(-) create mode 100644 internal/admin/templates/plugins/security.domainblock.html create mode 100644 internal/admin/templates/plugins/social.instagram.html create mode 100644 internal/admin/templates/plugins/social.twitter.html diff --git a/internal/admin/admin.go b/internal/admin/admin.go index 2b41820..cfa2595 100644 --- a/internal/admin/admin.go +++ b/internal/admin/admin.go @@ -16,7 +16,7 @@ import ( "github.com/gorilla/sessions" ) -//go:embed templates/*.html +//go:embed templates/*.html templates/plugins/*.html var templateFS embed.FS const ( @@ -90,7 +90,7 @@ func New(cfg *config.Config, database *db.Database, version string) *Admin { } // Parse and register all templates - templateFiles := []string{ + mainTemplateFiles := []string{ "index.html", "login.html", "change_password.html", @@ -101,7 +101,13 @@ func New(cfg *config.Config, database *db.Database, version string) *Admin { "channel_plugin_config.html", } - for _, tf := range templateFiles { + pluginTemplateFiles := []string{ + "plugins/security.domainblock.html", + "plugins/social.instagram.html", + "plugins/social.twitter.html", + } + + for _, tf := range mainTemplateFiles { // Read template content from embedded filesystem content, err := templateFS.ReadFile("templates/" + tf) if err != nil { @@ -120,6 +126,20 @@ func New(cfg *config.Config, database *db.Database, version string) *Admin { panic(err) } + // If this is the channel_plugin_config template, also parse plugin templates + if tf == "channel_plugin_config.html" { + for _, pluginTf := range pluginTemplateFiles { + pluginContent, err := templateFS.ReadFile("templates/" + pluginTf) + if err != nil { + panic(err) + } + t, err = t.Parse(string(pluginContent)) + if err != nil { + panic(err) + } + } + } + templates[tf] = t } diff --git a/internal/admin/templates/channel_plugin_config.html b/internal/admin/templates/channel_plugin_config.html index 2719004..0f229f9 100644 --- a/internal/admin/templates/channel_plugin_config.html +++ b/internal/admin/templates/channel_plugin_config.html @@ -9,36 +9,11 @@
{{if eq .ChannelPlugin.PluginID "security.domainblock"}} -
- - -
- Enter comma-separated list of domains to block (e.g., example.com, evil.org). - Messages containing links to these domains will be blocked. -
-
+ {{template "plugins/security.domainblock.html" .}} {{else if eq .ChannelPlugin.PluginID "social.instagram"}} -
- - -
- Enter the domain to replace instagram.com links with. Default is ddinstagram.com if left empty. -
-
+ {{template "plugins/social.instagram.html" .}} {{else if eq .ChannelPlugin.PluginID "social.twitter"}} -
- - -
- Enter the domain to replace twitter.com and x.com links with. Default is fxtwitter.com if left empty. -
-
+ {{template "plugins/social.twitter.html" .}} {{else}}
This plugin doesn't have specific configuration fields implemented yet. diff --git a/internal/admin/templates/plugins/security.domainblock.html b/internal/admin/templates/plugins/security.domainblock.html new file mode 100644 index 0000000..7ffcc48 --- /dev/null +++ b/internal/admin/templates/plugins/security.domainblock.html @@ -0,0 +1,12 @@ +{{define "plugins/security.domainblock.html"}} +
+ + +
+ Enter comma-separated list of domains to block (e.g., example.com, evil.org). + Messages containing links to these domains will be blocked. +
+
+{{end}} \ No newline at end of file diff --git a/internal/admin/templates/plugins/social.instagram.html b/internal/admin/templates/plugins/social.instagram.html new file mode 100644 index 0000000..a83485d --- /dev/null +++ b/internal/admin/templates/plugins/social.instagram.html @@ -0,0 +1,11 @@ +{{define "plugins/social.instagram.html"}} +
+ + +
+ Enter the domain to replace instagram.com links with. Default is ddinstagram.com if left empty. +
+
+{{end}} \ No newline at end of file diff --git a/internal/admin/templates/plugins/social.twitter.html b/internal/admin/templates/plugins/social.twitter.html new file mode 100644 index 0000000..cb4885f --- /dev/null +++ b/internal/admin/templates/plugins/social.twitter.html @@ -0,0 +1,11 @@ +{{define "plugins/social.twitter.html"}} +
+ + +
+ Enter the domain to replace twitter.com and x.com links with. Default is fxtwitter.com if left empty. +
+
+{{end}} \ No newline at end of file