7c05b59708
gates / gates (push) Successful in 24s
179 Hungarian sentences were built deep inside a package with fmt.Errorf and printed by whoever caught them: too late to translate where they are shown, too early where they are made. Every one now carries its key across that gap. ZERO Hungarian error literals remain. util.MsgError does three things at once, each earned: - Error() is the Hungarian, byte for byte, so every un-converted printer is unchanged; - errors.Is answers for the kind AND for a wrapped cause (KindErrorf dropped the cause); - an error ARGUMENT renders recursively, so "formázás sikertelen: %w" translates whole. A foreign error — restic, docker, ssh, the stdlib — prints verbatim. It is not ours. 76 display sites go through errText, and TestNoErrErrorInPageOutput convicts any that do not. memoryVerdict returns an error rather than a sentence, so the deploy's 409 and the household's language come from one value; UpdateRefusal gained a Cause to carry it. Plurals, one rule, stated once: a key with .one/.other takes its COUNT first. Not a per-call-site flag — the producer somebody forgot would read "3 app is not running". The guard caught a real key collision (alert.deadapp.one) the day the rule landed. TWO DEFECTS FOUND IN MY OWN TOOLING, recorded rather than quietly fixed. The bulk converter silently dropped multi-line concatenations, damaging 7 producers — and the parity gate could not see it, because every surviving fragment WAS a real base literal while the CALL had lost text; two behaviour tests caught it. And the counting script was case-sensitive, so it said "0 left" while five remained. MinAgent: 0.131.0 (unchanged). No hub release needed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
128 lines
4.6 KiB
Go
128 lines
4.6 KiB
Go
package integrations
|
|
|
|
import (
|
|
"fmt"
|
|
"gitea.dooplex.hu/admin/felhom-controller/internal/util"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// OnlyOfficeFileBrowserHandler enables/disables OnlyOffice document editing in FileBrowser Quantum.
|
|
type OnlyOfficeFileBrowserHandler struct{}
|
|
|
|
func (h *OnlyOfficeFileBrowserHandler) Apply(ac *ApplyContext) error {
|
|
jwtSecret := ac.ProviderEnv["JWT_SECRET"]
|
|
if jwtSecret == "" {
|
|
ac.Logger.Printf("[ERROR] [integrations] OnlyOffice-FileBrowser apply: JWT_SECRET not set")
|
|
return util.MsgError("err.integrations.onlyoffice_jwt_secret_nincs_beallitva_telepitsd")
|
|
}
|
|
|
|
subdomain := ac.ProviderEnv["SUBDOMAIN"]
|
|
if subdomain == "" && ac.ProviderMeta != nil {
|
|
subdomain = ac.ProviderMeta.Subdomain
|
|
}
|
|
if subdomain == "" {
|
|
ac.Logger.Printf("[ERROR] [integrations] OnlyOffice-FileBrowser apply: subdomain unknown")
|
|
return util.MsgError("err.integrations.onlyoffice_no_subdomain")
|
|
}
|
|
|
|
configPath := filepath.Join(ac.StacksDir, "filebrowser", "config.yaml")
|
|
officeURL := fmt.Sprintf("https://%s.%s", subdomain, ac.Domain)
|
|
|
|
configData, err := os.ReadFile(configPath)
|
|
if err != nil {
|
|
ac.Logger.Printf("[ERROR] [integrations] OnlyOffice-FileBrowser apply: %v", err)
|
|
return util.MsgError("err.integrations.filebrowser_config_olvasasi_hiba", err)
|
|
}
|
|
|
|
// Remove any existing integrations section, then append the new one
|
|
configStr := removeIntegrationsSection(string(configData))
|
|
|
|
internalURL := "http://onlyoffice:80"
|
|
|
|
integrationsBlock := fmt.Sprintf("integrations:\n office:\n url: %q\n internalUrl: %q\n secret: %q\n viewOnly: false\n",
|
|
officeURL, internalURL, jwtSecret)
|
|
|
|
configStr = strings.TrimRight(configStr, "\n") + "\n" + integrationsBlock
|
|
|
|
// Atomic write
|
|
tmpPath := configPath + ".tmp"
|
|
if err := os.WriteFile(tmpPath, []byte(configStr), 0644); err != nil {
|
|
ac.Logger.Printf("[ERROR] [integrations] OnlyOffice-FileBrowser apply: %v", err)
|
|
return util.MsgError("err.integrations.config_irasi_hiba", err)
|
|
}
|
|
if err := os.Rename(tmpPath, configPath); err != nil {
|
|
_ = os.Remove(tmpPath)
|
|
ac.Logger.Printf("[ERROR] [integrations] OnlyOffice-FileBrowser apply: %v", err)
|
|
return util.MsgError("err.integrations.config_atnevezesi_hiba", err)
|
|
}
|
|
|
|
ac.Logger.Printf("[INFO] [integrations] FileBrowser config updated with OnlyOffice integration")
|
|
return ac.RestartStack("filebrowser")
|
|
}
|
|
|
|
func (h *OnlyOfficeFileBrowserHandler) Revoke(ac *ApplyContext) error {
|
|
configPath := filepath.Join(ac.StacksDir, "filebrowser", "config.yaml")
|
|
ac.Logger.Printf("[DEBUG] [integrations] OnlyOfficeFileBrowser.Revoke: configPath=%s", configPath)
|
|
|
|
configData, err := os.ReadFile(configPath)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
return nil
|
|
}
|
|
ac.Logger.Printf("[ERROR] [integrations] OnlyOffice-FileBrowser revoke: %v", err)
|
|
return util.MsgError("err.integrations.config_olvasasi_hiba", err)
|
|
}
|
|
|
|
cleaned := removeIntegrationsSection(string(configData))
|
|
hadIntegrations := cleaned != string(configData)
|
|
ac.Logger.Printf("[DEBUG] [integrations] OnlyOfficeFileBrowser.Revoke: integrationsSectionFound=%v", hadIntegrations)
|
|
if !hadIntegrations {
|
|
return nil // no integrations section, nothing to remove
|
|
}
|
|
|
|
tmpPath := configPath + ".tmp"
|
|
if err := os.WriteFile(tmpPath, []byte(cleaned), 0644); err != nil {
|
|
ac.Logger.Printf("[ERROR] [integrations] OnlyOffice-FileBrowser revoke: %v", err)
|
|
return util.MsgError("err.integrations.config_irasi_hiba", err)
|
|
}
|
|
if err := os.Rename(tmpPath, configPath); err != nil {
|
|
_ = os.Remove(tmpPath)
|
|
ac.Logger.Printf("[ERROR] [integrations] OnlyOffice-FileBrowser revoke: %v", err)
|
|
return util.MsgError("err.integrations.config_atnevezesi_hiba", err)
|
|
}
|
|
|
|
ac.Logger.Printf("[INFO] [integrations] FileBrowser config cleaned — OnlyOffice integration removed")
|
|
return ac.RestartStack("filebrowser")
|
|
}
|
|
|
|
// removeIntegrationsSection strips the integrations: YAML block from a config string.
|
|
// It removes from the line starting with "integrations:" to the next unindented key or EOF.
|
|
func removeIntegrationsSection(config string) string {
|
|
lines := strings.Split(config, "\n")
|
|
var result []string
|
|
inBlock := false
|
|
for _, line := range lines {
|
|
if strings.HasPrefix(line, "integrations:") {
|
|
inBlock = true
|
|
continue
|
|
}
|
|
if inBlock {
|
|
trimmed := strings.TrimRight(line, " \t\r")
|
|
if trimmed == "" {
|
|
continue // skip blank lines within block
|
|
}
|
|
if line[0] != ' ' && line[0] != '\t' {
|
|
// New top-level key — end of integrations block
|
|
inBlock = false
|
|
result = append(result, line)
|
|
}
|
|
// else: still inside indented block, skip
|
|
continue
|
|
}
|
|
result = append(result, line)
|
|
}
|
|
return strings.Join(result, "\n")
|
|
}
|