new: get uuids by category via API

pull/926/head
Adrian Maraj 2024-07-23 14:10:38 +02:00
parent b20ddb4788
commit e4268554b9
1 changed files with 28 additions and 0 deletions

View File

@ -794,3 +794,31 @@ class CaptureHide(Resource): # type: ignore[misc]
class RecentCaptures(Resource): # type: ignore[misc] class RecentCaptures(Resource): # type: ignore[misc]
def get(self, timestamp: str | float | None=None) -> list[str]: def get(self, timestamp: str | float | None=None) -> list[str]:
return lookyloo.get_recent_captures(since=timestamp) return lookyloo.get_recent_captures(since=timestamp)
@api.route('/json/categories')
@api.route('/json/categories/<string:category>')
@api.doc(description='Get uuids for a specific category.',
params={'category': 'The category according to which the uuids are to be returned.'},
required=False)
class CategoriesCaptures(Resource): # type: ignore[misc]
def get(self, category: str | None=None) -> list[str] | dict[str, list[str]] | None:
categories = ['legitimate', 'parking-page', 'default-page', 'insti_usertution', 'captcha',
'authentication-form', 'adult-content', 'shop', 'malicious', 'clone', 'phishing', 'unclear']
if not category:
all_categorized_uuids: dict[str, set[str]] = {}
for c in categories:
one_categorie = get_indexing(flask_login.current_user).get_captures_category(c)
if not one_categorie:
continue
for uuid in one_categorie:
if uuid not in all_categorized_uuids:
all_categorized_uuids[uuid] = {c}
else:
all_categorized_uuids[uuid].add(c)
all_categorized_uuids = {uuid: list(categories) for uuid, categories in all_categorized_uuids.items()}
return all_categorized_uuids
if not category in categories:
return {'error': f'Invalid category: {category}'}
return list(get_indexing(flask_login.current_user).get_captures_category(category))