vboxes fix
This commit is contained in:
@@ -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),
|
||||
}
|
||||
@@ -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),
|
||||
|
||||
@@ -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),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user