Use SiteURL to build image path (#17)

master
Ben Schumacher 2020-05-19 18:28:37 +02:00 committed by GitHub
parent 10827e90c3
commit 64160b0f46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 9 deletions

View File

@ -116,15 +116,12 @@ func (p *Plugin) OnActivate() error {
}
func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Mattermost-User-Id") == "" {
http.Error(w, "please log in", http.StatusForbidden)
return
}
p.router.ServeHTTP(w, r)
}
func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
siteURL := *p.API.GetConfig().ServiceSettings.SiteURL
input := strings.TrimSpace(strings.TrimPrefix(args.Command, "/meme"))
if input == "" || input == "help" {
@ -147,7 +144,7 @@ If your meme doesn't have well-defined phrasing or you want more control, you ca
In either case...
![brace-yourself](/plugins/memes/templates/brace-yourselves.jpg?text=brace+yourself.&text=memes+are+coming.)
![brace-yourself](` + siteURL + `/plugins/memes/templates/brace-yourselves.jpg?text=brace+yourself.&text=memes+are+coming.)
Available memes: ` + strings.Join(availableMemes, ", "),
}, nil
@ -168,10 +165,11 @@ Available memes: ` + strings.Join(availableMemes, ", "),
queryString += "text=" + url.QueryEscape(t)
}
return &model.CommandResponse{
resp := &model.CommandResponse{
ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL,
Text: "![" + template.Name + "](/plugins/memes/templates/" + template.Name + ".jpg" + queryString + ")",
}, nil
Text: "![" + template.Name + "](" + siteURL + "/plugins/memes/templates/" + template.Name + ".jpg" + queryString + ")",
}
return resp, nil
}
func main() {