seawolf2357 commited on
Commit
f8b8ae4
·
verified ·
1 Parent(s): c3b008e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -3
app.py CHANGED
@@ -1,7 +1,38 @@
1
- from flask import Flask, render_template, request, redirect, url_for, jsonify, session
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import requests
3
  import os
4
  from datetime import timedelta
 
5
 
6
  app = Flask(__name__)
7
  app.secret_key = os.urandom(24) # Session encryption key
@@ -599,6 +630,9 @@ if __name__ == '__main__':
599
  urls.forEach(item => {
600
  const { url, title } = item;
601
 
 
 
 
602
  // Create grid item
603
  const gridItem = document.createElement('div');
604
  gridItem.className = 'grid-item';
@@ -625,9 +659,9 @@ if __name__ == '__main__':
625
  const content = document.createElement('div');
626
  content.className = 'grid-content';
627
 
628
- // Create iframe to display the actual content
629
  const iframe = document.createElement('iframe');
630
- iframe.src = url;
631
  iframe.title = title;
632
  iframe.sandbox = 'allow-same-origin allow-scripts allow-popups allow-forms';
633
  iframe.allow = 'accelerometer; camera; encrypted-media; geolocation; gyroscope; microphone; midi';
 
1
+ # Proxy route to bypass X-Frame-Options
2
+ @app.route('/proxy/<path:url>')
3
+ def proxy(url):
4
+ # Authorization header if user is logged in
5
+ headers = {}
6
+ if 'token' in session:
7
+ headers["Authorization"] = f"Bearer {session['token']}"
8
+
9
+ try:
10
+ # Parse URL to ensure it's safe
11
+ parsed_url = urlparse(url)
12
+ if not parsed_url.netloc.endswith('huggingface.co'):
13
+ return "Only Huggingface URLs are allowed", 403
14
+
15
+ # Make request to the target URL
16
+ response = requests.get(url, headers=headers, stream=True)
17
+
18
+ # Create response
19
+ resp = Response(
20
+ response.iter_content(chunk_size=10*1024),
21
+ content_type=response.headers.get('Content-Type')
22
+ )
23
+
24
+ # Remove headers that prevent iframe embedding
25
+ resp.headers.remove('X-Frame-Options')
26
+ resp.headers.remove('Content-Security-Policy')
27
+
28
+ return resp
29
+ except Exception as e:
30
+ print(f"Proxy error: {e}")
31
+ return f"Error: {str(e)}", 500from flask import Flask, render_template, request, redirect, url_for, jsonify, session, Response
32
  import requests
33
  import os
34
  from datetime import timedelta
35
+ from urllib.parse import urlparse
36
 
37
  app = Flask(__name__)
38
  app.secret_key = os.urandom(24) # Session encryption key
 
630
  urls.forEach(item => {
631
  const { url, title } = item;
632
 
633
+ // Create proxy URL
634
+ const proxyUrl = `/proxy/${encodeURIComponent(url)}`;
635
+
636
  // Create grid item
637
  const gridItem = document.createElement('div');
638
  gridItem.className = 'grid-item';
 
659
  const content = document.createElement('div');
660
  content.className = 'grid-content';
661
 
662
+ // Create iframe to display the actual content via proxy
663
  const iframe = document.createElement('iframe');
664
+ iframe.src = proxyUrl;
665
  iframe.title = title;
666
  iframe.sandbox = 'allow-same-origin allow-scripts allow-popups allow-forms';
667
  iframe.allow = 'accelerometer; camera; encrypted-media; geolocation; gyroscope; microphone; midi';