From c78d2f1d22e49868870166ead4b115731e054b4f Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Wed, 7 Jul 2021 10:46:04 -0700 Subject: added media proxy for remote links --- client.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'client.go') diff --git a/client.go b/client.go index 39ecd29..5ac527e 100644 --- a/client.go +++ b/client.go @@ -174,6 +174,9 @@ func AllNewsGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { func OutboxGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection Collection){ t := template.Must(template.New("").Funcs(template.FuncMap{ + "proxy": func(url string) string { + return MediaProxy(url) + }, "sub": func (i, j int) int { return i - j }}).ParseFiles("./static/main.html", "./static/nposts.html", "./static/top.html", "./static/bottom.html", "./static/posts.html")) @@ -224,6 +227,9 @@ func OutboxGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection Co func CatalogGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection Collection){ t := template.Must(template.New("").Funcs(template.FuncMap{ + "proxy": func(url string) string { + return MediaProxy(url) + }, "sub": func (i, j int) int { return i - j }}).ParseFiles("./static/main.html", "./static/ncatalog.html", "./static/top.html")) actor := collection.Actor @@ -258,6 +264,9 @@ func CatalogGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection C func PostGet(w http.ResponseWriter, r *http.Request, db *sql.DB){ t := template.Must(template.New("").Funcs(template.FuncMap{ + "proxy": func(url string) string { + return MediaProxy(url) + }, "sub": func (i, j int) int { return i - j }}).ParseFiles("./static/main.html", "./static/npost.html", "./static/top.html", "./static/bottom.html", "./static/posts.html")) path := r.URL.Path @@ -567,3 +576,14 @@ type BoardSortAsc []Board func (a BoardSortAsc) Len() int { return len(a) } func (a BoardSortAsc) Less(i, j int) bool { return a[i].Name < a[j].Name } func (a BoardSortAsc) Swap(i, j int) { a[i], a[j] = a[j], a[i] } + +func MediaProxy(url string) string { + re := regexp.MustCompile("(.+)?" + Domain + "(.+)?") + + if re.MatchString(url) { + return url + } + + MediaHashs[HashMedia(url)] = url + return "/api/media?hash=" + HashMedia(url) +} -- cgit v1.2.3