Update app.py
Browse files
app.py
CHANGED
@@ -1,61 +1,45 @@
|
|
1 |
-
from flask import Flask, request,
|
2 |
-
import
|
3 |
|
4 |
app = Flask(__name__)
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
12 |
|
13 |
-
@app.route('/'
|
14 |
def home():
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
@app.route('/
|
19 |
-
def
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
@app.route('/files')
|
45 |
-
def list_files():
|
46 |
-
files = os.listdir(app.config['UPLOAD_FOLDER'])
|
47 |
-
return '''
|
48 |
-
<!doctype html>
|
49 |
-
<title>Uploaded files</title>
|
50 |
-
<h1>Uploaded files</h1>
|
51 |
-
<ul>
|
52 |
-
''' + ''.join(['<li><a href="/download/{}">{}</a></li>'.format(f, f) for f in files]) + '''
|
53 |
-
</ul>
|
54 |
-
'''
|
55 |
-
|
56 |
-
@app.route('/download/<filename>')
|
57 |
-
def download_file(filename):
|
58 |
-
return send_from_directory(app.config['UPLOAD_FOLDER'], filename, as_attachment=True)
|
59 |
-
|
60 |
-
if __name__ == '__main__':
|
61 |
-
app.run(host='0.0.0.0', port=7860, debug=True)
|
|
|
1 |
+
from flask import Flask, request, Response
|
2 |
+
import requests
|
3 |
|
4 |
app = Flask(__name__)
|
5 |
|
6 |
+
# HTML form template to allow user input
|
7 |
+
html_form = '''
|
8 |
+
<form action="/proxy" method="get">
|
9 |
+
<label for="url">Enter URL:</label>
|
10 |
+
<input type="text" id="url" name="url" placeholder="https://example.com" required>
|
11 |
+
<button type="submit">Browse</button>
|
12 |
+
</form>
|
13 |
+
'''
|
14 |
|
15 |
+
@app.route('/')
|
16 |
def home():
|
17 |
+
# Display the form for URL input
|
18 |
+
return html_form
|
19 |
+
|
20 |
+
@app.route('/proxy')
|
21 |
+
def proxy():
|
22 |
+
# Get the URL from the user's input
|
23 |
+
url = request.args.get('url')
|
24 |
+
if not url:
|
25 |
+
return "No URL provided", 400
|
26 |
+
|
27 |
+
# Validate URL (must start with http:// or https:// for security)
|
28 |
+
if not (url.startswith("http://") or url.startswith("https://")):
|
29 |
+
return "Invalid URL. Please include http:// or https://", 400
|
30 |
+
|
31 |
+
try:
|
32 |
+
# Fetch the content from the specified URL
|
33 |
+
response = requests.get(url)
|
34 |
+
response.raise_for_status() # Ensure the request was successful
|
35 |
+
|
36 |
+
# Return the fetched content as a response to the user
|
37 |
+
return Response(response.content, content_type=response.headers['Content-Type'])
|
38 |
+
|
39 |
+
except requests.RequestException as e:
|
40 |
+
# Handle errors in fetching the page
|
41 |
+
return f"Error fetching the page: {e}"
|
42 |
+
|
43 |
+
if __name__ == "__main__":
|
44 |
+
# Run the Flask app on port 7860
|
45 |
+
app.run(host="0.0.0.0", port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|