package ctrl import ( "fmt" "html" "net/http" "os" "path/filepath" "regexp" "strings" "text/template" . "github.com/mickael-kerjean/filestash/server/common" "github.com/mickael-kerjean/filestash/server/model" ) var listOfPlugins = struct { oss []string enterprise []string custom []string apps []string }{} func InitPluginList(code []byte, plgs map[string]model.PluginImpl) error { listOfPackages := regexp.MustCompile(`\t_?\s*\"(github.com/[^\"]+)`).FindAllStringSubmatch(string(code), -1) for _, packageNameMatch := range listOfPackages { if len(packageNameMatch) != 2 { Log.Error("ctrl::static error=assertion_failed msg=invalid_match_size arg=%d", len(packageNameMatch)) return ErrNotValid } packageName := packageNameMatch[1] packageShortName := filepath.Base(packageName) if strings.HasPrefix(packageName, "github.com/mickael-kerjean/filestash/server/plugin/") { listOfPlugins.oss = append(listOfPlugins.oss, packageShortName) } else if strings.HasPrefix(packageName, "github.com/mickael-kerjean/filestash/filestash-enterprise/plugins/") { listOfPlugins.enterprise = append(listOfPlugins.enterprise, packageShortName) } else if strings.HasPrefix(packageName, "github.com/mickael-kerjean/filestash/filestash-enterprise/customers/") { listOfPlugins.custom = append(listOfPlugins.custom, packageShortName) } else { listOfPlugins.custom = append(listOfPlugins.custom, packageShortName) } } for name, _ := range plgs { listOfPlugins.apps = append(listOfPlugins.apps, name) } return nil } func AboutHandler(ctx *App, res http.ResponseWriter, req *http.Request) { t, _ := template. New("about"). Funcs(map[string]interface{}{ "renderPlugin": func(lstr string, commit string) string { if len(lstr) == 0 { return "N/A" } else if commit == "" { return html.EscapeString(lstr) } list := strings.Split(lstr, " ") for i, _ := range list { list[i] = `` + html.EscapeString(list[i]) + `` } return strings.Join(list, " ") }, }). Parse(Page(`
| Commit hash | {{ .CommitHash }} |
| Binary hash | {{ index .Checksum 0}} |
| Config hash | {{ index .Checksum 1}} |
| License | {{ .License }} |
| Plugins |
STANDARD [{{ renderPlugin (index .Plugins 0) .CommitHash }}]
APPS [{{ renderPlugin (index .Plugins 3) "" }}] ENTERPRISE [{{ renderPlugin (index .Plugins 1) "" }}] CUSTOM [{{ renderPlugin (index .Plugins 2) "" }}] |