mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-06-24 03:55:23 -04:00
plugins: enhance browser and CLI with new votes and labels
This commit is contained in:
@@ -280,6 +280,8 @@ func browsePlugins() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
feedback := plugins.FetchFeedback()
|
||||
|
||||
fmt.Printf("\nAvailable Plugins (%d):\n\n", len(pluginList))
|
||||
for _, plugin := range pluginList {
|
||||
installed, _ := manager.IsInstalled(plugin)
|
||||
@@ -303,6 +305,15 @@ func browsePlugins() error {
|
||||
if len(plugin.Dependencies) > 0 {
|
||||
fmt.Printf(" Dependencies: %s\n", strings.Join(plugin.Dependencies, ", "))
|
||||
}
|
||||
if fb, ok := feedback[plugin.ID]; ok {
|
||||
fmt.Printf(" Upvotes: %d\n", fb.Upvotes)
|
||||
if len(fb.Status) > 0 {
|
||||
fmt.Printf(" Status: %s\n", strings.Join(fb.Status, ", "))
|
||||
}
|
||||
if fb.IssueURL != "" {
|
||||
fmt.Printf(" Discuss: %s\n", fb.IssueURL)
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
const feedbackURL = "https://api.danklinux.com/plugins"
|
||||
|
||||
type Feedback struct {
|
||||
Upvotes int
|
||||
Status []string
|
||||
IssueURL string
|
||||
}
|
||||
|
||||
// FetchFeedback retrieves community upvotes and moderator status from the directory API.
|
||||
// Best-effort: any failure returns a nil map.
|
||||
func FetchFeedback() map[string]Feedback {
|
||||
client := &http.Client{Timeout: 5 * time.Second}
|
||||
|
||||
resp, err := client.Get(feedbackURL)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil
|
||||
}
|
||||
|
||||
var payload struct {
|
||||
Plugins []struct {
|
||||
ID string `json:"id"`
|
||||
Upvotes int `json:"upvotes"`
|
||||
Status []string `json:"status"`
|
||||
IssueURL string `json:"issueUrl"`
|
||||
} `json:"plugins"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&payload); err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
feedback := make(map[string]Feedback, len(payload.Plugins))
|
||||
for _, p := range payload.Plugins {
|
||||
feedback[p.ID] = Feedback{Upvotes: p.Upvotes, Status: p.Status, IssueURL: p.IssueURL}
|
||||
}
|
||||
return feedback
|
||||
}
|
||||
@@ -28,9 +28,12 @@ func HandleList(conn net.Conn, req models.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
feedback := plugins.FetchFeedback()
|
||||
|
||||
result := make([]PluginInfo, len(pluginList))
|
||||
for i, p := range pluginList {
|
||||
installed, _ := manager.IsInstalled(p)
|
||||
fb := feedback[p.ID]
|
||||
result[i] = PluginInfo{
|
||||
ID: p.ID,
|
||||
Name: p.Name,
|
||||
@@ -46,6 +49,9 @@ func HandleList(conn net.Conn, req models.Request) {
|
||||
FirstParty: strings.HasPrefix(p.Repo, "https://github.com/AvengeMedia"),
|
||||
Featured: p.Featured,
|
||||
RequiresDMS: p.RequiresDMS,
|
||||
Upvotes: fb.Upvotes,
|
||||
Status: fb.Status,
|
||||
IssueURL: fb.IssueURL,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@ type PluginInfo struct {
|
||||
Note string `json:"note,omitempty"`
|
||||
HasUpdate bool `json:"hasUpdate,omitempty"`
|
||||
RequiresDMS string `json:"requires_dms,omitempty"`
|
||||
Upvotes int `json:"upvotes,omitempty"`
|
||||
Status []string `json:"status,omitempty"`
|
||||
IssueURL string `json:"issueUrl,omitempty"`
|
||||
}
|
||||
|
||||
type SuccessResult struct {
|
||||
|
||||
Reference in New Issue
Block a user