|
|
@ -115,18 +115,19 @@ def _jinja2_filter_datetime(watch_obj, format="%Y-%m-%d %H:%M:%S"):
|
|
|
|
|
|
|
|
|
|
|
|
return timeago.format(int(watch_obj['last_checked']), time.time())
|
|
|
|
return timeago.format(int(watch_obj['last_checked']), time.time())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# @app.context_processor
|
|
|
|
|
|
|
|
# def timeago():
|
|
|
|
|
|
|
|
# def _timeago(lower_time, now):
|
|
|
|
|
|
|
|
# return timeago.format(lower_time, now)
|
|
|
|
|
|
|
|
# return dict(timeago=_timeago)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.template_filter('format_timestamp_timeago')
|
|
|
|
@app.template_filter('format_timestamp_timeago')
|
|
|
|
def _jinja2_filter_datetimestamp(timestamp, format="%Y-%m-%d %H:%M:%S"):
|
|
|
|
def _jinja2_filter_datetimestamp(timestamp, format="%Y-%m-%d %H:%M:%S"):
|
|
|
|
|
|
|
|
if timestamp == False:
|
|
|
|
|
|
|
|
return 'Not yet'
|
|
|
|
|
|
|
|
|
|
|
|
return timeago.format(timestamp, time.time())
|
|
|
|
return timeago.format(timestamp, time.time())
|
|
|
|
# return timeago.format(timestamp, time.time())
|
|
|
|
|
|
|
|
# return datetime.datetime.utcfromtimestamp(timestamp).strftime(format)
|
|
|
|
@app.template_filter('format_seconds_ago')
|
|
|
|
|
|
|
|
def _jinja2_filter_seconds_precise(timestamp):
|
|
|
|
|
|
|
|
if timestamp == False:
|
|
|
|
|
|
|
|
return 'Not yet'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return format(int(time.time()-timestamp), ',d')
|
|
|
|
|
|
|
|
|
|
|
|
# When nobody is logged in Flask-Login's current_user is set to an AnonymousUser object.
|
|
|
|
# When nobody is logged in Flask-Login's current_user is set to an AnonymousUser object.
|
|
|
|
class User(flask_login.UserMixin):
|
|
|
|
class User(flask_login.UserMixin):
|
|
|
@ -830,7 +831,7 @@ def changedetection_app(config=None, datastore_o=None):
|
|
|
|
previous_version_file_contents = "Unable to read {}.\n".format(previous_file)
|
|
|
|
previous_version_file_contents = "Unable to read {}.\n".format(previous_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
screenshot_url = datastore.get_screenshot(uuid)
|
|
|
|
screenshot_url = watch.get_screenshot()
|
|
|
|
|
|
|
|
|
|
|
|
system_uses_webdriver = datastore.data['settings']['application']['fetch_backend'] == 'html_webdriver'
|
|
|
|
system_uses_webdriver = datastore.data['settings']['application']['fetch_backend'] == 'html_webdriver'
|
|
|
|
|
|
|
|
|
|
|
@ -850,7 +851,11 @@ def changedetection_app(config=None, datastore_o=None):
|
|
|
|
extra_title=" - Diff - {}".format(watch['title'] if watch['title'] else watch['url']),
|
|
|
|
extra_title=" - Diff - {}".format(watch['title'] if watch['title'] else watch['url']),
|
|
|
|
left_sticky=True,
|
|
|
|
left_sticky=True,
|
|
|
|
screenshot=screenshot_url,
|
|
|
|
screenshot=screenshot_url,
|
|
|
|
is_html_webdriver=is_html_webdriver)
|
|
|
|
is_html_webdriver=is_html_webdriver,
|
|
|
|
|
|
|
|
last_error=watch['last_error'],
|
|
|
|
|
|
|
|
last_error_text=watch.get_error_text(),
|
|
|
|
|
|
|
|
last_error_screenshot=watch.get_error_snapshot()
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return output
|
|
|
|
return output
|
|
|
|
|
|
|
|
|
|
|
@ -865,20 +870,34 @@ def changedetection_app(config=None, datastore_o=None):
|
|
|
|
if uuid == 'first':
|
|
|
|
if uuid == 'first':
|
|
|
|
uuid = list(datastore.data['watching'].keys()).pop()
|
|
|
|
uuid = list(datastore.data['watching'].keys()).pop()
|
|
|
|
|
|
|
|
|
|
|
|
# Normally you would never reach this, because the 'preview' button is not available when there's no history
|
|
|
|
|
|
|
|
# However they may try to clear snapshots and reload the page
|
|
|
|
|
|
|
|
if datastore.data['watching'][uuid].history_n == 0:
|
|
|
|
|
|
|
|
flash("Preview unavailable - No fetch/check completed or triggers not reached", "error")
|
|
|
|
|
|
|
|
return redirect(url_for('index'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extra_stylesheets = [url_for('static_content', group='styles', filename='diff.css')]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
watch = datastore.data['watching'][uuid]
|
|
|
|
watch = datastore.data['watching'][uuid]
|
|
|
|
except KeyError:
|
|
|
|
except KeyError:
|
|
|
|
flash("No history found for the specified link, bad link?", "error")
|
|
|
|
flash("No history found for the specified link, bad link?", "error")
|
|
|
|
return redirect(url_for('index'))
|
|
|
|
return redirect(url_for('index'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
system_uses_webdriver = datastore.data['settings']['application']['fetch_backend'] == 'html_webdriver'
|
|
|
|
|
|
|
|
extra_stylesheets = [url_for('static_content', group='styles', filename='diff.css')]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
is_html_webdriver = True if watch.get('fetch_backend') == 'html_webdriver' or (
|
|
|
|
|
|
|
|
watch.get('fetch_backend', None) is None and system_uses_webdriver) else False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Never requested successfully, but we detected a fetch error
|
|
|
|
|
|
|
|
if datastore.data['watching'][uuid].history_n == 0 and (watch.get_error_text() or watch.get_error_snapshot()):
|
|
|
|
|
|
|
|
flash("Preview unavailable - No fetch/check completed or triggers not reached", "error")
|
|
|
|
|
|
|
|
output = render_template("preview.html",
|
|
|
|
|
|
|
|
content=content,
|
|
|
|
|
|
|
|
history_n=watch.history_n,
|
|
|
|
|
|
|
|
extra_stylesheets=extra_stylesheets,
|
|
|
|
|
|
|
|
# current_diff_url=watch['url'],
|
|
|
|
|
|
|
|
watch=watch,
|
|
|
|
|
|
|
|
uuid=uuid,
|
|
|
|
|
|
|
|
is_html_webdriver=is_html_webdriver,
|
|
|
|
|
|
|
|
last_error=watch['last_error'],
|
|
|
|
|
|
|
|
last_error_text=watch.get_error_text(),
|
|
|
|
|
|
|
|
last_error_screenshot=watch.get_error_snapshot())
|
|
|
|
|
|
|
|
return output
|
|
|
|
|
|
|
|
|
|
|
|
timestamp = list(watch.history.keys())[-1]
|
|
|
|
timestamp = list(watch.history.keys())[-1]
|
|
|
|
filename = watch.history[timestamp]
|
|
|
|
filename = watch.history[timestamp]
|
|
|
@ -913,23 +932,20 @@ def changedetection_app(config=None, datastore_o=None):
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
content.append({'line': "File doesnt exist or unable to read file {}".format(filename), 'classes': ''})
|
|
|
|
content.append({'line': "File doesnt exist or unable to read file {}".format(filename), 'classes': ''})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
screenshot_url = datastore.get_screenshot(uuid)
|
|
|
|
|
|
|
|
system_uses_webdriver = datastore.data['settings']['application']['fetch_backend'] == 'html_webdriver'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
is_html_webdriver = True if watch.get('fetch_backend') == 'html_webdriver' or (
|
|
|
|
|
|
|
|
watch.get('fetch_backend', None) is None and system_uses_webdriver) else False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output = render_template("preview.html",
|
|
|
|
output = render_template("preview.html",
|
|
|
|
content=content,
|
|
|
|
content=content,
|
|
|
|
|
|
|
|
history_n=watch.history_n,
|
|
|
|
extra_stylesheets=extra_stylesheets,
|
|
|
|
extra_stylesheets=extra_stylesheets,
|
|
|
|
ignored_line_numbers=ignored_line_numbers,
|
|
|
|
ignored_line_numbers=ignored_line_numbers,
|
|
|
|
triggered_line_numbers=trigger_line_numbers,
|
|
|
|
triggered_line_numbers=trigger_line_numbers,
|
|
|
|
current_diff_url=watch['url'],
|
|
|
|
current_diff_url=watch['url'],
|
|
|
|
screenshot=screenshot_url,
|
|
|
|
screenshot=watch.get_screenshot(),
|
|
|
|
watch=watch,
|
|
|
|
watch=watch,
|
|
|
|
uuid=uuid,
|
|
|
|
uuid=uuid,
|
|
|
|
is_html_webdriver=is_html_webdriver)
|
|
|
|
is_html_webdriver=is_html_webdriver,
|
|
|
|
|
|
|
|
last_error=watch['last_error'],
|
|
|
|
|
|
|
|
last_error_text=watch.get_error_text(),
|
|
|
|
|
|
|
|
last_error_screenshot=watch.get_error_snapshot())
|
|
|
|
|
|
|
|
|
|
|
|
return output
|
|
|
|
return output
|
|
|
|
|
|
|
|
|
|
|
@ -1029,11 +1045,12 @@ def changedetection_app(config=None, datastore_o=None):
|
|
|
|
if datastore.data['settings']['application']['password'] and not flask_login.current_user.is_authenticated:
|
|
|
|
if datastore.data['settings']['application']['password'] and not flask_login.current_user.is_authenticated:
|
|
|
|
abort(403)
|
|
|
|
abort(403)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
screenshot_filename = "last-screenshot.png" if not request.args.get('error_screenshot') else "last-error-screenshot.png"
|
|
|
|
|
|
|
|
|
|
|
|
# These files should be in our subdirectory
|
|
|
|
# These files should be in our subdirectory
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
# set nocache, set content-type
|
|
|
|
# set nocache, set content-type
|
|
|
|
watch_dir = datastore_o.datastore_path + "/" + filename
|
|
|
|
response = make_response(send_from_directory(os.path.join(datastore_o.datastore_path, filename), screenshot_filename))
|
|
|
|
response = make_response(send_from_directory(filename="last-screenshot.png", directory=watch_dir, path=watch_dir + "/last-screenshot.png"))
|
|
|
|
|
|
|
|
response.headers['Content-type'] = 'image/png'
|
|
|
|
response.headers['Content-type'] = 'image/png'
|
|
|
|
response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
|
|
|
|
response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
|
|
|
|
response.headers['Pragma'] = 'no-cache'
|
|
|
|
response.headers['Pragma'] = 'no-cache'
|
|
|
|