2024-11-18 19:04:10 -05:00
|
|
|
package motr
|
2024-10-10 13:44:17 -04:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
_ "embed"
|
2024-10-15 14:31:19 -04:00
|
|
|
"encoding/json"
|
2024-10-10 13:44:17 -04:00
|
|
|
|
|
|
|
|
"github.com/ipfs/boxo/files"
|
2024-11-18 19:04:10 -05:00
|
|
|
|
|
|
|
|
"github.com/onsonr/sonr/pkg/motr/config"
|
|
|
|
|
"github.com/onsonr/sonr/pkg/motr/static"
|
2024-10-15 14:31:19 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
2024-11-18 19:04:10 -05:00
|
|
|
FileNameConfigJSON = "dwn.pkl"
|
2024-10-15 14:31:19 -04:00
|
|
|
FileNameIndexHTML = "index.html"
|
|
|
|
|
FileNameWorkerJS = "sw.js"
|
2024-10-10 13:44:17 -04:00
|
|
|
)
|
|
|
|
|
|
2024-11-18 19:04:10 -05:00
|
|
|
//go:embed static/sw.js
|
2024-10-10 13:44:17 -04:00
|
|
|
var swJSData []byte
|
|
|
|
|
|
|
|
|
|
// NewVaultDirectory creates a new directory with the default files
|
2024-11-18 19:04:10 -05:00
|
|
|
func NewVaultDirectory(cnfg *config.Config) (files.Node, error) {
|
|
|
|
|
idxFile, err := static.BuildVaultFile(cnfg)
|
2024-10-15 14:31:19 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
cnfgBz, err := json.Marshal(cnfg)
|
2024-10-10 13:44:17 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
fileMap := map[string]files.Node{
|
2024-10-15 14:31:19 -04:00
|
|
|
FileNameConfigJSON: files.NewBytesFile(cnfgBz),
|
|
|
|
|
FileNameIndexHTML: idxFile,
|
|
|
|
|
FileNameWorkerJS: files.NewBytesFile(swJSData),
|
2024-10-10 13:44:17 -04:00
|
|
|
}
|
|
|
|
|
return files.NewMapDirectory(fileMap), nil
|
|
|
|
|
}
|