Files
sonr/pkg/vault/embed/codec.go
T

49 lines
1.3 KiB
Go
Raw Normal View History

package embed
2024-12-05 20:36:58 -05:00
import (
"encoding/json"
"github.com/ipfs/boxo/files"
2024-12-18 15:53:45 -05:00
"github.com/onsonr/sonr/internal/config/motr"
2024-12-05 20:36:58 -05:00
)
const SchemaVersion = 1
const (
AppManifestFileName = "app.webmanifest"
DWNConfigFileName = "dwn.json"
IndexHTMLFileName = "index.html"
MainJSFileName = "main.js"
ServiceWorkerFileName = "sw.js"
)
// spawnVaultDirectory creates a new directory with the default files
2024-12-18 15:53:45 -05:00
func NewVaultFS(cfg *motr.Config) (files.Directory, error) {
manifestBz, err := NewWebManifest()
2024-12-05 20:36:58 -05:00
if err != nil {
return nil, err
}
cnfBz, err := json.Marshal(cfg)
if err != nil {
return nil, err
}
return files.NewMapDirectory(map[string]files.Node{
AppManifestFileName: files.NewBytesFile(manifestBz),
DWNConfigFileName: files.NewBytesFile(cnfBz),
IndexHTMLFileName: files.NewBytesFile(IndexHTML),
MainJSFileName: files.NewBytesFile(MainJS),
ServiceWorkerFileName: files.NewBytesFile(WorkerJS),
2024-12-05 20:36:58 -05:00
}), nil
}
// NewVaultConfig returns the default vault config
2024-12-18 15:53:45 -05:00
func NewVaultConfig(addr string, ucanCID string) *motr.Config {
return &motr.Config{
2024-12-05 20:36:58 -05:00
MotrToken: ucanCID,
MotrAddress: addr,
IpfsGatewayUrl: "http://localhost:80",
SonrApiUrl: "http://localhost:1317",
SonrRpcUrl: "http://localhost:26657",
SonrChainId: "sonr-testnet-1",
2024-12-16 15:29:54 -05:00
}
}