mirror of
https://github.com/studiokaiji/nostr-webhost.git
synced 2025-12-19 07:44:25 +01:00
@@ -4,9 +4,11 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/nbd-wtf/go-nostr"
|
"github.com/nbd-wtf/go-nostr"
|
||||||
"github.com/nbd-wtf/go-nostr/nip19"
|
"github.com/nbd-wtf/go-nostr/nip19"
|
||||||
|
"github.com/studiokaiji/nostr-webhost/nostrh/cmd/paths"
|
||||||
)
|
)
|
||||||
|
|
||||||
const PATH = ".nostr_account_secret"
|
const PATH = ".nostr_account_secret"
|
||||||
@@ -20,8 +22,19 @@ func SetSecret(key string) error {
|
|||||||
}
|
}
|
||||||
key = v.(string)
|
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) {
|
func ShowPublic() (string, string, error) {
|
||||||
|
|||||||
28
nostrh/cmd/paths/paths.go
Normal file
28
nostrh/cmd/paths/paths.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -2,13 +2,22 @@ package relays
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/studiokaiji/nostr-webhost/nostrh/cmd/paths"
|
||||||
)
|
)
|
||||||
|
|
||||||
const PATH = ".nostr_relays"
|
const PATH = ".nostr_relays"
|
||||||
|
|
||||||
func AddRelay(relayURL string) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,7 +154,6 @@ func main() {
|
|||||||
|
|
||||||
fmt.Println(buf.String())
|
fmt.Println(buf.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start app
|
// Start app
|
||||||
|
|||||||
Reference in New Issue
Block a user