| 875 | } |
| 876 | |
| 877 | func UpdateTaskPluginMarketplaceSources(c *gin.Context) { |
| 878 | var sources []setting.TaskPluginMarketplaceSource |
| 879 | if err := c.ShouldBindJSON(&sources); err != nil { |
| 880 | common.ApiErrorMsg(c, err.Error()) |
| 881 | return |
| 882 | } |
| 883 | if sources == nil { |
| 884 | sources = []setting.TaskPluginMarketplaceSource{} |
| 885 | } |
| 886 | for i := range sources { |
| 887 | name := strings.TrimSpace(sources[i].Name) |
| 888 | indexURL := strings.TrimSpace(sources[i].IndexURL) |
| 889 | if name == "" { |
| 890 | common.ApiErrorMsg(c, "marketplace source name is required") |
| 891 | return |
| 892 | } |
| 893 | parsed, err := url.Parse(indexURL) |
| 894 | if err != nil || !parsed.IsAbs() || parsed.Host == "" || (!strings.EqualFold(parsed.Scheme, "http") && !strings.EqualFold(parsed.Scheme, "https")) { |
| 895 | common.ApiErrorMsg(c, "marketplace source index_url must be an absolute http(s) URL") |
| 896 | return |
| 897 | } |
| 898 | sources[i].Name = name |
| 899 | sources[i].IndexURL = indexURL |
| 900 | } |
| 901 | encoded, err := common.Marshal(sources) |
| 902 | if err != nil { |
| 903 | common.ApiError(c, err) |
| 904 | return |
| 905 | } |
| 906 | if err = model.UpdateOption(setting.TaskPluginMarketplaceSourcesKey, string(encoded)); err != nil { |
| 907 | common.ApiError(c, err) |
| 908 | return |
| 909 | } |
| 910 | common.ApiSuccess(c, sources) |
| 911 | } |
| 912 | |
| 913 | // relayPaths lists the incoming paths of a plugin's relay routes, each once. |
| 914 | func relayPaths(meta jsplugin.Meta) []string { |