fix images not working on annotations
This commit is contained in:
parent
833a6afd15
commit
903d4ca99b
@ -20,19 +20,11 @@ func Annotations(l *logrus.Logger) http.HandlerFunc {
|
|||||||
id := mux.Vars(r)["id"]
|
id := mux.Vars(r)["id"]
|
||||||
|
|
||||||
if data, err := getCache[data.Annotation](id); err == nil {
|
if data, err := getCache[data.Annotation](id); err == nil {
|
||||||
|
encoder := json.NewEncoder(w)
|
||||||
|
|
||||||
response, err := json.Marshal(data)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
l.Errorf("could not marshal json: %s\n", err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
views.ErrorPage(500, "something went wrong").Render(context.Background(), w)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
w.Header().Set("content-type", "application/json")
|
w.Header().Set("content-type", "application/json")
|
||||||
_, err = w.Write(response)
|
if err = encoder.Encode(&data); err != nil {
|
||||||
if err != nil {
|
l.Errorln(err)
|
||||||
l.Errorln("Error sending response: ", err)
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -96,7 +88,8 @@ func Annotations(l *logrus.Logger) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cleanBody(body string) string {
|
func cleanBody(body string) string {
|
||||||
var withCleanedImageLinks = strings.Replace(body, "https://images.rapgenius.com/", "/images/", -1)
|
var withCleanedImageLinks = strings.ReplaceAll(body, "https://images.rapgenius.com/", "/images/")
|
||||||
|
withCleanedImageLinks = strings.ReplaceAll(body, "https://images.genius.com/", "/images/")
|
||||||
|
|
||||||
var re = regexp.MustCompile(`https?:\/\/[a-z]*.?genius.com`)
|
var re = regexp.MustCompile(`https?:\/\/[a-z]*.?genius.com`)
|
||||||
var withCleanedLinks = re.ReplaceAllString(withCleanedImageLinks, "")
|
var withCleanedLinks = re.ReplaceAllString(withCleanedImageLinks, "")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user