mirror of
https://github.com/fiatjaf/nak.git
synced 2025-12-09 17:18:50 +00:00
fs: something that makes more sense.
This commit is contained in:
46
nostrfs/npubdir.go
Normal file
46
nostrfs/npubdir.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user