Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from flask import Flask, request, jsonify, send_from_directory,
|
| 2 |
import os
|
| 3 |
import time
|
| 4 |
import random
|
|
@@ -7,6 +7,8 @@ from werkzeug.utils import secure_filename
|
|
| 7 |
import requests
|
| 8 |
|
| 9 |
app = Flask(__name__)
|
|
|
|
|
|
|
| 10 |
PUBLIC_DIR = 'public'
|
| 11 |
UPLOAD_DIR = 'uploads'
|
| 12 |
os.makedirs(PUBLIC_DIR, exist_ok=True)
|
|
@@ -42,6 +44,12 @@ USER_AGENTS = [
|
|
| 42 |
def allowed_file(filename):
|
| 43 |
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
@app.route('/')
|
| 46 |
def index():
|
| 47 |
return jsonify({
|
|
@@ -102,15 +110,11 @@ def get_url():
|
|
| 102 |
continue
|
| 103 |
|
| 104 |
if html_only:
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
'X-User-Agent': user_agent,
|
| 111 |
-
'X-Attempts': str(len(failed_attempts) + 1)
|
| 112 |
-
}
|
| 113 |
-
)
|
| 114 |
|
| 115 |
return jsonify({
|
| 116 |
'success': True,
|
|
@@ -163,7 +167,9 @@ def fetch_with_ua(url, user_agent, html_only):
|
|
| 163 |
html = response.text
|
| 164 |
|
| 165 |
if html_only:
|
| 166 |
-
|
|
|
|
|
|
|
| 167 |
|
| 168 |
return jsonify({
|
| 169 |
'success': True,
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify, send_from_directory, make_response
|
| 2 |
import os
|
| 3 |
import time
|
| 4 |
import random
|
|
|
|
| 7 |
import requests
|
| 8 |
|
| 9 |
app = Flask(__name__)
|
| 10 |
+
app.config['COMPRESS_REGISTER'] = False
|
| 11 |
+
|
| 12 |
PUBLIC_DIR = 'public'
|
| 13 |
UPLOAD_DIR = 'uploads'
|
| 14 |
os.makedirs(PUBLIC_DIR, exist_ok=True)
|
|
|
|
| 44 |
def allowed_file(filename):
|
| 45 |
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
| 46 |
|
| 47 |
+
@app.after_request
|
| 48 |
+
def after_request(response):
|
| 49 |
+
response.headers['Content-Encoding'] = 'identity'
|
| 50 |
+
response.direct_passthrough = False
|
| 51 |
+
return response
|
| 52 |
+
|
| 53 |
@app.route('/')
|
| 54 |
def index():
|
| 55 |
return jsonify({
|
|
|
|
| 110 |
continue
|
| 111 |
|
| 112 |
if html_only:
|
| 113 |
+
resp = make_response(html)
|
| 114 |
+
resp.headers['Content-Type'] = 'text/html; charset=utf-8'
|
| 115 |
+
resp.headers['X-User-Agent'] = user_agent
|
| 116 |
+
resp.headers['X-Attempts'] = str(len(failed_attempts) + 1)
|
| 117 |
+
return resp
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
return jsonify({
|
| 120 |
'success': True,
|
|
|
|
| 167 |
html = response.text
|
| 168 |
|
| 169 |
if html_only:
|
| 170 |
+
resp = make_response(html)
|
| 171 |
+
resp.headers['Content-Type'] = 'text/html; charset=utf-8'
|
| 172 |
+
return resp
|
| 173 |
|
| 174 |
return jsonify({
|
| 175 |
'success': True,
|