mirror of
https://github.com/simon987/od-database.git
synced 2025-04-19 18:36:44 +00:00
Enhanced search results page
This commit is contained in:
parent
8a73142ff8
commit
83f4b8def9
2
app.py
2
app.py
@ -20,7 +20,7 @@ db = Database("db.sqlite3")
|
|||||||
cache = Cache(app, config={'CACHE_TYPE': 'simple'})
|
cache = Cache(app, config={'CACHE_TYPE': 'simple'})
|
||||||
app.jinja_env.globals.update(truncate_path=od_util.truncate_path)
|
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_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()
|
taskDispatcher = TaskDispatcher()
|
||||||
searchEngine = ElasticSearchEngine("od-database")
|
searchEngine = ElasticSearchEngine("od-database")
|
||||||
|
@ -214,7 +214,7 @@ class Database:
|
|||||||
if hit["_source"]["website_id"] in websites:
|
if hit["_source"]["website_id"] in websites:
|
||||||
hit["_source"]["website_url"] = websites[hit["_source"]["website_id"]]
|
hit["_source"]["website_url"] = websites[hit["_source"]["website_id"]]
|
||||||
else:
|
else:
|
||||||
hit["_source"]["website_url"] = "NONE"
|
hit["_source"]["website_url"] = "[DELETED]"
|
||||||
|
|
||||||
return page
|
return page
|
||||||
|
|
||||||
|
107
od_util.py
107
od_util.py
@ -18,25 +18,112 @@ def truncate_path(path, max_len):
|
|||||||
return ".../" + path.rsplit("/", maxsplit=1)[1] if "/" in path else path
|
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 = {
|
colors = {
|
||||||
"application": "bg-application",
|
"application": "bg-application",
|
||||||
"text": "bg-text",
|
"text": "bg-text",
|
||||||
"video": "bg-video",
|
"video": "bg-video",
|
||||||
"image": "bg-image",
|
"image": "bg-image",
|
||||||
"audio": "bg-audio"
|
"audio": "bg-audio",
|
||||||
|
"archive": "bg-archive"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_color(mime):
|
def get_color(category):
|
||||||
return colors.get(mime.split("/", maxsplit=1)[0], None)
|
return colors.get(category, None)
|
||||||
|
|
||||||
|
|
||||||
def get_mime(file_name):
|
def get_category(extension):
|
||||||
mime = mimetypes.guess_type(file_name)
|
return category_map.get(extension, None)
|
||||||
if mime[0]:
|
|
||||||
return mime[0]
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def is_valid_url(url):
|
def is_valid_url(url):
|
||||||
@ -62,7 +149,6 @@ def is_external_link(base_url, url: str):
|
|||||||
|
|
||||||
|
|
||||||
def is_od(url):
|
def is_od(url):
|
||||||
|
|
||||||
if not url.endswith("/"):
|
if not url.endswith("/"):
|
||||||
print("Url does not end with trailing /")
|
print("Url does not end with trailing /")
|
||||||
return False
|
return False
|
||||||
@ -105,7 +191,6 @@ def is_od(url):
|
|||||||
|
|
||||||
|
|
||||||
def is_blacklisted(url):
|
def is_blacklisted(url):
|
||||||
|
|
||||||
with open("blacklist.txt", "r") as f:
|
with open("blacklist.txt", "r") as f:
|
||||||
for line in f.readlines():
|
for line in f.readlines():
|
||||||
if url.startswith(line.strip()):
|
if url.startswith(line.strip()):
|
||||||
|
@ -19,6 +19,11 @@
|
|||||||
color: #FFFFFF;
|
color: #FFFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bg-archive {
|
||||||
|
background: #1fa32a;
|
||||||
|
color: #FFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
.bg-audio {
|
.bg-audio {
|
||||||
background: #009CD8;
|
background: #009CD8;
|
||||||
color: #FFFFFF;
|
color: #FFFFFF;
|
||||||
|
@ -62,10 +62,10 @@
|
|||||||
{{ hl_name |safe }}{{ ("." if src["ext"] != "" else "") + src["ext"] }}
|
{{ hl_name |safe }}{{ ("." if src["ext"] != "" else "") + src["ext"] }}
|
||||||
</a>
|
</a>
|
||||||
{# File type badge #}
|
{# File type badge #}
|
||||||
{% set mime = get_mime(src["path"]) %}
|
{% set mime = get_mime(src["ext"]) %}
|
||||||
{% if mime %}
|
{% if mime %}
|
||||||
<span class="badge badge-pill {{ get_color(mime) }}">
|
<span class="badge badge-pill {{ get_color(mime) }}">
|
||||||
{{ src["path"][src["path"].rfind(".") + 1:] }}
|
{{ src["ext"] }}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{# File path #}
|
{# File path #}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user