mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
- Add (project) labels to status, sync, collect, target, and uninstall headers for clear mode distinction (matching list/target list pattern) - Add ui.WithModeLabel() helper for shared functions that run in both modes - Update uninstall confirmation prompt: "from the project?" in project mode - Add "Privacy-first" to README Why section and website homepage - Replace "Unified Source" card with "Privacy-First" card on website - Unify Quick Actions card heights with h-full in DashboardPage - Add frontend rebuild note to Docker sandbox docs
98 lines
2.4 KiB
Go
98 lines
2.4 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"path/filepath"
|
|
|
|
"skillshare/internal/git"
|
|
"skillshare/internal/install"
|
|
)
|
|
|
|
type repoCheckResult struct {
|
|
Name string `json:"name"`
|
|
Status string `json:"status"`
|
|
Behind int `json:"behind"`
|
|
Message string `json:"message,omitempty"`
|
|
}
|
|
|
|
type skillCheckResult struct {
|
|
Name string `json:"name"`
|
|
Source string `json:"source"`
|
|
Version string `json:"version"`
|
|
Status string `json:"status"`
|
|
InstalledAt string `json:"installed_at,omitempty"`
|
|
}
|
|
|
|
func (s *Server) handleCheck(w http.ResponseWriter, r *http.Request) {
|
|
sourceDir := s.cfg.Source
|
|
if s.IsProjectMode() {
|
|
sourceDir = filepath.Join(s.projectRoot, ".skillshare", "skills")
|
|
}
|
|
|
|
repos, _ := install.GetTrackedRepos(sourceDir)
|
|
skills, _ := install.GetUpdatableSkills(sourceDir)
|
|
|
|
var repoResults []repoCheckResult
|
|
for _, repo := range repos {
|
|
repoPath := filepath.Join(sourceDir, repo)
|
|
result := repoCheckResult{Name: repo}
|
|
|
|
if isDirty, _ := git.IsDirty(repoPath); isDirty {
|
|
result.Status = "dirty"
|
|
result.Message = "has uncommitted changes"
|
|
} else if behind, err := git.GetBehindCount(repoPath); err != nil {
|
|
result.Status = "error"
|
|
result.Message = err.Error()
|
|
} else if behind == 0 {
|
|
result.Status = "up_to_date"
|
|
} else {
|
|
result.Status = "behind"
|
|
result.Behind = behind
|
|
}
|
|
|
|
repoResults = append(repoResults, result)
|
|
}
|
|
|
|
var skillResults []skillCheckResult
|
|
for _, skill := range skills {
|
|
skillPath := filepath.Join(sourceDir, skill)
|
|
result := skillCheckResult{Name: skill}
|
|
|
|
meta, err := install.ReadMeta(skillPath)
|
|
if err != nil || meta == nil || meta.RepoURL == "" {
|
|
result.Status = "local"
|
|
skillResults = append(skillResults, result)
|
|
continue
|
|
}
|
|
|
|
result.Source = meta.Source
|
|
result.Version = meta.Version
|
|
if !meta.InstalledAt.IsZero() {
|
|
result.InstalledAt = meta.InstalledAt.Format("2006-01-02")
|
|
}
|
|
|
|
remoteHash, err := git.GetRemoteHeadHash(meta.RepoURL)
|
|
if err != nil {
|
|
result.Status = "error"
|
|
} else if meta.Version == remoteHash {
|
|
result.Status = "up_to_date"
|
|
} else {
|
|
result.Status = "update_available"
|
|
}
|
|
|
|
skillResults = append(skillResults, result)
|
|
}
|
|
|
|
if repoResults == nil {
|
|
repoResults = []repoCheckResult{}
|
|
}
|
|
if skillResults == nil {
|
|
skillResults = []skillCheckResult{}
|
|
}
|
|
|
|
writeJSON(w, map[string]any{
|
|
"tracked_repos": repoResults,
|
|
"skills": skillResults,
|
|
})
|
|
}
|