From d449edeb233099be719a6baec87217bddb92c101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Fri, 20 Jan 2023 11:15:33 +0100 Subject: [PATCH] new: Allow API user to force re-caching the captures on URL/Hostname request --- lookyloo/lookyloo.py | 8 ++++---- website/web/genericapi.py | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lookyloo/lookyloo.py b/lookyloo/lookyloo.py index 33c44e7..67da7d9 100644 --- a/lookyloo/lookyloo.py +++ b/lookyloo/lookyloo.py @@ -757,9 +757,9 @@ class Lookyloo(): return captures[0] return None - def get_url_occurrences(self, url: str, /, limit: int=20) -> List[Dict]: + def get_url_occurrences(self, url: str, /, limit: int=20, cached_captures_only: bool=True) -> List[Dict]: '''Get the most recent captures and URL nodes where the URL has been seen.''' - captures = self.sorted_capture_cache(self.indexing.get_captures_url(url)) + captures = self.sorted_capture_cache(self.indexing.get_captures_url(url), cached_captures_only=cached_captures_only) to_return: List[Dict] = [] for capture in captures[:limit]: @@ -777,9 +777,9 @@ class Lookyloo(): to_return.append(to_append) return to_return - def get_hostname_occurrences(self, hostname: str, /, with_urls_occurrences: bool=False, limit: int=20) -> List[Dict]: + def get_hostname_occurrences(self, hostname: str, /, with_urls_occurrences: bool=False, limit: int=20, cached_captures_only: bool=True) -> List[Dict]: '''Get the most recent captures and URL nodes where the hostname has been seen.''' - captures = self.sorted_capture_cache(self.indexing.get_captures_hostname(hostname)) + captures = self.sorted_capture_cache(self.indexing.get_captures_hostname(hostname), cached_captures_only=cached_captures_only) to_return: List[Dict] = [] for capture in captures[:limit]: diff --git a/website/web/genericapi.py b/website/web/genericapi.py index 56f5fca..18fd9bd 100644 --- a/website/web/genericapi.py +++ b/website/web/genericapi.py @@ -280,6 +280,7 @@ class HashInfo(Resource): url_info_fields = api.model('URLInfoFields', { 'url': fields.String(description="The URL to search", required=True), 'limit': fields.Integer(description="The maximal amount of captures to return", example=20), + 'cached_captures_only': fields.Boolean(description="If false, re-cache the missing captures (can take a while)", default=True), }) @@ -297,6 +298,7 @@ class URLInfo(Resource): hostname_info_fields = api.model('HostnameInfoFields', { 'hostname': fields.String(description="The hostname to search", required=True), 'limit': fields.Integer(description="The maximal amount of captures to return", example=20), + 'cached_captures_only': fields.Boolean(description="If false, re-cache the missing captures (can take a while)", default=True), })