taler-mailbox

Service for asynchronous wallet-to-wallet payment messages
Log | Files | Refs | Submodules | README | LICENSE

commit 8f3e10b92ea5a678fa8915f22283a2c65d970ee0
parent 418673474b3db3cadead3126f25177e36d0a2af6
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Sat, 26 Apr 2025 15:26:48 +0200

correctly find tos from datahome

Diffstat:
Mpkg/rest/mailbox.go | 54+++++++++++++++++++++++++++++++++++-------------------
1 file changed, 35 insertions(+), 19 deletions(-)

diff --git a/pkg/rest/mailbox.go b/pkg/rest/mailbox.go @@ -25,6 +25,7 @@ import ( "crypto/sha512" "encoding/binary" "encoding/json" + "errors" "fmt" "io" "log" @@ -47,6 +48,23 @@ import ( type TalerMailboxBoxySize int +type MailboxConfig struct { + // Version + Version string + + // Data home + Datahome string + + // Configuration + Ini *ini.File + + // DB connection + Db gorm.Dialector + + // Merchant connection + Merchant merchant.Merchant +} + // Mailbox is the primary object of the Mailbox service type Mailbox struct { @@ -353,9 +371,23 @@ func (m *Mailbox) deleteMessagesResponse(w http.ResponseWriter, r *http.Request) w.WriteHeader(http.StatusNoContent) } +func (m *Mailbox) getFileName(relativeFileName string) string { + _, err := os.Stat(relativeFileName) + if errors.Is(err, os.ErrNotExist) { + _, err := os.Stat(m.Cfg.Datahome + "/" + relativeFileName) + if errors.Is(err, os.ErrNotExist) { + log.Printf("Tried fallback not found %s\n", m.Cfg.Datahome+"/"+relativeFileName) + return "" + } + return m.Cfg.Datahome + "/" + relativeFileName + } + return relativeFileName +} + func (m *Mailbox) termsResponse(w http.ResponseWriter, r *http.Request) { s := m.Cfg.Ini.Section("mailbox") - tos.ServiceTermsResponse(w, r, s.Key("default_terms_path").MustString("terms/"), tos.TalerTosConfig{ + termspath := m.getFileName(s.Key("default_terms_path").MustString("terms/")) + tos.ServiceTermsResponse(w, r, termspath, tos.TalerTosConfig{ DefaultFileType: s.Key("default_doc_filetype").MustString("text/html"), DefaultLanguage: s.Key("default_doc_lang").MustString("en"), SupportedFileTypes: strings.Split(s.Key("supported_doc_filetypes").String(), " "), @@ -364,7 +396,8 @@ func (m *Mailbox) termsResponse(w http.ResponseWriter, r *http.Request) { func (m *Mailbox) privacyResponse(w http.ResponseWriter, r *http.Request) { s := m.Cfg.Ini.Section("mailbox") - tos.PrivacyPolicyResponse(w, r, s.Key("default_pp_path").MustString("privacy/"), tos.TalerTosConfig{ + pppath := m.getFileName(s.Key("default_pp_path").MustString("privacy/")) + tos.PrivacyPolicyResponse(w, r, pppath, tos.TalerTosConfig{ DefaultFileType: s.Key("default_doc_filetype").MustString("text/html"), DefaultLanguage: s.Key("default_doc_lang").MustString("en"), SupportedFileTypes: strings.Split(s.Key("supported_doc_filetypes").String(), " "), @@ -387,23 +420,6 @@ func (m *Mailbox) setupHandlers() { m.Router.HandleFunc("/{mailbox}", m.deleteMessagesResponse).Methods("DELETE") } -type MailboxConfig struct { - // Version - Version string - - // Data home - Datahome string - - // Configuration - Ini *ini.File - - // DB connection - Db gorm.Dialector - - // Merchant connection - Merchant merchant.Merchant -} - // Initialize the Mailbox instance with cfgfile func (m *Mailbox) Initialize(cfg MailboxConfig) { m.Cfg = cfg