■ ■ ■ ■ ■ ■ ■
changedetectionio/__init__.py
| skipped 781 lines |
782 | 782 | | |
783 | 783 | | return redirect(url_for('index')) |
784 | 784 | | |
| 785 | + | |
| 786 | + | @app.route("/diff/image/<string:uuid>", methods=['GET']) |
| 787 | + | @login_required |
| 788 | + | def diff_image_history_page(uuid): |
| 789 | + | |
| 790 | + | # More for testing, possible to return the first/only |
| 791 | + | if uuid == 'first': |
| 792 | + | uuid = list(datastore.data['watching'].keys()).pop() |
| 793 | + | |
| 794 | + | extra_stylesheets = [url_for('static_content', group='styles', filename='diff.css')] |
| 795 | + | try: |
| 796 | + | watch = datastore.data['watching'][uuid] |
| 797 | + | except KeyError: |
| 798 | + | flash("No history found for the specified link, bad link?", "error") |
| 799 | + | return redirect(url_for('index')) |
| 800 | + | |
| 801 | + | history = watch.history |
| 802 | + | dates = list(history.keys()) |
| 803 | + | |
| 804 | + | if len(dates) < 2: |
| 805 | + | flash("Not enough saved change detection snapshots to produce a report.", "error") |
| 806 | + | return redirect(url_for('index')) |
| 807 | + | |
| 808 | + | previous_version = dates[-2] |
| 809 | + | |
| 810 | + | output = render_template("diff-image.html", |
| 811 | + | watch=watch, |
| 812 | + | extra_stylesheets=extra_stylesheets, |
| 813 | + | versions=dates[:-1], # All except current/last |
| 814 | + | uuid=uuid, |
| 815 | + | newest_version_timestamp=dates[-1], |
| 816 | + | current_previous_version=str(previous_version), |
| 817 | + | current_diff_url=watch['url'], |
| 818 | + | extra_title=" - Diff - {}".format(watch['title'] if watch['title'] else watch['url']), |
| 819 | + | left_sticky=True, |
| 820 | + | last_error=watch['last_error'], |
| 821 | + | last_error_text=watch.get_error_text(), |
| 822 | + | last_error_screenshot=watch.get_error_snapshot() |
| 823 | + | ) |
| 824 | + | return output |
| 825 | + | |
| 826 | + | |
785 | 827 | | @app.route("/diff/<string:uuid>", methods=['GET']) |
786 | 828 | | @login_required |
787 | 829 | | def diff_history_page(uuid): |
| skipped 159 lines |
947 | 989 | | |
948 | 990 | | return output |
949 | 991 | | |
| 992 | + | @app.route("/preview/image/<string:uuid>/<string:history_timestamp>") |
| 993 | + | def render_single_image(uuid, history_timestamp): |
| 994 | + | |
| 995 | + | watch = datastore.data['watching'].get(uuid) |
| 996 | + | dates = list(watch.history.keys()) |
| 997 | + | |
| 998 | + | |
| 999 | + | if not history_timestamp or history_timestamp == 'None': |
| 1000 | + | history_timestamp = dates[-2] |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | filename = watch.history[history_timestamp] |
| 1004 | + | with open(filename, 'rb') as f: |
| 1005 | + | img = f.read() |
| 1006 | + | |
| 1007 | + | response = make_response(img) |
| 1008 | + | |
| 1009 | + | response.headers['Content-type'] = 'image/png' |
| 1010 | + | response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate' |
| 1011 | + | response.headers['Pragma'] = 'no-cache' |
| 1012 | + | response.headers['Expires'] = 0 |
| 1013 | + | |
| 1014 | + | return response |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | # Diff renderer for images |
| 1019 | + | # Renders the diff which includes the red box around what changes |
| 1020 | + | # We always compare the newest against whatever compare_date we are given |
| 1021 | + | @app.route("/diff/image/<string:uuid>/<string:compare_date>") |
| 1022 | + | def render_diff_image(uuid, compare_date): |
| 1023 | + | from changedetectionio import image_diff |
| 1024 | + | |
| 1025 | + | from flask import make_response |
| 1026 | + | watch = datastore.data['watching'].get(uuid) |
| 1027 | + | |
| 1028 | + | dates = list(watch.history.keys()) |
| 1029 | + | if len(dates) < 2: |
| 1030 | + | flash("Not enough saved change detection snapshots to produce a report.", "error") |
| 1031 | + | return redirect(url_for('index')) |
| 1032 | + | |
| 1033 | + | if not compare_date or compare_date == 'None': |
| 1034 | + | compare_date = dates[-2] |
| 1035 | + | |
| 1036 | + | new_img = watch.history[watch.newest_history_key] |
| 1037 | + | prev_img = watch.history[compare_date] |
| 1038 | + | |
| 1039 | + | img = image_diff.render_diff(new_img, prev_img) |
| 1040 | + | |
| 1041 | + | resp = make_response(img) |
| 1042 | + | resp.headers['Content-Type'] = 'image/jpeg' |
| 1043 | + | return resp |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
950 | 1047 | | @app.route("/settings/notification-logs", methods=['GET']) |
951 | 1048 | | @login_required |
952 | 1049 | | def notification_logs(): |
| skipped 142 lines |
1095 | 1192 | | return redirect(url_for('index')) |
1096 | 1193 | | |
1097 | 1194 | | url = request.form.get('url').strip() |
| 1195 | + | fetch_processor =request.form.get('fetch_processor').strip() |
1098 | 1196 | | if datastore.url_exists(url): |
1099 | 1197 | | flash('The URL {} already exists'.format(url), "error") |
1100 | 1198 | | return redirect(url_for('index')) |
1101 | 1199 | | |
1102 | 1200 | | add_paused = request.form.get('edit_and_watch_submit_button') != None |
1103 | | - | new_uuid = datastore.add_watch(url=url, tag=request.form.get('tag').strip(), extras={'paused': add_paused}) |
| 1201 | + | new_uuid = datastore.add_watch(url=url, |
| 1202 | + | tag=request.form.get('tag').strip(), |
| 1203 | + | extras={'paused': add_paused, 'fetch_processor': fetch_processor} |
| 1204 | + | ) |
1104 | 1205 | | |
1105 | 1206 | | |
1106 | 1207 | | if not add_paused and new_uuid: |
| skipped 134 lines |
1241 | 1342 | | |
1242 | 1343 | | return redirect(url_for('index')) |
1243 | 1344 | | |
1244 | | - | @app.route("/api/share-url", methods=['GET']) |
| 1345 | + | @app.route("/api/r-url", methods=['GET']) |
1245 | 1346 | | @login_required |
1246 | 1347 | | def form_share_put_watch(): |
1247 | 1348 | | """Given a watch UUID, upload the info and return a share-link |
| skipped 217 lines |