diff --git a/config/packages/nelmio_cors.yaml b/config/packages/nelmio_cors.yaml index 7b20162..2717d60 100644 --- a/config/packages/nelmio_cors.yaml +++ b/config/packages/nelmio_cors.yaml @@ -5,7 +5,7 @@ nelmio_cors: allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE'] allow_headers: ['Content-Type', 'Authorization'] allow_credentials: true - expose_headers: ['Link'] + expose_headers: ['Link', 'Content-Disposition'] max_age: 3600 paths: '^/': null diff --git a/frontend/composables/useApi.ts b/frontend/composables/useApi.ts index fda5e47..94f57ec 100644 --- a/frontend/composables/useApi.ts +++ b/frontend/composables/useApi.ts @@ -4,9 +4,14 @@ import { useAuthStore } from '~/stores/auth' export type AnyObject = Record +export type BlobResponse = { + data: Blob + headers: Headers +} + export type ApiClient = { get(url: string, query?: AnyObject, options?: ApiFetchOptions<'json'>): Promise - getBlob(url: string, query?: AnyObject, options?: ApiFetchOptions<'blob'>): Promise + getBlob(url: string, query?: AnyObject, options?: ApiFetchOptions<'blob'>): Promise post(url: string, body?: AnyObject, options?: ApiFetchOptions<'json'>): Promise put(url: string, body?: AnyObject, options?: ApiFetchOptions<'json'>): Promise patch(url: string, body?: AnyObject, options?: ApiFetchOptions<'json'>): Promise @@ -165,7 +170,9 @@ export const useApi = (): ApiClient => { return request('GET', url, { ...options, query }) }, getBlob(url: string, query: AnyObject = {}, options: ApiFetchOptions<'blob'> = {}) { - return client(url, { ...options, method: 'GET', query, responseType: 'blob' }) + return client + .raw(url, { ...options, method: 'GET', query, responseType: 'blob' }) + .then((res) => ({ data: res._data as Blob, headers: res.headers })) }, post(url: string, body: AnyObject = {}, options: ApiFetchOptions<'json'> = {}) { return request('POST', url, { ...options, body }) diff --git a/frontend/composables/usePdfPrinter.ts b/frontend/composables/usePdfPrinter.ts index 7d68179..b60666d 100644 --- a/frontend/composables/usePdfPrinter.ts +++ b/frontend/composables/usePdfPrinter.ts @@ -4,16 +4,17 @@ export const usePdfPrinter = () => { const api = useApi() const printPdf = async (url: string): Promise => { - const blob = await api.getBlob(url); + const res = await api.getBlob(url); + const disposition = res.headers.get('content-disposition') || ''; + const match = disposition.match(/filename="(.+?)"/i); + const filename = match?.[1] ?? 'document.pdf'; - const pdfBlob = blob.type === 'application/pdf' - ? blob - : new Blob([blob], { type: 'application/pdf' }); + const pdfBlob = res.data.type === 'application/pdf' + ? res.data + : new Blob([res.data], { type: 'application/pdf' }); const blobUrl = URL.createObjectURL(pdfBlob); - const filename = `test.pdf`; - const a = document.createElement('a'); a.href = blobUrl; a.download = filename; diff --git a/frontend/pages/login.vue b/frontend/pages/login.vue index 0b57285..f2e0c37 100644 --- a/frontend/pages/login.vue +++ b/frontend/pages/login.vue @@ -63,7 +63,6 @@ const handleSubmit = async () => { isSubmitting.value = true try { - console.log(useRuntimeConfig().public.apiBase) await auth.login(username.value, password.value) await router.push('/') diff --git a/frontend/public/favicon.ico b/frontend/public/favicon.ico index 18993ad..0c9b311 100644 Binary files a/frontend/public/favicon.ico and b/frontend/public/favicon.ico differ diff --git a/src/State/AbsencePrintProvider.php b/src/State/AbsencePrintProvider.php index d78592e..fc481fd 100644 --- a/src/State/AbsencePrintProvider.php +++ b/src/State/AbsencePrintProvider.php @@ -78,7 +78,11 @@ class AbsencePrintProvider implements ProviderInterface $dompdf->setPaper('A3', 'landscape'); $dompdf->render(); - $filename = 'test'; + $filename = sprintf( + 'absences_du_%s_au_%s.pdf', + $fromDate->format('d-m-Y'), + $toDate->format('d-m-Y') + ); return new Response($dompdf->output(), Response::HTTP_OK, [ 'Content-Type' => 'application/pdf',