Skip to content

Commit

Permalink
Merge pull request #21 from studiokaiji/feature-#14
Browse files Browse the repository at this point in the history
Feature #14
  • Loading branch information
studiokaiji authored Aug 25, 2023
2 parents b620346 + b456626 commit 67b1301
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
15 changes: 14 additions & 1 deletion nostrh/cmd/keystore/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down
28 changes: 28 additions & 0 deletions nostrh/cmd/paths/paths.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package paths

import (
"os"
"path/filepath"
)

const BaseDirName = ".nostr-webhost"

func GetSettingsDirectory() (string, error) {
homeDir, err := os.UserHomeDir()
if err != nil {
return "", err
}

dirPath := filepath.Join(homeDir, BaseDirName)
if os.IsNotExist(err) {
// ディレクトリが存在しない場合に作成
err = os.Mkdir(dirPath, 0700)
if err != nil {
return "", err
}
} else if err != nil {
return "", err
}

return dirPath, nil
}
11 changes: 10 additions & 1 deletion nostrh/cmd/relays/relays.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion nostrh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ func main() {

fmt.Println(buf.String())
}

}

// Start app
Expand Down

0 comments on commit 67b1301

Please sign in to comment.