fs: something that makes more sense.

This commit is contained in:
fiatjaf
2025-03-08 12:52:05 -03:00
parent d6a23bd00c
commit 3d961d4bec
8 changed files with 208 additions and 151 deletions

46
nostrfs/npubdir.go Normal file
View File

@@ -0,0 +1,46 @@
package nostrfs
import (
"context"
"sync/atomic"
"syscall"
"github.com/hanwen/go-fuse/v2/fs"
"github.com/nbd-wtf/go-nostr"
sdk "github.com/nbd-wtf/go-nostr/sdk"
)
type NpubDir struct {
sys *sdk.System
fs.Inode
pointer nostr.ProfilePointer
ctx context.Context
fetched atomic.Bool
}
func CreateNpubDir(ctx context.Context, parent fs.InodeEmbedder, pointer nostr.ProfilePointer) *fs.Inode {
npubdir := &NpubDir{pointer: pointer}
return parent.EmbeddedInode().NewPersistentInode(
ctx,
npubdir,
fs.StableAttr{Mode: syscall.S_IFDIR},
)
}
var _ = (fs.NodeOpendirer)((*NpubDir)(nil))
func (n *NpubDir) Opendir(ctx context.Context) syscall.Errno {
if n.fetched.CompareAndSwap(true, true) {
return fs.OK
}
for ie := range n.sys.Pool.FetchMany(ctx, n.sys.FetchOutboxRelays(ctx, n.pointer.PublicKey, 2), nostr.Filter{
Kinds: []int{1},
Authors: []string{n.pointer.PublicKey},
}, nostr.WithLabel("nak-fs-feed")) {
e := CreateEventDir(ctx, n, ie.Event)
n.AddChild(ie.Event.ID, e, true)
}
return fs.OK
}