Skip to content

Commit

Permalink
Merge pull request #4 from FlamesX-128/develop
Browse files Browse the repository at this point in the history
problem getting recent versions of plugins fixed.
  • Loading branch information
FlamesX-128 authored Nov 13, 2022
2 parents 61dda7b + 20083f2 commit 7c8e85b
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions controllers/plugins/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,50 @@ package plugins
import (
"encoding/json"
"io"
"log"
"net/http"
"strings"

"github.com/FlamesX-128/anigo/models/plugins"
"github.com/hashicorp/go-version"
)

func FilterValidPlugins(ss []plugins.Response) map[string]plugins.Response {
var data = map[string]plugins.Response{}

for _, plugin := range ss {
params := strings.Split(plugin.Name, "-")
name := params[0]
info := strings.Split(params[0], "@")
skip := false

if len(params) != 4 || params[1] != PluginModelVersion {

continue
}

if _, ok := data[name]; !ok {
data[name] = plugin
for name := range data {
if !strings.HasPrefix(name, info[0]) {

continue
}

v1, err := version.NewVersion(strings.Split(name, "@")[1])
v2, err2 := version.NewVersion(info[1])

if err != nil || err2 != nil {
log.Panicln(err, err2)
}

if v1.GreaterThan(v2) {
skip = true
} else {
delete(data, name)
}

}

if !skip {
data[params[0]] = plugin
}

}
Expand Down

0 comments on commit 7c8e85b

Please sign in to comment.