vboxes fix

This commit is contained in:
2026-03-19 14:28:09 +01:00
parent b7f7c1f7c0
commit 06dfbfcbc4
30 changed files with 4405 additions and 166 deletions
+59
View File
@@ -0,0 +1,59 @@
import apiClient from './client'
import type {
LabelCreate,
LabelResponse,
LabelUpdate,
MessageBulkLabelRequest,
MessageBulkLabelResponse,
MessageLabelAddRequest,
MessageLabelRemoveRequest,
MessageLabelSetRequest,
} from '@/types/api.types'
export const labelsApi = {
// ─── CRUD Tag ─────────────────────────────────────────────────────────────
list: () =>
apiClient.get<LabelResponse[]>('/labels').then((r) => r.data),
create: (data: LabelCreate) =>
apiClient.post<LabelResponse>('/labels', data).then((r) => r.data),
update: (id: string, data: LabelUpdate) =>
apiClient.patch<LabelResponse>(`/labels/${id}`, data).then((r) => r.data),
delete: (id: string) =>
apiClient.delete(`/labels/${id}`).then((r) => r.data),
// ─── Tag su singolo messaggio ─────────────────────────────────────────────
getMessageLabels: (messageId: string) =>
apiClient
.get<LabelResponse[]>(`/messages/${messageId}/labels`)
.then((r) => r.data),
/** Sostituisce tutti i tag di un messaggio. */
setMessageLabels: (messageId: string, data: MessageLabelSetRequest) =>
apiClient
.put<LabelResponse[]>(`/messages/${messageId}/labels`, data)
.then((r) => r.data),
/** Aggiunge tag a un messaggio senza rimuovere quelli esistenti. */
addMessageLabels: (messageId: string, data: MessageLabelAddRequest) =>
apiClient
.post<LabelResponse[]>(`/messages/${messageId}/labels/add`, data)
.then((r) => r.data),
/** Rimuove specifici tag da un messaggio. */
removeMessageLabels: (messageId: string, data: MessageLabelRemoveRequest) =>
apiClient
.post<LabelResponse[]>(`/messages/${messageId}/labels/remove`, data)
.then((r) => r.data),
// ─── Bulk ─────────────────────────────────────────────────────────────────
bulkLabels: (data: MessageBulkLabelRequest) =>
apiClient
.post<MessageBulkLabelResponse>('/messages/bulk-labels', data)
.then((r) => r.data),
}
+19 -2
View File
@@ -69,8 +69,25 @@ export const messagesApi = {
getAttachments: (id: string) =>
apiClient.get<AttachmentResponse[]>(`/messages/${id}/attachments`).then((r) => r.data),
getAttachmentUrl: (messageId: string, attachmentId: string) =>
`/api/v1/messages/${messageId}/attachments/${attachmentId}/download`,
/**
* Scarica un allegato autenticato e lo salva localmente.
* Utilizza apiClient (con Bearer token) per evitare il 401 che si ottiene
* navigando direttamente verso l'URL con un <a href>.
*/
downloadAttachment: async (messageId: string, attachmentId: string, filename: string): Promise<void> => {
const response = await apiClient.get(
`/messages/${messageId}/attachments/${attachmentId}/download`,
{ responseType: 'blob' },
)
const blobUrl = window.URL.createObjectURL(new Blob([response.data]))
const anchor = document.createElement('a')
anchor.href = blobUrl
anchor.setAttribute('download', filename)
document.body.appendChild(anchor)
anchor.click()
anchor.remove()
window.URL.revokeObjectURL(blobUrl)
},
getReceipts: (id: string) =>
apiClient.get<MessageResponse[]>(`/messages/${id}/receipts`).then((r) => r.data),
+23
View File
@@ -12,10 +12,33 @@ export interface SendJobFilters {
status?: string
}
/** Payload esteso per l'invio multipart (include body_html) */
export interface SendPecMultipartRequest extends SendPecRequest {
body_html?: string
}
export const sendApi = {
/** Invio PEC semplice (JSON, senza allegati) retrocompatibile */
send: (data: SendPecRequest) =>
apiClient.post<SendJobResponse>('/send', data).then((r) => r.data),
/**
* Invio PEC con allegati tramite multipart/form-data.
*
* Il campo `data` viene serializzato come JSON string;
* i file vengono appesi come `attachments[]`.
*/
sendMultipart: (data: SendPecMultipartRequest, files: File[] = []) => {
const formData = new FormData()
formData.append('data', JSON.stringify(data))
files.forEach((file) => formData.append('attachments', file))
return apiClient
.post<SendJobResponse>('/send/multipart', formData, {
headers: { 'Content-Type': 'multipart/form-data' },
})
.then((r) => r.data)
},
listJobs: (filters: SendJobFilters = {}) =>
apiClient.get<SendJobListResponse>('/send/jobs', { params: filters }).then((r) => r.data),