Skip to content
Closed
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
3 changes: 2 additions & 1 deletion cmd/agentbbs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import (
"github.com/profullstack/agentbbs/internal/store"
"github.com/profullstack/agentbbs/internal/tor"
"github.com/profullstack/agentbbs/plugins/about"
"github.com/profullstack/agentbbs/plugins/files"
"github.com/profullstack/agentbbs/plugins/agentgames"
"github.com/profullstack/agentbbs/plugins/arcade"
qryptinviteplugin "github.com/profullstack/agentbbs/plugins/qryptinvite"
Expand Down Expand Up @@ -171,7 +172,7 @@ func main() {
a.mm = games.NewMatchmaker(a.gamesReg, a.st,
time.Duration(envInt("AGENTBBS_GAME_MOVE_TIMEOUT", 15))*time.Second,
time.Duration(envInt("AGENTBBS_GAME_QUEUE_WAIT", 120))*time.Second)
a.registry = []plugin.Plugin{arcade.Plugin{}, agentgames.New(a.gamesReg), qryptinviteplugin.Plugin{}, about.Plugin{}}
a.registry = []plugin.Plugin{arcade.Plugin{}, agentgames.New(a.gamesReg), qryptinviteplugin.Plugin{}, about.Plugin{}, files.Plugin{}}

// Custom domains: maintain the symlink farm Caddy serves and answer its
// on-demand-TLS "ask" query so certs are only issued for mapped domains.
Expand Down
100 changes: 100 additions & 0 deletions plugins/files/files.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package files

import (
"fmt"
"os"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"

"github.com/profullstack/agentbbs/internal/auth"
"github.com/profullstack/agentbbs/internal/plugin"
)

type Plugin struct{}

func (Plugin) ID() string { return "files" }
func (Plugin) Title() string { return "Files" }
func (Plugin) Description() string { return "Browse your personal pod files" }
func (Plugin) RequiresAuth() bool { return true }

func (Plugin) New(user auth.User, ctx plugin.Context) tea.Model {
return model{user: user, dataDir: ctx.DataDir}
}

type model struct {
user auth.User
dataDir string
files []os.DirEntry
cursor int
err error
}

func (m model) Init() tea.Cmd {
return func() tea.Msg {
if m.dataDir == "" {
return fmt.Errorf("no data directory configured")
}
files, err := os.ReadDir(m.dataDir)
if err != nil {
return err
}
return files
}
}

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case error:
m.err = msg
return m, nil
case []os.DirEntry:
m.files = msg
return m, nil
case tea.KeyMsg:
switch msg.String() {
case "up", "k":
if m.cursor > 0 {
m.cursor--
}
case "down", "j":
if m.cursor < len(m.files)-1 {
m.cursor++
}
case "q", "esc", "ctrl+c":
return m, plugin.Exit
}
}
return m, nil
}

var (
titleStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("#4ade80"))
itemStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("252"))
selStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("#4ade80"))
)

func (m model) View() string {
if m.err != nil {
return fmt.Sprintf("Error reading files: %v\n\npress any key to return", m.err)
}
s := titleStyle.Render("Files in your pod workspace:") + "\n\n"
if len(m.files) == 0 {
s += " (no files found)\n"
}
for i, file := range m.files {
cur := " "
style := itemStyle
if i == m.cursor {
cur = "❯ "
style = selStyle
}
icon := "📄 "
if file.IsDir() {
icon = "📁 "
}
s += fmt.Sprintf("%s%s%s\n", cur, icon, style.Render(file.Name()))
}
s += "\n" + lipgloss.NewStyle().Foreground(lipgloss.Color("241")).Render("↑/↓ move · q back")
return lipgloss.NewStyle().Padding(1, 2).Render(s)
}
Loading