Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ui/src/pages/case.notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,8 @@ function handle_ed_paste(event) {
notify_success('The file is uploading in background. Don\'t leave the page');

if (filename === null) {
filename = random_filename(25);
let ext = get_extension_from_mime(blob.type);
filename = random_filename(25) + '.' + ext;
}

upload_interactive_data(e.target.result, filename, function(data){
Expand Down
3 changes: 2 additions & 1 deletion ui/src/pages/case.summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ function handle_ed_paste(event) {
notify_success('The file is uploading in background. Don\'t leave the page');

if (filename === null) {
filename = random_filename(25);
let ext = get_extension_from_mime(blob.type);
filename = random_filename(25) + '.' + ext;
}

upload_interactive_data(e.target.result, filename, function(data){
Expand Down
29 changes: 29 additions & 0 deletions ui/src/pages/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,35 @@ function random_filename(length) {
return filename;
}

function get_extension_from_mime(mimeType) {
if (!mimeType || typeof mimeType !== 'string') return 'bin';

// Strip parameters (e.g., "image/png; charset=utf-8" -> "image/png") and normalize case
const cleanMime = mimeType.split(';')[0].trim().toLowerCase();

const mimeMap = {
'image/png': 'png',
'image/jpeg': 'jpg',
'image/gif': 'gif',
'image/webp': 'webp',
'image/avif': 'avif',
'image/svg+xml': 'svg',
'image/bmp': 'bmp',
'image/tiff': 'tiff',
'image/x-icon': 'ico',
'image/vnd.microsoft.icon': 'ico'
};

let ext = mimeMap[cleanMime];
if (!ext) {
// Fallback: extract substring after "/" and before any "+", e.g., "application/pdf" -> "pdf"
ext = (cleanMime.split('/')[1] || 'bin').split('+')[0];
}

// Ensure the extension only contains safe alphanumeric characters
return ext.replace(/[^a-z0-9]/g, '');
}

function createPagination(currentPage, totalPages, per_page, callback, paginationContainersNodes) {
const maxPagesToShow = 5;
const paginationContainers = $(paginationContainersNodes);
Expand Down