aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorFChannel <>2021-07-07 10:46:04 -0700
committerFChannel <>2021-07-07 10:46:04 -0700
commitc78d2f1d22e49868870166ead4b115731e054b4f (patch)
tree0a3e696fa278097b07331245279c3a73eb135aae /client.go
parente859b3bc4e7e9c5a77ec2283088a042eb7b1b6e1 (diff)
added media proxy for remote links
Diffstat (limited to 'client.go')
-rw-r--r--client.go20
1 files changed, 20 insertions, 0 deletions
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)
+}