chg: [message image] show qrcodes extracted

pull/607/merge
terrtia 2024-10-04 15:10:29 +02:00
parent d91e14f200
commit c8b1c67a08
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
6 changed files with 45 additions and 11 deletions

View File

@ -23,6 +23,7 @@ from lib.objects import Chats
from lib.objects import ChatSubChannels from lib.objects import ChatSubChannels
from lib.objects import ChatThreads from lib.objects import ChatThreads
from lib.objects import Messages from lib.objects import Messages
from lib.objects.QrCodes import Qrcode
from lib.objects import UsersAccount from lib.objects import UsersAccount
from lib.objects import Usernames from lib.objects import Usernames
from lib import Language from lib import Language
@ -418,7 +419,7 @@ def get_nb_messages_iterator(filters={}):
nb_messages += chat.get_nb_messages() nb_messages += chat.get_nb_messages()
return nb_messages return nb_messages
def get_chat_object_messages_forward_meta(c_messages): def get_chat_object_messages_meta(c_messages):
temp_chats = {} temp_chats = {}
for date in c_messages: for date in c_messages:
for meta in c_messages[date]: for meta in c_messages[date]:
@ -428,6 +429,12 @@ def get_chat_object_messages_forward_meta(c_messages):
temp_chats[meta['forwarded_from']] = chat.get_meta({'icon'}) temp_chats[meta['forwarded_from']] = chat.get_meta({'icon'})
else: else:
meta['forwarded_from'] = temp_chats[meta['forwarded_from']] meta['forwarded_from'] = temp_chats[meta['forwarded_from']]
if meta['qrcodes']:
qrcodes = []
for q in meta['qrcodes']:
qr = Qrcode(q)
qrcodes.append({'id': qr.id, 'content': qr.get_content(), 'tags': qr.get_tags()})
meta['qrcodes'] = qrcodes
return c_messages return c_messages
def get_user_account_chats_meta(user_id, chats, subchannels): def get_user_account_chats_meta(user_id, chats, subchannels):
@ -754,7 +761,7 @@ def api_get_chat(chat_id, chat_instance_uuid, translation_target=None, nb=-1, pa
translation_target = None translation_target = None
if messages: if messages:
meta['messages'], meta['pagination'], meta['tags_messages'] = chat.get_messages(translation_target=translation_target, nb=nb, page=page) meta['messages'], meta['pagination'], meta['tags_messages'] = chat.get_messages(translation_target=translation_target, nb=nb, page=page)
meta['messages'] = get_chat_object_messages_forward_meta(meta['messages']) meta['messages'] = get_chat_object_messages_meta(meta['messages'])
return meta, 200 return meta, 200
def api_get_nb_message_by_week(chat_type, chat_instance_uuid, chat_id): def api_get_nb_message_by_week(chat_type, chat_instance_uuid, chat_id):
@ -800,7 +807,7 @@ def api_get_subchannel(chat_id, chat_instance_uuid, translation_target=None, nb=
if meta.get('username'): if meta.get('username'):
meta['username'] = get_username_meta_from_global_id(meta['username']) meta['username'] = get_username_meta_from_global_id(meta['username'])
meta['messages'], meta['pagination'], meta['tags_messages'] = subchannel.get_messages(translation_target=translation_target, nb=nb, page=page) meta['messages'], meta['pagination'], meta['tags_messages'] = subchannel.get_messages(translation_target=translation_target, nb=nb, page=page)
meta['messages'] = get_chat_object_messages_forward_meta(meta['messages']) meta['messages'] = get_chat_object_messages_meta(meta['messages'])
return meta, 200 return meta, 200
def api_get_thread(thread_id, thread_instance_uuid, translation_target=None, nb=-1, page=-1): def api_get_thread(thread_id, thread_instance_uuid, translation_target=None, nb=-1, page=-1):
@ -812,17 +819,22 @@ def api_get_thread(thread_id, thread_instance_uuid, translation_target=None, nb=
# if meta['chat']: # if meta['chat']:
# meta['chat'] = get_chat_meta_from_global_id(meta['chat']) # meta['chat'] = get_chat_meta_from_global_id(meta['chat'])
meta['messages'], meta['pagination'], meta['tags_messages'] = thread.get_messages(translation_target=translation_target, nb=nb, page=page) meta['messages'], meta['pagination'], meta['tags_messages'] = thread.get_messages(translation_target=translation_target, nb=nb, page=page)
meta['messages'] = get_chat_object_messages_forward_meta(meta['messages']) meta['messages'] = get_chat_object_messages_meta(meta['messages'])
return meta, 200 return meta, 200
def api_get_message(message_id, translation_target=None): def api_get_message(message_id, translation_target=None):
message = Messages.Message(message_id) message = Messages.Message(message_id)
if not message.exists(): if not message.exists():
return {"status": "error", "reason": "Unknown uuid"}, 404 return {"status": "error", "reason": "Unknown uuid"}, 404
meta = message.get_meta({'chat', 'content', 'files-names', 'forwarded_from', 'icon', 'images', 'language', 'link', 'parent', 'parent_meta', 'reactions', 'thread', 'translation', 'user-account'}, translation_target=translation_target) meta = message.get_meta({'chat', 'content', 'files-names', 'forwarded_from', 'icon', 'images', 'language', 'link', 'parent', 'parent_meta', 'qrcodes', 'reactions', 'thread', 'translation', 'user-account'}, translation_target=translation_target)
if 'forwarded_from' in meta: if 'forwarded_from' in meta:
chat = get_obj_chat_from_global_id(meta['forwarded_from']) chat = get_obj_chat_from_global_id(meta['forwarded_from'])
meta['forwarded_from'] = chat.get_meta({'icon'}) meta['forwarded_from'] = chat.get_meta({'icon'})
qrcodes = []
for q in meta['qrcodes']:
qr = Qrcode(q)
qrcodes.append({'id': qr.id, 'content': qr.get_content(), 'tags': qr.get_tags()})
meta['qrcodes'] = qrcodes
return meta, 200 return meta, 200
def api_message_detect_language(message_id): def api_message_detect_language(message_id):

View File

@ -151,6 +151,12 @@ class Message(AbstractObject):
images.append({'id': obj_id, 'ocr': self._get_image_ocr(obj_id)}) images.append({'id': obj_id, 'ocr': self._get_image_ocr(obj_id)})
return images return images
def get_qrcodes(self):
qrcodes = []
for c in self.get_correlation('qrcode').get('qrcode', []):
qrcodes.append(c[1:])
return qrcodes
def get_user_account(self, meta=False): def get_user_account(self, meta=False):
user_account = self.get_correlation('user-account') user_account = self.get_correlation('user-account')
if user_account.get('user-account'): if user_account.get('user-account'):
@ -300,6 +306,8 @@ class Message(AbstractObject):
meta['thread'] = thread meta['thread'] = thread
if 'images' in options: if 'images' in options:
meta['images'] = self.get_images() meta['images'] = self.get_images()
if 'qrcodes' in options:
meta['qrcodes'] = self.get_qrcodes()
if 'files-names' in options: if 'files-names' in options:
meta['files-names'] = self.get_files_names() meta['files-names'] = self.get_files_names()
if 'reactions' in options: if 'reactions' in options:

View File

@ -226,7 +226,7 @@ class AbstractChatObject(AbstractSubtypeObject, ABC):
def get_message_meta(self, message, timestamp=None, translation_target='', options=None): # TODO handle file message def get_message_meta(self, message, timestamp=None, translation_target='', options=None): # TODO handle file message
message = Messages.Message(message[9:]) message = Messages.Message(message[9:])
if not options: if not options:
options = {'content', 'files-names', 'forwarded_from', 'images', 'language', 'link', 'parent', 'parent_meta', 'reactions', 'thread', 'translation', 'user-account'} options = {'content', 'files-names', 'forwarded_from', 'images', 'language', 'link', 'parent', 'parent_meta', 'qrcodes', 'reactions', 'thread', 'translation', 'user-account'}
meta = message.get_meta(options=options, timestamp=timestamp, translation_target=translation_target) meta = message.get_meta(options=options, timestamp=timestamp, translation_target=translation_target)
return meta return meta

View File

@ -80,7 +80,7 @@ def objects_qrcodes_range_json():
return jsonify(QrCodes.Qrcodes().api_get_chart_nb_by_daterange(date_from, date_to)) return jsonify(QrCodes.Qrcodes().api_get_chart_nb_by_daterange(date_from, date_to))
@objects_qrcode.route("/objects/qrcodes", methods=['GET']) @objects_qrcode.route("/objects/qrcode", methods=['GET'])
@login_required @login_required
@login_read_only @login_read_only
def object_qrcode(): def object_qrcode():
@ -90,11 +90,9 @@ def object_qrcode():
return create_json_response(meta[0], meta[1]) return create_json_response(meta[0], meta[1])
else: else:
meta = meta[0] meta = meta[0]
languages = Language.get_translation_languages()
return render_template("ShowQrcode.html", meta=meta, return render_template("ShowQrcode.html", meta=meta,
bootstrap_label=bootstrap_label, bootstrap_label=bootstrap_label,
ail_tags=Tag.get_modal_add_tags(meta['id'], meta['type'], meta['subtype']), ail_tags=Tag.get_modal_add_tags(meta['id'], meta['type'], meta['subtype']))
translation_languages=languages, translation_target=target)
# ============= ROUTES ============== # ============= ROUTES ==============

View File

@ -97,6 +97,21 @@
<a class="btn btn-info" target="_blank" href="{{ url_for('objects_ocr.object_ocr', id=message_image['id'])}}"><i class="fas fa-expand"></i> OCR</a> <a class="btn btn-info" target="_blank" href="{{ url_for('objects_ocr.object_ocr', id=message_image['id'])}}"><i class="fas fa-expand"></i> OCR</a>
</span> </span>
{% endif %} {% endif %}
{% if message['qrcodes'] %}
{% for qrcode in message['qrcodes'] %}
<span>
<a class="btn btn-info" target="_blank" href="{{ url_for('correlation.show_correlation', type='qrcode', id=qrcode['id'])}}" style="max-width: 49%">
<i class="fas fa-qrcode fa-lg"></i> {{ qrcode['content'] }}
<div>
{% for tag in qrcode['tags'] %}
<span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }}">{{ tag }}</span>
{% endfor %}
</div>
</a>
</span>
{% endfor %}
{% endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% if message['files-names'] %} {% if message['files-names'] %}

View File

@ -15,7 +15,8 @@
<div class="card my-1"> <div class="card my-1">
<div class="card-header"> <div class="card-header">
<h4 class="text-secondary">{{ meta["id"] }} :</h4> <small>{{ meta["id"] }} :</small>
<div class="py-1 my-1 bg-white">{{ meta["content"] }}</div>
<ul class="list-group mb-2"> <ul class="list-group mb-2">
<li class="list-group-item py-0"> <li class="list-group-item py-0">
<table class="table"> <table class="table">