From 45899e457755eb58e61ec51b054f7b241db4f004 Mon Sep 17 00:00:00 2001 From: 0xCr0wbar <96867225+0xCr0wbar@users.noreply.github.com> Date: Mon, 15 Jun 2026 12:37:36 +0000 Subject: [PATCH] [#640][IMP] Enable image pasting in timeline description editor by moving 'handle_ed_paste' in 'case.common.js' --- ui/src/pages/case.common.js | 41 ++++++++++++++++++++++++++++++++- ui/src/pages/case.notes.js | 43 +---------------------------------- ui/src/pages/case.timeline.js | 7 ++++++ 3 files changed, 48 insertions(+), 43 deletions(-) diff --git a/ui/src/pages/case.common.js b/ui/src/pages/case.common.js index 10260e789..9e769f0e2 100644 --- a/ui/src/pages/case.common.js +++ b/ui/src/pages/case.common.js @@ -35,4 +35,43 @@ $(document).ready(function(){ collab_case = io.connect(); collab_case.emit('join-case-obj-notif', { 'channel': 'case-' + get_caseid() }); } -}); \ No newline at end of file +}); + +function handle_ed_paste(event, editor) { + let filename = null; + const { items } = event.originalEvent.clipboardData; + for (let i = 0; i < items.length; i += 1) { + const item = items[i]; + + if (item.kind === 'string') { + item.getAsString(function (s){ + filename = $.trim(s.replace(/\t|\n|\r/g, '')).substring(0, 40); + }); + } + + if (item.kind === 'file') { + const blob = item.getAsFile(); + + if (blob !== null) { + const reader = new FileReader(); + reader.onload = (e) => { + notify_success('The file is uploading in background. Don\'t leave the page'); + + if (filename === null) { + filename = random_filename(25); + } + + upload_interactive_data(e.target.result, filename, function(data){ + url = data.data.file_url + case_param(); + event.preventDefault(); + editor.insertSnippet(`\n![${filename}](${url} =100%x40%)\n`); + }); + + }; + reader.readAsDataURL(blob); + } else { + notify_error('Unsupported direct paste of this item. Use datastore to upload.'); + } + } + } +} \ No newline at end of file diff --git a/ui/src/pages/case.notes.js b/ui/src/pages/case.notes.js index cfd02f1ee..d87782f9e 100644 --- a/ui/src/pages/case.notes.js +++ b/ui/src/pages/case.notes.js @@ -451,7 +451,7 @@ async function note_detail(id) { ed_details.off('paste'); ed_details.on('paste', (event) => { event.preventDefault(); - handle_ed_paste(event); + handle_ed_paste(event, note_editor); }); setSharedLink(id); @@ -1056,47 +1056,6 @@ function createDirectoryListItem(directory, directoryMap) { return listItem; } - -function handle_ed_paste(event) { - let filename = null; - const { items } = event.originalEvent.clipboardData; - for (let i = 0; i < items.length; i += 1) { - const item = items[i]; - - if (item.kind === 'string') { - item.getAsString(function (s){ - filename = $.trim(s.replace(/\t|\n|\r/g, '')).substring(0, 40); - }); - } - - if (item.kind === 'file') { - const blob = item.getAsFile(); - - if (blob !== null) { - const reader = new FileReader(); - reader.onload = (e) => { - notify_success('The file is uploading in background. Don\'t leave the page'); - - if (filename === null) { - filename = random_filename(25); - } - - upload_interactive_data(e.target.result, filename, function(data){ - url = data.data.file_url + case_param(); - event.preventDefault(); - note_editor.insertSnippet(`\n![${filename}](${url} =100%x40%)\n`); - }); - - }; - reader.readAsDataURL(blob); - } else { - notify_error('Unsupported direct paste of this item. Use datastore to upload.'); - } - } - } -} - - function note_interval_pinger() { if (new Date() - last_ping > 2000) { collaborator_socket.emit('ping-note', diff --git a/ui/src/pages/case.timeline.js b/ui/src/pages/case.timeline.js index 1320f15c3..e36de3d0e 100644 --- a/ui/src/pages/case.timeline.js +++ b/ui/src/pages/case.timeline.js @@ -107,6 +107,13 @@ function add_event(parent_event_id = null) { $('#modal_add_event').modal({ show: true }); $('#event_title').focus(); + let ed_event_description = $('#event_description'); + ed_event_description.off('paste'); + ed_event_description.on('paste', (event) => { + event.preventDefault(); + handle_ed_paste(event, g_event_desc_editor); + }); + }); }