sonr/internal/dwn/embed.go
Prad Nukala d8cb2cbbf6
feature/1126 implement pkl config (#1161)
- **refactor: move marketing pages to**
- **feat: add role select input**
2024-11-06 13:32:51 -05:00

43 lines
947 B
Go

package dwn
import (
_ "embed"
"encoding/json"
"github.com/ipfs/boxo/files"
"github.com/onsonr/sonr/internal/dwn/gen"
"github.com/onsonr/sonr/pkg/nebula"
)
const (
FileNameAppWASM = "app.wasm"
FileNameConfigJSON = "dwn.json"
FileNameIndexHTML = "index.html"
FileNameWorkerJS = "sw.js"
)
//go:embed app.wasm
var dwnWasmData []byte
//go:embed sw.js
var swJSData []byte
// NewVaultDirectory creates a new directory with the default files
func NewVaultDirectory(cnfg *gen.Config) (files.Node, error) {
idxFile, err := nebula.BuildVaultFile(cnfg)
if err != nil {
return nil, err
}
cnfgBz, err := json.Marshal(cnfg)
if err != nil {
return nil, err
}
fileMap := map[string]files.Node{
FileNameAppWASM: files.NewBytesFile(dwnWasmData),
FileNameConfigJSON: files.NewBytesFile(cnfgBz),
FileNameIndexHTML: idxFile,
FileNameWorkerJS: files.NewBytesFile(swJSData),
}
return files.NewMapDirectory(fileMap), nil
}