From 9c77816ee74adbef8e95bf440943c4f893db8312 Mon Sep 17 00:00:00 2001 From: "Gustavo L de Mello (Guz)" Date: Tue, 14 Jan 2025 22:21:07 -0300 Subject: [PATCH] feat(blogo,gitea): update implementation with new blogo.File and blogo.FS --- blogo/gitea/fs.go | 49 +++++++++++++++++++++++++++++++++++++++++--- blogo/gitea/gitea.go | 3 +-- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/blogo/gitea/fs.go b/blogo/gitea/fs.go index 6fe38b3..c4c304f 100644 --- a/blogo/gitea/fs.go +++ b/blogo/gitea/fs.go @@ -27,9 +27,13 @@ import ( "slices" "syscall" "time" + + "forge.capytal.company/loreddev/x/blogo" ) type repositoryFS struct { + metadata map[string]any + owner string repo string ref string @@ -37,11 +41,32 @@ type repositoryFS struct { client *client } -func newRepositoryFS(owner, repo, ref string, client *client) *repositoryFS { - return &repositoryFS{owner: owner, repo: repo, ref: ref, client: client} +func newRepositoryFS(owner, repo, ref string, client *client) blogo.FS { + return &repositoryFS{ + owner: owner, + repo: repo, + ref: ref, + client: client, + } } -func (fsys *repositoryFS) Open(name string) (fs.File, error) { +func (fsys *repositoryFS) Metadata() blogo.Metadata { + // TODO: Properly implement metadata with contents from the API + if fsys.metadata == nil || (fsys.metadata != nil && len(fsys.metadata) == 0) { + m := map[string]any{} + m["gitea.owner"] = fsys.owner + m["gitea.repository"] = fsys.repo + + if fsys.ref != "" { + m["gitea.ref"] = fsys.ref + } + + fsys.metadata = m + } + return blogo.MetadataMap(fsys.metadata) +} + +func (fsys *repositoryFS) Open(name string) (blogo.File, error) { if !fs.ValidPath(name) { return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrInvalid} } @@ -145,6 +170,8 @@ func (fsys *repositoryFS) Open(name string) (fs.File, error) { type repositoryFile struct { contentsResponse + metadata map[string]any + owner string repo string ref string @@ -154,6 +181,22 @@ type repositoryFile struct { contents io.ReadCloser } +func (f *repositoryFile) Metadata() blogo.Metadata { + // TODO: Properly implement metadata with contents from the API + if f.metadata == nil || (f.metadata != nil && len(f.metadata) == 0) { + m := map[string]any{} + m["gitea.owner"] = f.owner + m["gitea.repository"] = f.repo + + if f.ref != "" { + m["gitea.ref"] = f.ref + } + + f.metadata = m + } + return blogo.MetadataMap(f.metadata) +} + func (f *repositoryFile) Stat() (fs.FileInfo, error) { return &repositoryFileInfo{*f}, nil } diff --git a/blogo/gitea/gitea.go b/blogo/gitea/gitea.go index 371fb52..12a4ee7 100644 --- a/blogo/gitea/gitea.go +++ b/blogo/gitea/gitea.go @@ -17,7 +17,6 @@ package gitea import ( "fmt" - "io/fs" "net/http" "net/url" "strings" @@ -83,6 +82,6 @@ func (p *plugin) Name() string { return pluginName } -func (p *plugin) Source() (fs.FS, error) { +func (p *plugin) Source() (blogo.FS, error) { return newRepositoryFS(p.owner, p.repo, p.ref, p.client), nil }