refactor(admin): simplify editorial event administration
This commit is contained in:
1 parent
736bcc1d78
commit
4ebdfd7b05
1 file changed
+1
-50
@@ -82,7 +82,6 @@ type adminHandler struct {
|
||||
users *userStore
|
||||
team *teamStore
|
||||
forum *forumStore
|
||||
destinationOne *destinationOneImporter
|
||||
newsStudio *newsStudioStore
|
||||
aiJobs *aiJobStore
|
||||
firebasePush *firebasePushService
|
||||
@@ -185,7 +184,6 @@ type adminSettingsData struct {
|
||||
SettingsPath string
|
||||
OpenAIKeySet bool
|
||||
ElevenLabsKeySet bool
|
||||
DestinationOneKeySet bool
|
||||
Error string
|
||||
Success string
|
||||
OpenAIModels []providerModel
|
||||
@@ -365,7 +363,6 @@ func newAdminHandler(logger *log.Logger, weather *WeatherService, data PageData,
|
||||
var database *postgresStore
|
||||
var team *teamStore
|
||||
var forum *forumStore
|
||||
var destinationOne *destinationOneImporter
|
||||
var navigation *navigationStore
|
||||
var directory *directoryStore
|
||||
for _, extra := range extras {
|
||||
@@ -388,8 +385,6 @@ func newAdminHandler(logger *log.Logger, weather *WeatherService, data PageData,
|
||||
team = value
|
||||
case *forumStore:
|
||||
forum = value
|
||||
case *destinationOneImporter:
|
||||
destinationOne = value
|
||||
case *navigationStore:
|
||||
navigation = value
|
||||
case *directoryStore:
|
||||
@@ -573,7 +568,6 @@ func newAdminHandler(logger *log.Logger, weather *WeatherService, data PageData,
|
||||
users: newUserStore(database),
|
||||
team: team,
|
||||
forum: forum,
|
||||
destinationOne: destinationOne,
|
||||
newsStudio: newsStudio,
|
||||
aiJobs: newAIJobStore(),
|
||||
firebasePush: firebasePush,
|
||||
@@ -594,7 +588,6 @@ func (a *adminHandler) register(mux *http.ServeMux) {
|
||||
mux.HandleFunc("/admin/downloads", a.withPermission("downloads.manage", a.adminDownloads))
|
||||
mux.HandleFunc("/admin/app/push", a.withPermission("settings.manage", a.adminAppPush))
|
||||
mux.HandleFunc("/admin/settings", a.withPermission("settings.manage", a.adminSettings))
|
||||
mux.HandleFunc("/admin/settings/import-events", a.withPermission("settings.manage", a.adminSettingsImportEvents))
|
||||
mux.HandleFunc("/admin/settings/background-music", a.withPermission("settings.manage", a.adminBackgroundMusic))
|
||||
mux.HandleFunc("/admin/ai", a.withPermission("ai.use", a.adminAI))
|
||||
mux.HandleFunc("/admin/ai/news", a.withPermission("ai.use", a.adminNewsStudio))
|
||||
@@ -629,7 +622,6 @@ func (a *adminHandler) register(mux *http.ServeMux) {
|
||||
mux.HandleFunc("/admin/api/charts/generate", a.adminChartsGenerate)
|
||||
mux.HandleFunc("/admin/api/charts/year-info/generate", a.adminChartYearInfoGenerate)
|
||||
mux.HandleFunc("/admin/events", a.adminManagement)
|
||||
mux.HandleFunc("/admin/niedersachsen-hub", a.withPermission("settings.manage", a.adminTourismHub))
|
||||
mux.HandleFunc("/admin/excursions", a.withPermission("excursions.manage", a.adminExcursions))
|
||||
mux.HandleFunc("/admin/navigation", a.withPermission("navigation.manage", a.adminNavigation))
|
||||
mux.HandleFunc("/admin/directory", a.withPermission("directory.manage", a.adminDirectory))
|
||||
@@ -1478,16 +1470,6 @@ func (a *adminHandler) adminSettings(w http.ResponseWriter, r *http.Request) {
|
||||
next.Social.FacebookAPIVersion = r.FormValue("facebook_api_version")
|
||||
next.Social.PublicBaseURL = r.FormValue("social_public_base_url")
|
||||
next.Social.WhatsAppChannelURL = r.FormValue("whatsapp_channel_url")
|
||||
next.DestinationOne.Enabled = r.FormValue("destination_one_enabled") == "on"
|
||||
next.DestinationOne.APIURL = r.FormValue("destination_one_api_url")
|
||||
if value := strings.TrimSpace(r.FormValue("destination_one_api_key")); value != "" {
|
||||
next.DestinationOne.APIKey = value
|
||||
}
|
||||
next.DestinationOne.KeyParameter = r.FormValue("destination_one_key_parameter")
|
||||
next.DestinationOne.Experience = r.FormValue("destination_one_experience")
|
||||
next.DestinationOne.ExperienceParam = r.FormValue("destination_one_experience_parameter")
|
||||
next.DestinationOne.IntervalMinutes, _ = strconv.Atoi(r.FormValue("destination_one_interval_minutes"))
|
||||
next.DestinationOne.AutoPublish = r.FormValue("destination_one_auto_publish") == "on"
|
||||
labels := r.Form["voice_label"]
|
||||
ids := r.Form["voice_id"]
|
||||
purposes := r.Form["voice_purpose"]
|
||||
@@ -1540,7 +1522,6 @@ func (a *adminHandler) renderSettings(w http.ResponseWriter, session adminSessio
|
||||
data.SettingsPath = a.settings.Path()
|
||||
data.OpenAIKeySet = data.Settings.OpenAI.APIKey != ""
|
||||
data.ElevenLabsKeySet = data.Settings.ElevenLabs.APIKey != ""
|
||||
data.DestinationOneKeySet = data.Settings.DestinationOne.APIKey != ""
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 8*time.Second)
|
||||
defer cancel()
|
||||
if models, err := a.ai.ListOpenAIModels(ctx); err == nil {
|
||||
@@ -1553,7 +1534,6 @@ func (a *adminHandler) renderSettings(w http.ResponseWriter, session adminSessio
|
||||
}
|
||||
data.Settings.OpenAI.APIKey = ""
|
||||
data.Settings.ElevenLabs.APIKey = ""
|
||||
data.Settings.DestinationOne.APIKey = ""
|
||||
setAdminHTMLHeaders(w)
|
||||
if err := a.settingsTemplate.ExecuteTemplate(w, "settings-admin.html", data); err != nil {
|
||||
a.logger.Printf("admin settings template: %v", err)
|
||||
@@ -2597,7 +2577,7 @@ func adminNavigationHTML() string {
|
||||
<span class="admin-nav-subheading">Redaktion</span>
|
||||
<a href="/admin/editorial" data-admin-nav-link>Redaktion & Beiträge</a><a href="/admin/mediathek" data-admin-nav-link>Mediathek</a><a href="/admin/media" data-admin-nav-link>Mediengalerie</a><a href="/admin/presse" data-admin-nav-link>Pressebereich</a><a href="/admin/karriere" data-admin-nav-link>Karriere</a><a href="/admin/faq" data-admin-nav-link>FAQ</a><a href="/admin/kontakt" data-admin-nav-link>Kontakt & Anfragen</a><a href="/admin/team" data-admin-nav-link>Team</a>
|
||||
<span class="admin-nav-subheading">Planung & Verzeichnisse</span>
|
||||
<a href="/admin/program" data-admin-nav-link>Programm</a><a href="/admin/events" data-admin-nav-link>Veranstaltungen</a><a href="/admin/niedersachsen-hub" data-admin-nav-link>Niedersachsen Hub · Tourismus</a><a href="/admin/excursions" data-admin-nav-link>Ausflugstipps</a><a href="/admin/directory" data-admin-nav-link>Branchenbuch</a><a href="/admin/navigation" data-admin-nav-link>Website-Navigation</a>
|
||||
<a href="/admin/program" data-admin-nav-link>Programm</a><a href="/admin/events" data-admin-nav-link>Veranstaltungen</a><a href="/admin/excursions" data-admin-nav-link>Ausflugstipps</a><a href="/admin/directory" data-admin-nav-link>Branchenbuch</a><a href="/admin/navigation" data-admin-nav-link>Website-Navigation</a>
|
||||
</div></details>
|
||||
<details data-admin-nav-group="community"><summary><i>♫</i><span><strong>Hörer & Community</strong><small>Charts, Wünsche und Forum</small></span><b>⌄</b></summary><div>
|
||||
<span class="admin-nav-subheading">Höreraktionen</span>
|
||||
@@ -3035,35 +3015,6 @@ func (a *adminHandler) adminNewsStudio(w http.ResponseWriter, r *http.Request) {
|
||||
render()
|
||||
}
|
||||
|
||||
func (a *adminHandler) adminSettingsImportEvents(w http.ResponseWriter, r *http.Request) {
|
||||
_, session, ok := a.sessionFromRequest(r)
|
||||
if !ok {
|
||||
http.Redirect(w, r, "/admin/login", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "Methode nicht erlaubt", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
_ = r.ParseForm()
|
||||
if subtle.ConstantTimeCompare([]byte(r.FormValue("csrf_token")), []byte(session.CSRFToken)) != 1 {
|
||||
http.Error(w, "Ungültige Sicherheitsprüfung", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
if a.destinationOne == nil {
|
||||
a.renderSettings(w, session, adminSettingsData{Settings: a.settings.Get(), Error: "destination.one ist nicht verfügbar."})
|
||||
return
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 2*time.Minute)
|
||||
defer cancel()
|
||||
n, err := a.destinationOne.Sync(ctx)
|
||||
if err != nil {
|
||||
a.renderSettings(w, session, adminSettingsData{Settings: a.settings.Get(), Error: "Import fehlgeschlagen: " + err.Error()})
|
||||
return
|
||||
}
|
||||
a.renderSettings(w, session, adminSettingsData{Settings: a.settings.Get(), Success: fmt.Sprintf("Import abgeschlossen: %d Veranstaltungen verarbeitet.", n)})
|
||||
}
|
||||
|
||||
func (a *adminHandler) adminBackgroundMusic(w http.ResponseWriter, r *http.Request) {
|
||||
_, session, ok := a.sessionFromRequest(r)
|
||||
if !ok {
|
||||
|
||||
Reference in new issue
Block a user