mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
Single-binary web UI for visual skill management — React 19 + Vite frontend embedded via go:embed, Go net/http REST API backend (30+ endpoints). Includes dashboard, skills browser, targets, sync, collect, search, install, config editor, backup/restore, and git sync pages. Also adds Bitbucket/GitLab URL parsing for install, git operations library, skill version checking, CI frontend build steps, Docker sandbox support, and website docs for the ui command.
87 lines
1.9 KiB
Go
87 lines
1.9 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"skillshare/internal/git"
|
|
"skillshare/internal/install"
|
|
"skillshare/internal/sync"
|
|
"skillshare/internal/utils"
|
|
versioncheck "skillshare/internal/version"
|
|
)
|
|
|
|
type trackedRepoItem struct {
|
|
Name string `json:"name"`
|
|
SkillCount int `json:"skillCount"`
|
|
Dirty bool `json:"dirty"`
|
|
}
|
|
|
|
func (s *Server) handleOverview(w http.ResponseWriter, r *http.Request) {
|
|
// Count skills
|
|
skills, err := sync.DiscoverSourceSkills(s.cfg.Source)
|
|
if err != nil {
|
|
writeError(w, http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
|
|
// Count top-level source entries (for display)
|
|
topLevelCount := 0
|
|
entries, _ := os.ReadDir(s.cfg.Source)
|
|
for _, e := range entries {
|
|
if e.IsDir() && !utils.IsHidden(e.Name()) {
|
|
topLevelCount++
|
|
}
|
|
}
|
|
|
|
mode := s.cfg.Mode
|
|
if mode == "" {
|
|
mode = "merge"
|
|
}
|
|
|
|
// Tracked repos
|
|
trackedRepos := buildTrackedRepos(s.cfg.Source, skills)
|
|
|
|
writeJSON(w, map[string]any{
|
|
"source": s.cfg.Source,
|
|
"skillCount": len(skills),
|
|
"topLevelCount": topLevelCount,
|
|
"targetCount": len(s.cfg.Targets),
|
|
"mode": mode,
|
|
"version": versioncheck.Version,
|
|
"trackedRepos": trackedRepos,
|
|
})
|
|
}
|
|
|
|
func buildTrackedRepos(sourceDir string, skills []sync.DiscoveredSkill) []trackedRepoItem {
|
|
repoNames, err := install.GetTrackedRepos(sourceDir)
|
|
if err != nil || len(repoNames) == 0 {
|
|
return []trackedRepoItem{}
|
|
}
|
|
|
|
items := make([]trackedRepoItem, 0, len(repoNames))
|
|
for _, repoName := range repoNames {
|
|
repoPath := filepath.Join(sourceDir, repoName)
|
|
|
|
// Count skills belonging to this repo
|
|
skillCount := 0
|
|
for _, sk := range skills {
|
|
if sk.IsInRepo && strings.HasPrefix(sk.RelPath, repoName+"/") {
|
|
skillCount++
|
|
}
|
|
}
|
|
|
|
// Check git dirty status
|
|
dirty, _ := git.IsDirty(repoPath)
|
|
|
|
items = append(items, trackedRepoItem{
|
|
Name: repoName,
|
|
SkillCount: skillCount,
|
|
Dirty: dirty,
|
|
})
|
|
}
|
|
return items
|
|
}
|