Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions pkg/filesystem/classic.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import (

const DirName string = ".git-calendar-data"

// easy as that you bozo
//
// Returns a FS starting from users home directory
// Returns a FS starting from users home directory.
func GetFS() (billy.Filesystem, error) {
// get user home dir
home, err := os.UserHomeDir()
Expand Down
31 changes: 4 additions & 27 deletions pkg/filesystem/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,13 @@
package filesystem

import (
"errors"
"fmt"
"syscall/js"

"github.com/git-calendar/core/pkg/opfs"
"github.com/git-calendar/core/pkg/idb"
"github.com/go-git/go-billy/v5"
)

const DirName = "git-calendar-data"
const DirName = "git-calendar-data" // the storeName for IndexedDB

// Returns a FS inside IndexedDB.
func GetFS() (billy.Filesystem, error) {
// gets the handle from js window.opfsRootHandle
rootHandle := js.Global().Get("opfsRootHandle")
if rootHandle.IsUndefined() {
return nil, errors.New("opfsRootHandle not initialized")
}

// create OPFS rooted at /
fs := opfs.New(rootHandle)

// ensure directory exists
if err := fs.MkdirAll(DirName, 0o755); err != nil {
return nil, fmt.Errorf("failed to create dir: %w", err)
}

// chroot into the directory
chrooted, err := fs.Chroot(DirName)
if err != nil {
return nil, fmt.Errorf("failed to chroot: %w", err)
}

return chrooted, nil
return idb.New(DirName, 1)
}
Loading