mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-10 00:28:22 +00:00
chg: [api] get chat/subchannel/thread messages
This commit is contained in:
parent
c22d2982fb
commit
ad039e4720
5 changed files with 42 additions and 10 deletions
|
@ -57,6 +57,8 @@ def get_object_all_subtypes(obj_type): # TODO Dynamic subtype
|
|||
return r_object.smembers(f'all_chat:subtypes')
|
||||
if obj_type == 'chat-subchannel':
|
||||
return r_object.smembers(f'all_chat-subchannel:subtypes')
|
||||
if obj_type == 'chat-thread':
|
||||
return r_object.smembers(f'all_chat-thread:subtypes')
|
||||
if obj_type == 'cryptocurrency':
|
||||
return ['bitcoin', 'bitcoin-cash', 'dash', 'ethereum', 'litecoin', 'monero', 'zcash']
|
||||
if obj_type == 'pgp':
|
||||
|
|
|
@ -420,7 +420,7 @@ def api_get_user_account(user_id, instance_uuid, translation_target=None):
|
|||
meta = user_account.get_meta({'chats', 'icon', 'info', 'subchannels', 'threads', 'translation', 'username', 'username_meta'}, translation_target=translation_target)
|
||||
return meta, 200
|
||||
|
||||
def api_download_chat(chat_id, subtype):
|
||||
def api_chat_messages(subtype, chat_id):
|
||||
chat = Chats.Chat(chat_id, subtype)
|
||||
if not chat.exists():
|
||||
return {"status": "error", "reason": "Unknown chat"}, 404
|
||||
|
@ -434,7 +434,7 @@ def api_download_chat(chat_id, subtype):
|
|||
meta['messages'], _, _ = chat.get_messages(nb=-1, options=options)
|
||||
return meta, 200
|
||||
|
||||
def api_download_subchannel(subchannel_id, subtype):
|
||||
def api_subchannel_messages(subtype, subchannel_id):
|
||||
subchannel = ChatSubChannels.ChatSubChannel(subchannel_id, subtype)
|
||||
if not subchannel.exists():
|
||||
return {"status": "error", "reason": "Unknown subchannel"}, 404
|
||||
|
@ -450,7 +450,7 @@ def api_download_subchannel(subchannel_id, subtype):
|
|||
meta['messages'], _, _ = subchannel.get_messages(nb=-1, options=options)
|
||||
return meta, 200
|
||||
|
||||
def api_download_thread(thread_id, subtype):
|
||||
def api_thread_messages(subtype, thread_id):
|
||||
thread = ChatThreads.ChatThread(thread_id, subtype)
|
||||
if not thread.exists():
|
||||
return {"status": "error", "reason": "Unknown thread"}, 404
|
||||
|
|
|
@ -128,12 +128,12 @@ def api_get_object(obj_type, obj_subtype, obj_id):
|
|||
if not is_valid_object_type(obj_type):
|
||||
return {'status': 'error', 'reason': 'Invalid object type'}, 400
|
||||
if obj_subtype:
|
||||
if not is_valid_object_subtype(obj_type, subtype):
|
||||
if not is_valid_object_subtype(obj_type, obj_subtype):
|
||||
return {'status': 'error', 'reason': 'Invalid object subtype'}, 400
|
||||
obj = get_object(obj_type, obj_subtype, obj_id)
|
||||
if not obj.exists():
|
||||
return {'status': 'error', 'reason': 'Object Not Found'}, 404
|
||||
options = {'chat', 'content', 'files-names', 'images', 'parent', 'parent_meta', 'reactions', 'thread', 'user-account'}
|
||||
options = {'chat', 'content', 'created_at', 'files-names', 'icon', 'images', 'info', 'nb_participants', 'parent', 'parent_meta', 'reactions', 'thread', 'user-account', 'username', 'subchannels', 'threads'}
|
||||
return obj.get_meta(options=options), 200
|
||||
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ from lib import ail_api
|
|||
from lib import ail_core
|
||||
from lib import ail_updates
|
||||
from lib import crawlers
|
||||
from lib import chats_viewer
|
||||
|
||||
from lib import Investigations
|
||||
from lib import Tag
|
||||
|
@ -179,18 +180,46 @@ def v1_object_type_id(object_type, object_id):
|
|||
r = ail_objects.api_get_object_type_id(object_type, object_id)
|
||||
return create_json_response(r[0], r[1])
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# # # # # # # # # # # # # # # CHATS # # # # # # # # # # # # # # # # # # #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
@api_rest.route("api/v1/chat/messages", methods=['GET'])
|
||||
@token_required('analyst')
|
||||
def objects_chat_messages():
|
||||
obj_subtype = request.args.get('subtype')
|
||||
obj_id = request.args.get('id')
|
||||
r = chats_viewer.api_chat_messages(obj_subtype, obj_id)
|
||||
return create_json_response(r[0], r[1])
|
||||
|
||||
@api_rest.route("api/v1/chat-subchannel/messages", methods=['GET'])
|
||||
@token_required('analyst')
|
||||
def objects_chat_subchannel_messages():
|
||||
obj_subtype = request.args.get('subtype')
|
||||
obj_id = request.args.get('id')
|
||||
r = chats_viewer.api_subchannel_messages(obj_subtype, obj_id)
|
||||
return create_json_response(r[0], r[1])
|
||||
|
||||
@api_rest.route("api/v1/chat-thread/messages", methods=['GET'])
|
||||
@token_required('analyst')
|
||||
def objects_chat_thread_messages():
|
||||
obj_subtype = request.args.get('subtype')
|
||||
obj_id = request.args.get('id')
|
||||
r = chats_viewer.api_thread_messages(obj_subtype, obj_id)
|
||||
return create_json_response(r[0], r[1])
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# # # # # # # # # # # # # # # TITLES # # # # # # # # # # # # # # # # # # # TODO TO REVIEW
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
@api_rest.route("api/v1/titles/download", methods=['GET'])
|
||||
@api_rest.route("api/v1/titles/download", methods=['GET']) # TODO RENAME ->api/v1/titles/domains
|
||||
@token_required('analyst')
|
||||
def objects_titles_download():
|
||||
return create_json_response(Titles.Titles().get_contents_ids(), 200)
|
||||
|
||||
|
||||
# TODO
|
||||
@api_rest.route("api/v1/titles/download/unsafe", methods=['GET']) # TODO REFACTOR ME
|
||||
@api_rest.route("api/v1/titles/download/unsafe", methods=['GET']) # TODO RENAME ->api/v1/titles/domains/unsafe
|
||||
@token_required('analyst')
|
||||
def objects_titles_download_unsafe():
|
||||
all_titles = {}
|
||||
|
@ -212,6 +241,7 @@ def objects_titles_download_unsafe():
|
|||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# # # # # # # # # # # # # # # INVESTIGATIONS # # # # # # # # # # # # # # #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
@api_rest.route("api/v1/investigation/<investigation_uuid>", methods=['GET']) # TODO options
|
||||
@token_required('read_only')
|
||||
def v1_investigation(investigation_uuid):
|
||||
|
|
|
@ -165,7 +165,7 @@ def chats_explorer_chat_participants():
|
|||
def chats_explorer_chat_download():
|
||||
chat_id = request.args.get('id')
|
||||
chat_subtype = request.args.get('uuid')
|
||||
chat = chats_viewer.api_download_chat(chat_id, chat_subtype)
|
||||
chat = chats_viewer.api_chat_messages(chat_subtype, chat_id)
|
||||
if chat[1] != 200:
|
||||
if chat[1] == 404:
|
||||
abort(404)
|
||||
|
@ -180,7 +180,7 @@ def chats_explorer_chat_download():
|
|||
def objects_subchannel_messages_download():
|
||||
subchannel_id = request.args.get('id')
|
||||
instance_uuid = request.args.get('uuid')
|
||||
subchannel = chats_viewer.api_download_subchannel(subchannel_id, instance_uuid)
|
||||
subchannel = chats_viewer.api_subchannel_messages(instance_uuid, subchannel_id)
|
||||
if subchannel[1] != 200:
|
||||
return create_json_response(subchannel[0], subchannel[1])
|
||||
else:
|
||||
|
@ -193,7 +193,7 @@ def objects_subchannel_messages_download():
|
|||
def objects_thread_messages_download():
|
||||
thread_id = request.args.get('id')
|
||||
instance_uuid = request.args.get('uuid')
|
||||
thread = chats_viewer.api_download_thread(thread_id, instance_uuid)
|
||||
thread = chats_viewer.api_thread_messages(instance_uuid, thread_id)
|
||||
if thread[1] != 200:
|
||||
return create_json_response(thread[0], thread[1])
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue