mirror of
https://github.com/get-drexa/drive.git
synced 2025-12-02 06:21:40 +00:00
wip: vfs implementation
This commit is contained in:
38
apps/backend/internal/virtualfs/key_resolver.go
Normal file
38
apps/backend/internal/virtualfs/key_resolver.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package virtualfs
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/get-drexa/drexa/internal/blob"
|
||||
"github.com/google/uuid"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type BlobKeyResolver interface {
|
||||
Resolve(ctx context.Context, node *Node) (blob.Key, error)
|
||||
}
|
||||
|
||||
type FlatKeyResolver struct{}
|
||||
|
||||
func (r *FlatKeyResolver) Resolve(ctx context.Context, node *Node) (blob.Key, error) {
|
||||
if node.BlobKey == "" {
|
||||
id, err := uuid.NewV7()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return blob.Key(id.String()), nil
|
||||
}
|
||||
return node.BlobKey, nil
|
||||
}
|
||||
|
||||
type HierarchicalKeyResolver struct {
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
func (r *HierarchicalKeyResolver) Resolve(ctx context.Context, node *Node) (blob.Key, error) {
|
||||
path, err := buildNodeAbsolutePath(ctx, r.db, node.ID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return blob.Key(path), nil
|
||||
}
|
||||
Reference in New Issue
Block a user