From 83f4b8def993d8001b0ce8c5f239475bcd0ecdd0 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 18 Jun 2018 15:01:49 -0400 Subject: [PATCH] Enhanced search results page --- app.py | 2 +- database.py | 2 +- od_util.py | 107 +++++++++++++++++++++++++++++++++++++----- static/css/main.css | 5 ++ templates/search.html | 4 +- 5 files changed, 105 insertions(+), 15 deletions(-) diff --git a/app.py b/app.py index ddece8c..1929e95 100644 --- a/app.py +++ b/app.py @@ -20,7 +20,7 @@ db = Database("db.sqlite3") cache = Cache(app, config={'CACHE_TYPE': 'simple'}) app.jinja_env.globals.update(truncate_path=od_util.truncate_path) app.jinja_env.globals.update(get_color=od_util.get_color) -app.jinja_env.globals.update(get_mime=od_util.get_mime) +app.jinja_env.globals.update(get_mime=od_util.get_category) taskDispatcher = TaskDispatcher() searchEngine = ElasticSearchEngine("od-database") diff --git a/database.py b/database.py index a388bbe..0981f3e 100644 --- a/database.py +++ b/database.py @@ -214,7 +214,7 @@ class Database: if hit["_source"]["website_id"] in websites: hit["_source"]["website_url"] = websites[hit["_source"]["website_id"]] else: - hit["_source"]["website_url"] = "NONE" + hit["_source"]["website_url"] = "[DELETED]" return page diff --git a/od_util.py b/od_util.py index 2961d4b..72be7d0 100644 --- a/od_util.py +++ b/od_util.py @@ -18,25 +18,112 @@ def truncate_path(path, max_len): return ".../" + path.rsplit("/", maxsplit=1)[1] if "/" in path else path +category_map = { + + # Application category + 'bcpio': 'application', 'bin': 'application', 'cdf': 'application', + 'csh': 'application', 'dll': 'application', 'doc': 'application', + 'dot': 'application', 'dvi': 'application', 'eml': 'application', + 'exe': 'application', 'hdf': 'application', + 'man': 'application', 'me': 'application', 'mht': 'application', + 'mhtml': 'application', 'mif': 'application', 'ms': 'application', + 'nc': 'application', 'nws': 'application', 'o': 'application', + 'obj': 'application', 'oda': 'application', 'p12': 'application', + 'p7c': 'application', 'pfx': 'application', 'tr': 'application', + 'ppa': 'application', 'pps': 'application', 'ppt': 'application', + 'ps': 'application', 'pwz': 'application', 'pyc': 'application', + 'pyo': 'application', 'ram': 'application', 'rdf': 'application', + 'roff': 'application', 'sh': 'application', 'so': 'application', + 'src': 'application', 'sv4cpio': 'application', 'sv4crc': 'application', + 't': 'application', 'tcl': 'application', 'tex': 'application', + 'texi': 'application', 'texinfo': 'application', 'ustar': 'application', + 'wiz': 'application', 'wsdl': 'application', 'xlb': 'application', + 'xls': 'application', 'xpdl': 'application', 'xsl': 'application', + 'torrent': 'application', + # Text category + 'java': 'text', 'cpp': 'text', 'rb': 'text', + 'bat': 'text', 'latex': 'text', 'xml': 'text', + 'etx': 'text', 'htm': 'text', 'c': 'text', + 'css': 'text', 'csv': 'text', 'html': 'text', + 'js': 'text', 'json': 'text', 'ksh': 'text', + 'pl': 'text', 'pot': 'application', 'py': 'text', + 'h': 'text', 'tsv': 'text', 'rtx': 'text', + 'sgm': 'text', 'sgml': 'text', 'txt': 'text', + 'vcf': 'text', 'pdf': 'text', 'epub': 'text', + # Video category + '3g2': 'video', '3gp': 'video', 'asf': 'video', + 'asx': 'video', 'avi': 'video', 'flv': 'video', + 'swf': 'video', 'vob:': 'video', 'qt': 'video', + 'webm': 'video', 'mov': 'video', 'm1v': 'video', + 'm3u': 'video', 'm3u8': 'video', 'movie': 'video', + 'mp4': 'video', 'mpa': 'video', 'mpe': 'video', + 'mpeg': 'video', 'mpg': 'video', 'mkv': 'video', + 'wmv': 'video', + # Audio category + 'wav': 'audio', 'snd': 'audio', 'mp2': 'audio', + 'aif': 'audio', 'iff': 'audio', 'm4a': 'audio', + 'mid': 'audio', 'midi': 'audio', 'mp3': 'audio', + 'wma': 'audio', 'ra': 'audio', 'aifc': 'audio', + 'aiff': 'audio', 'au': 'audio', + # Image category + 'bmp': 'image', 'gif': 'image', 'jpg': 'image', + 'xwd': 'image', 'tif': 'image', 'tiff': 'image', + 'png': 'image', 'pnm': 'image', 'ras': 'image', + 'ico': 'image', 'ief': 'image', 'pgm': 'image', + 'jpe': 'image', 'pbm': 'image', 'jpeg': 'image', + 'ppm': 'image', 'xpm': 'image', 'xbm': 'image', + 'rgb': 'image', 'svg': 'image', 'psd': 'image', + 'yuv': 'image', 'ai': 'image', 'eps': 'image', + # Archive category + 'ar': 'archive', 'cpio': 'archive', 'shar': 'archive', + 'iso': 'archive', 'lbr': 'archive', 'mar': 'archive', + 'sbx': 'archive', 'bz2': 'archive', 'f': 'archive', + 'gz': 'archive', 'lz': 'archive', 'lzma': 'archive', + 'lzo': 'archive', 'rz': 'archive', 'sfark': 'archive', + 'sz': 'archive', 'z': 'archive', '7z': 'archive', + 's7z': 'archive', 'ace': 'archive', 'afa': 'archive', + 'alz': 'archive', 'apk': 'archive', 'arc': 'archive', + 'arj': 'archive', 'b1': 'archive', 'b6z': 'archive', + 'a': 'archive', 'bh': 'archive', 'cab': 'archive', + 'car': 'archive', 'cfs': 'archive', 'cpt': 'archive', + 'dar': 'archive', 'dd': 'archive', 'dgc': 'archive', + 'dmg': 'archive', 'ear': 'archive', 'gca': 'archive', + 'ha': 'archive', 'hki': 'archive', 'ice': 'archive', + 'jar': 'archive', 'kgb': 'archive', 'lzh': 'archive', + 'lha': 'archive', 'lzx': 'archive', 'pak': 'archive', + 'partimg': 'archive', 'paq6': 'archive', 'paq7': 'archive', + 'paq8': 'archive', 'pea': 'archive', 'pim': 'archive', + 'pit': 'archive', 'qda': 'archive', 'rar': 'archive', + 'rk': 'archive', 'sda': 'archive', 'sea': 'archive', + 'sen': 'archive', 'sfx': 'archive', 'shk': 'archive', + 'sit': 'archive', 'sitx': 'archive', 'sqx': 'archive', + 'tbz2': 'archive', 'tlz': 'archive', 'xz': 'archive', + 'txz': 'archive', 'uc': 'archive', 'uc0': 'archive', + 'uc2': 'archive', 'ucn': 'archive', 'ur2': 'archive', + 'ue2': 'archive', 'uca': 'archive', 'uha': 'archive', + 'war': 'archive', 'wim': 'archive', 'xar': 'archive', + 'xp3': 'archive', 'yz1': 'archive', 'zip': 'archive', + 'zipx': 'archive', 'zoo': 'archive', 'zpaq': 'archive', + 'zz': 'archive', 'xpi': 'archive', 'tgz': 'archive', + 'tbz': 'archive' +} + colors = { "application": "bg-application", "text": "bg-text", "video": "bg-video", "image": "bg-image", - "audio": "bg-audio" + "audio": "bg-audio", + "archive": "bg-archive" } -def get_color(mime): - return colors.get(mime.split("/", maxsplit=1)[0], None) +def get_color(category): + return colors.get(category, None) -def get_mime(file_name): - mime = mimetypes.guess_type(file_name) - if mime[0]: - return mime[0] - else: - return None +def get_category(extension): + return category_map.get(extension, None) def is_valid_url(url): @@ -62,7 +149,6 @@ def is_external_link(base_url, url: str): def is_od(url): - if not url.endswith("/"): print("Url does not end with trailing /") return False @@ -105,7 +191,6 @@ def is_od(url): def is_blacklisted(url): - with open("blacklist.txt", "r") as f: for line in f.readlines(): if url.startswith(line.strip()): diff --git a/static/css/main.css b/static/css/main.css index 66d3863..73d8586 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -19,6 +19,11 @@ color: #FFFFFF; } +.bg-archive { + background: #1fa32a; + color: #FFFFFF; +} + .bg-audio { background: #009CD8; color: #FFFFFF; diff --git a/templates/search.html b/templates/search.html index 2cdfc3a..6749ecb 100644 --- a/templates/search.html +++ b/templates/search.html @@ -62,10 +62,10 @@ {{ hl_name |safe }}{{ ("." if src["ext"] != "" else "") + src["ext"] }} {# File type badge #} - {% set mime = get_mime(src["path"]) %} + {% set mime = get_mime(src["ext"]) %} {% if mime %} - {{ src["path"][src["path"].rfind(".") + 1:] }} + {{ src["ext"] }} {% endif %} {# File path #}