Message attachments

This commit is contained in:
Zan
2026-01-15 17:56:40 +01:00
parent 3243ebdc2e
commit d44be3b029
3 changed files with 118 additions and 8 deletions

View File

@@ -525,7 +525,7 @@ body.modal-open {
} }
.message-info { .message-info {
background-color: var(--card-card); background-color: var(--button-secondaryFill);
padding: 15px; padding: 15px;
border-radius: 6px; border-radius: 6px;
margin-bottom: 20px; margin-bottom: 20px;
@@ -564,7 +564,7 @@ body.modal-open {
} }
.message-text { .message-text {
background-color: var(--card-card); background-color: var(--button-secondaryFill);
border-radius: 6px; border-radius: 6px;
padding: 15px; padding: 15px;
line-height: 1.6; line-height: 1.6;
@@ -591,14 +591,14 @@ body.modal-open {
} }
.message-attachments { .message-attachments {
background: #f9f9f9; background: var(--button-secondaryFill);
padding: 15px; padding: 15px;
border-radius: 6px; border-radius: 6px;
} }
.message-attachments h4 { .message-attachments h4 {
margin: 0 0 10px 0; margin: 0 0 10px 0;
color: #333; color: var(--text-secondary);
font-size: 1.1em; font-size: 1.1em;
} }

View File

@@ -327,8 +327,11 @@
const li = document.createElement('li'); const li = document.createElement('li');
const a = document.createElement('a'); const a = document.createElement('a');
a.href = '#'; a.href = '#';
a.textContent = sanitizeHTML(attachment.nev); a.textContent = sanitizeHTML(attachment.fajlNev || attachment.nev || 'Ismeretlen fájl');
a.onclick = () => downloadAttachment(attachment.azonosito); a.onclick = (e) => {
e.preventDefault();
downloadAttachment(attachment.azonosito, attachment.fajlNev || attachment.nev);
};
li.appendChild(a); li.appendChild(a);
attachList.appendChild(li); attachList.appendChild(li);
}); });
@@ -346,6 +349,32 @@
} }
document.body.classList.remove('modal-open'); document.body.classList.remove('modal-open');
} }
async function downloadAttachment(azonosito, fileName) {
try {
const response = await chrome.runtime.sendMessage({
action: 'download_attachment',
azonosito: azonosito,
fileName: fileName
});
if (response.success && response.data) {
const a = document.createElement('a');
a.href = response.data;
a.download = response.fileName || 'letoltes';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
} else {
console.error('Melléklet letöltési hiba:', response.error);
alert('Nem sikerült letölteni a mellékletet.');
}
} catch (error) {
console.error('Melléklet letöltési hiba:', error);
alert('Hiba történt a melléklet letöltése során.');
}
}
window.openMessageModal = openMessageModal; window.openMessageModal = openMessageModal;
window.closeMessageModal = closeMessageModal; window.closeMessageModal = closeMessageModal;

View File

@@ -34,6 +34,11 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
sendResponse({ success: true }); sendResponse({ success: true });
break; break;
case 'download_attachment':
const downloadResult = await handleDownloadAttachment(request.azonosito, request.fileName);
sendResponse(downloadResult);
break;
default: default:
console.warn('[Background] Unknown action:', request.action); console.warn('[Background] Unknown action:', request.action);
sendResponse({ success: false, error: 'Unknown action' }); sendResponse({ success: false, error: 'Unknown action' });
@@ -89,6 +94,82 @@ async function handleStorageClear() {
} }
} }
async function handleDownloadAttachment(azonosito, fileName) {
try {
const apiUrl = `https://eugyintezes.e-kreta.hu/api/v1/dokumentumok/uzenetek/${azonosito}`;
const redirectResponse = await fetch(apiUrl, {
method: 'GET',
credentials: 'include',
headers: {
'Accept': 'application/json, text/plain, */*',
'x-csrf': '1',
'x-uzenet-json-formatum': 'CamelCase',
'x-uzenet-lokalizacio': 'hu-HU',
'x-uzenet-verzio-szam': '1.2.3'
},
redirect: 'manual'
});
let fileUrl;
if (redirectResponse.type === 'opaqueredirect' || redirectResponse.status === 0) {
const followResponse = await fetch(apiUrl, {
method: 'GET',
credentials: 'include',
headers: {
'Accept': 'application/json, text/plain, */*',
'x-csrf': '1',
'x-uzenet-json-formatum': 'CamelCase',
'x-uzenet-lokalizacio': 'hu-HU',
'x-uzenet-verzio-szam': '1.2.3'
},
redirect: 'follow'
});
if (followResponse.ok) {
const blob = await followResponse.blob();
const base64 = await blobToBase64(blob);
return { success: true, data: base64, fileName: fileName };
}
} else if (redirectResponse.status === 302 || redirectResponse.status === 301) {
fileUrl = redirectResponse.headers.get('location');
}
if (fileUrl) {
const fileResponse = await fetch(fileUrl, {
method: 'GET',
headers: {
'Accept': 'application/json, text/plain, */*',
'x-csrf': '1',
'x-uzenet-json-formatum': 'CamelCase',
'x-uzenet-lokalizacio': 'hu-HU',
'x-uzenet-verzio-szam': '1.2.3'
}
});
if (fileResponse.ok) {
const blob = await fileResponse.blob();
const base64 = await blobToBase64(blob);
return { success: true, data: base64, fileName: fileName };
}
}
return { success: false, error: 'Nem sikerült letölteni a mellékletet.' };
} catch (error) {
console.error('[Background] Attachment download error:', error);
return { success: false, error: error.message };
}
}
function blobToBase64(blob) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result);
reader.onerror = reject;
reader.readAsDataURL(blob);
});
}
chrome.storage.onChanged.addListener((changes, namespace) => { chrome.storage.onChanged.addListener((changes, namespace) => {
if (namespace === 'sync') { if (namespace === 'sync') {
const firkaChanges = Object.keys(changes).filter(key => key.startsWith('firka_')); const firkaChanges = Object.keys(changes).filter(key => key.startsWith('firka_'));