From d722f5cd5c0b2c2ace33e5efc96c0c436449ed8d Mon Sep 17 00:00:00 2001 From: Haruki Date: Fri, 25 Aug 2023 09:28:49 +0900 Subject: [PATCH] =?UTF-8?q?SettingsDirectory=E5=86=85=E3=81=AB=E3=83=95?= =?UTF-8?q?=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nostrh/cmd/keystore/keystore.go | 15 ++++++++++++++- nostrh/cmd/relays/relays.go | 11 ++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/nostrh/cmd/keystore/keystore.go b/nostrh/cmd/keystore/keystore.go index 4c6ff9d..7f7f79d 100644 --- a/nostrh/cmd/keystore/keystore.go +++ b/nostrh/cmd/keystore/keystore.go @@ -4,9 +4,11 @@ import ( "errors" "fmt" "os" + "path/filepath" "github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr/nip19" + "github.com/studiokaiji/nostr-webhost/nostrh/cmd/paths" ) const PATH = ".nostr_account_secret" @@ -20,8 +22,19 @@ func SetSecret(key string) error { } key = v.(string) } + + dir, err := paths.GetSettingsDirectory() + if err != nil { + return err + } + + filePath := filepath.Join(dir, PATH) + if err != nil { + return err + } + // キーをファイルに書き込み - return os.WriteFile(PATH, []byte(key), 0644) + return os.WriteFile(filePath, []byte(key), 0644) } func ShowPublic() (string, string, error) { diff --git a/nostrh/cmd/relays/relays.go b/nostrh/cmd/relays/relays.go index 471042c..66df0d3 100644 --- a/nostrh/cmd/relays/relays.go +++ b/nostrh/cmd/relays/relays.go @@ -2,13 +2,22 @@ package relays import ( "os" + "path/filepath" "strings" + + "github.com/studiokaiji/nostr-webhost/nostrh/cmd/paths" ) const PATH = ".nostr_relays" func AddRelay(relayURL string) error { - file, err := os.OpenFile(PATH, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644) + dir, err := paths.GetSettingsDirectory() + if err != nil { + return err + } + + filePath := filepath.Join(dir, PATH) + file, err := os.OpenFile(filePath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644) if err != nil { return err }