chore: split plugin configuration templates
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/tag/release Pipeline was successful

This commit is contained in:
Felipe M 2025-06-15 13:03:52 +02:00
parent fc77c97547
commit 899ac49336
Signed by: fmartingr
GPG key ID: CCFBC5637D4000A8
5 changed files with 60 additions and 31 deletions

View file

@ -16,7 +16,7 @@ import (
"github.com/gorilla/sessions" "github.com/gorilla/sessions"
) )
//go:embed templates/*.html //go:embed templates/*.html templates/plugins/*.html
var templateFS embed.FS var templateFS embed.FS
const ( const (
@ -90,7 +90,7 @@ func New(cfg *config.Config, database *db.Database, version string) *Admin {
} }
// Parse and register all templates // Parse and register all templates
templateFiles := []string{ mainTemplateFiles := []string{
"index.html", "index.html",
"login.html", "login.html",
"change_password.html", "change_password.html",
@ -101,7 +101,13 @@ func New(cfg *config.Config, database *db.Database, version string) *Admin {
"channel_plugin_config.html", "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 // Read template content from embedded filesystem
content, err := templateFS.ReadFile("templates/" + tf) content, err := templateFS.ReadFile("templates/" + tf)
if err != nil { if err != nil {
@ -120,6 +126,20 @@ func New(cfg *config.Config, database *db.Database, version string) *Admin {
panic(err) 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 templates[tf] = t
} }

View file

@ -9,36 +9,11 @@
<form method="post"> <form method="post">
<!-- Plugin configuration fields --> <!-- Plugin configuration fields -->
{{if eq .ChannelPlugin.PluginID "security.domainblock"}} {{if eq .ChannelPlugin.PluginID "security.domainblock"}}
<div class="mb-3"> {{template "plugins/security.domainblock.html" .}}
<label class="form-label">Blocked Domains</label>
<input type="text" class="form-control" name="blocked_domains"
value="{{with .ChannelPlugin.Config}}{{index . "blocked_domains"}}{{end}}"
placeholder="example.com, evil.org, ads.com">
<div class="form-text text-muted">
Enter comma-separated list of domains to block (e.g., example.com, evil.org).
Messages containing links to these domains will be blocked.
</div>
</div>
{{else if eq .ChannelPlugin.PluginID "social.instagram"}} {{else if eq .ChannelPlugin.PluginID "social.instagram"}}
<div class="mb-3"> {{template "plugins/social.instagram.html" .}}
<label class="form-label">Replacement Domain</label>
<input type="text" class="form-control" name="domain"
value="{{with .ChannelPlugin.Config}}{{index . "domain"}}{{end}}"
placeholder="ddinstagram.com">
<div class="form-text text-muted">
Enter the domain to replace instagram.com links with. Default is ddinstagram.com if left empty.
</div>
</div>
{{else if eq .ChannelPlugin.PluginID "social.twitter"}} {{else if eq .ChannelPlugin.PluginID "social.twitter"}}
<div class="mb-3"> {{template "plugins/social.twitter.html" .}}
<label class="form-label">Replacement Domain</label>
<input type="text" class="form-control" name="domain"
value="{{with .ChannelPlugin.Config}}{{index . "domain"}}{{end}}"
placeholder="fxtwitter.com">
<div class="form-text text-muted">
Enter the domain to replace twitter.com and x.com links with. Default is fxtwitter.com if left empty.
</div>
</div>
{{else}} {{else}}
<div class="alert alert-warning"> <div class="alert alert-warning">
This plugin doesn't have specific configuration fields implemented yet. This plugin doesn't have specific configuration fields implemented yet.

View file

@ -0,0 +1,12 @@
{{define "plugins/security.domainblock.html"}}
<div class="mb-3">
<label class="form-label">Blocked Domains</label>
<input type="text" class="form-control" name="blocked_domains"
value="{{with .ChannelPlugin.Config}}{{index . "blocked_domains"}}{{end}}"
placeholder="example.com, evil.org, ads.com">
<div class="form-text text-muted">
Enter comma-separated list of domains to block (e.g., example.com, evil.org).
Messages containing links to these domains will be blocked.
</div>
</div>
{{end}}

View file

@ -0,0 +1,11 @@
{{define "plugins/social.instagram.html"}}
<div class="mb-3">
<label class="form-label">Replacement Domain</label>
<input type="text" class="form-control" name="domain"
value="{{with .ChannelPlugin.Config}}{{index . "domain"}}{{end}}"
placeholder="ddinstagram.com">
<div class="form-text text-muted">
Enter the domain to replace instagram.com links with. Default is ddinstagram.com if left empty.
</div>
</div>
{{end}}

View file

@ -0,0 +1,11 @@
{{define "plugins/social.twitter.html"}}
<div class="mb-3">
<label class="form-label">Replacement Domain</label>
<input type="text" class="form-control" name="domain"
value="{{with .ChannelPlugin.Config}}{{index . "domain"}}{{end}}"
placeholder="fxtwitter.com">
<div class="form-text text-muted">
Enter the domain to replace twitter.com and x.com links with. Default is fxtwitter.com if left empty.
</div>
</div>
{{end}}