add media proxy for images

This commit is contained in:
Toaster 2023-01-08 01:42:26 -06:00
parent b8b094e90f
commit 53943fada7
2 changed files with 15 additions and 0 deletions

View File

@ -10,3 +10,4 @@ import morsel_login
import morsel_boards
import morsel_users
import morsel_avatar
import morsel_proxy

14
morsel_proxy.py Normal file
View File

@ -0,0 +1,14 @@
# Morsel Media Proxy
# Prevents users from doxxing themselves. Ain't that nice?
from main import app
from flask import redirect
from flask import Response
import requests
@app.route("/proxy/<path:url>")
def mediaproxy(url):
if url.startswith("static/") or url.startswith("avatar/"):
return redirect("/"+url, 303)
else:
proxied_media = requests.get(url, headers={"X-Proxied-By":"MorselMediaProxy"})
return Response(proxied_media.content, mimetype=proxied_media.headers["Content-Type"])