From 3fe7ecf75aab4f4c8460429fcb5f02e8e4c8cf07 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Tue, 12 Dec 2017 10:48:21 +0100 Subject: [PATCH] feature: diff in the web interface for duplicates pastes. --- var/www/modules/showpaste/Flask_showpaste.py | 19 ++++++++++++++++++- .../showpaste/templates/show_saved_paste.html | 10 ++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/var/www/modules/showpaste/Flask_showpaste.py b/var/www/modules/showpaste/Flask_showpaste.py index 0967f76f..eedfda17 100644 --- a/var/www/modules/showpaste/Flask_showpaste.py +++ b/var/www/modules/showpaste/Flask_showpaste.py @@ -7,7 +7,8 @@ import redis import json import flask -from flask import Flask, render_template, jsonify, request, Blueprint +from flask import Flask, render_template, jsonify, request, Blueprint, make_response +import difflib import Paste @@ -113,5 +114,21 @@ def getmoredata(): to_return = p_content[max_preview_modal-1:] return to_return +@showsavedpastes.route("/showDiff/") +def showDiff(): + s1 = request.args.get('s1', '') + s2 = request.args.get('s2', '') + p1 = Paste.Paste(s1) + p2 = Paste.Paste(s2) + maxLengthLine1 = p1.get_lines_info()[1] + maxLengthLine2 = p2.get_lines_info()[1] + if maxLengthLine1 > 100000 or maxLengthLine2 > 100000: + return "Can't make the difference as the lines are too long." + htmlD = difflib.HtmlDiff() + lines1 = p1.get_p_content().decode('utf8', 'ignore').splitlines() + lines2 = p2.get_p_content().decode('utf8', 'ignore').splitlines() + the_html = htmlD.make_file(lines1, lines2) + return the_html + # ========= REGISTRATION ========= app.register_blueprint(showsavedpastes) diff --git a/var/www/modules/showpaste/templates/show_saved_paste.html b/var/www/modules/showpaste/templates/show_saved_paste.html index d58b243f..d1d89dd7 100644 --- a/var/www/modules/showpaste/templates/show_saved_paste.html +++ b/var/www/modules/showpaste/templates/show_saved_paste.html @@ -15,14 +15,14 @@ - +

Paste: {{ request.args.get('paste') }}

- + @@ -62,7 +62,8 @@ - + + @@ -72,6 +73,7 @@ + {% set i = i + 1 %} {% endfor %} @@ -82,7 +84,7 @@

{{ content }}

- +
Hash type Paste info DatePathPathAction
Similarity: {{ simil_list[i] }}% {{ date_list[i] }} {{ dup_path }}