chg: use cache instead of get_info everywhere.

pull/559/head
Raphaël Vinot 2022-12-07 14:32:13 +01:00
parent 94b3b487f3
commit 3e7f1c3de9
3 changed files with 15 additions and 11 deletions

View File

@ -427,7 +427,12 @@ class Lookyloo():
def capture_cache(self, capture_uuid: str, /) -> Optional[CaptureCache]:
"""Get the cache from redis, rebuild the tree if the internal UUID changed => slow"""
try:
return self._captures_index[capture_uuid]
cache = self._captures_index[capture_uuid]
# 2022-12-07: New cache format, store the user agent and referers. Re-cache if needed
if cache and not cache.user_agent:
self._captures_index.reload_cache(capture_uuid)
cache = self._captures_index[capture_uuid]
return cache
except NoValidHarFile:
self.logger.debug('No HAR files, {capture_uuid} is a broken capture.')
return None

View File

@ -662,7 +662,6 @@ def tree(tree_uuid: str, node_uuid: Optional[str]=None):
ct = lookyloo.get_crawled_tree(tree_uuid)
b64_thumbnail = lookyloo.get_screenshot_thumbnail(tree_uuid, for_datauri=True)
screenshot_size = lookyloo.get_screenshot(tree_uuid).getbuffer().nbytes
info = lookyloo.get_info(tree_uuid)
meta = lookyloo.get_meta(tree_uuid)
hostnode_to_highlight = None
if node_uuid:
@ -682,7 +681,7 @@ def tree(tree_uuid: str, node_uuid: Optional[str]=None):
if cache.error:
flash(cache.error, 'warning')
return render_template('tree.html', tree_json=ct.to_json(),
info=info,
info=cache,
tree_uuid=tree_uuid, public_domain=lookyloo.public_domain,
screenshot_thumbnail=b64_thumbnail, page_title=cache.title,
screenshot_size=screenshot_size,

View File

@ -3,14 +3,14 @@
{% from 'bootstrap5/utils.html' import render_messages %}
{% from "macros.html" import shorten_string %}
{% block title %}Capture of {{info['url']}}{% endblock %}
{% block title %}Capture of {{info.url}}{% endblock %}
{% block card %}
<meta property="og:title" content="Lookyloo capture" />
<meta property="og:type" content="website"/>
<meta
property="og:description"
content="URL captured: {{info['url']}}"
content="URL captured: {{info.url}}"
/>
<meta
property="og:image"
@ -148,7 +148,7 @@
var enable_bookmark = {{ enable_bookmark|tojson }};
var treeData = {{ tree_json | safe }};
var parent_uuid = {{ parent_uuid|tojson }};
var capture_starttime = new Date(Date.parse("{{ info['capture_time'] }}"));
var capture_starttime = new Date(Date.parse("{{ info.timestamp.isoformat() }}"));
window.addEventListener('DOMContentLoaded', (event) => {
document.getElementById("start_time").innerHTML =
`${capture_starttime.getFullYear()}-${("0" + (capture_starttime.getMonth() + 1)).slice(-2)}-${("0" + capture_starttime.getDate()).slice(-2)} ${capture_starttime.toLocaleTimeString()}`;
@ -413,20 +413,20 @@
<div class="modal-body">
<dl class="row">
<dt class="col-sm-2">URL captured</dt>
<dd class="col-sm-10">{{ shorten_string(info['url'], 1000) }}</dd>
<dd class="col-sm-10">{{ shorten_string(info.url, 1000) }}</dd>
<dt class="col-sm-2">Page title</dt>
<dd class="col-sm-10">{{ info['title'] }}</dd>
<dd class="col-sm-10">{{ info.title }}</dd>
<dt class="col-sm-2">Capture time</dt>
<dd class="col-sm-10" id="start_time"></dd>
<dt class="col-sm-2">User Agent</dt>
<dd class="col-sm-10">{{ info['user_agent'] }}</dd>
<dd class="col-sm-10">{{ info.user_agent }}</dd>
{% if 'referer' in info and info['referer'] %}
{% if info.referer %}
<dt class="col-sm-2">Referer</dt>
<dd class="col-sm-10">{{ info['referer'] }}</dd>
<dd class="col-sm-10">{{ info.referer }}</dd>
{%endif%}