mirror of
				https://github.com/dgtlmoon/changedetection.io.git
				synced 2025-11-03 16:17:51 +00:00 
			
		
		
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			3526-refac
			...
			faster-bro
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					1a331b77bd | 
@@ -27,6 +27,7 @@ from flask import (
 | 
			
		||||
    session,
 | 
			
		||||
    url_for,
 | 
			
		||||
)
 | 
			
		||||
from flask_compress import Compress as FlaskCompress
 | 
			
		||||
from flask_login import login_required
 | 
			
		||||
from flask_restful import abort, Api
 | 
			
		||||
from flask_wtf import CSRFProtect
 | 
			
		||||
@@ -51,6 +52,10 @@ app = Flask(__name__,
 | 
			
		||||
            static_url_path="",
 | 
			
		||||
            static_folder="static",
 | 
			
		||||
            template_folder="templates")
 | 
			
		||||
from flask_compress import Compress
 | 
			
		||||
 | 
			
		||||
# Super handy for compressing large BrowserSteps responses and others
 | 
			
		||||
FlaskCompress(app)
 | 
			
		||||
 | 
			
		||||
# Stop browser caching of assets
 | 
			
		||||
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
 | 
			
		||||
 
 | 
			
		||||
@@ -210,16 +210,29 @@ def construct_blueprint(datastore: ChangeDetectionStore):
 | 
			
		||||
        except playwright._impl._api_types.Error as e:
 | 
			
		||||
            return make_response("Browser session ran out of time :( Please reload this page."+str(e), 401)
 | 
			
		||||
 | 
			
		||||
        p = {'screenshot': "data:image/png;base64,{}".format(
 | 
			
		||||
        # Use send_file() which is way faster than read/write loop on bytes
 | 
			
		||||
        import json
 | 
			
		||||
        from tempfile import mkstemp
 | 
			
		||||
        from flask import send_file
 | 
			
		||||
        tmp_fd, tmp_file = mkstemp(text=True, suffix=".json", prefix="changedetectionio-")
 | 
			
		||||
 | 
			
		||||
        output = json.dumps({'screenshot': "data:image/png;base64,{}".format(
 | 
			
		||||
            base64.b64encode(state[0]).decode('ascii')),
 | 
			
		||||
            'xpath_data': state[1],
 | 
			
		||||
            'session_age_start': this_session.age_start,
 | 
			
		||||
            'browser_time_remaining': round(remaining)
 | 
			
		||||
        }
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        with os.fdopen(tmp_fd, 'w') as f:
 | 
			
		||||
            f.write(output)
 | 
			
		||||
 | 
			
		||||
        # @todo BSON/binary JSON, faster xfer, OR pick it off the disk
 | 
			
		||||
        return p
 | 
			
		||||
        response = make_response(send_file(path_or_file=tmp_file,
 | 
			
		||||
                                           mimetype='application/json; charset=UTF-8',
 | 
			
		||||
                                           etag=True))
 | 
			
		||||
        # No longer needed
 | 
			
		||||
        os.unlink(tmp_file)
 | 
			
		||||
 | 
			
		||||
        return response
 | 
			
		||||
 | 
			
		||||
    return browser_steps_blueprint
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
flask~=2.0
 | 
			
		||||
flask_wtf
 | 
			
		||||
flask-compress
 | 
			
		||||
eventlet>=0.31.0
 | 
			
		||||
validators
 | 
			
		||||
timeago~=1.0
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user