import { useSession } from 'src/composables/useSession'; import { getUrl } from './getUrl'; import axios from 'axios'; import { exportFile } from 'quasar'; const { getTokenMultimedia } = useSession(); const token = getTokenMultimedia(); export async function downloadFile(id, model = 'dms', urlPath = '/downloadFile', url) { const appUrl = await getAppUrl(); const response = await axios.get( url ?? `${appUrl}/api/${model}/${id}${urlPath}?access_token=${token}`, { responseType: 'blob' }, ); download(response); } export async function downloadDocuware(url, params) { const appUrl = await getAppUrl(); const response = await axios.get(`${appUrl}/api/` + url, { responseType: 'blob', params, }); download(response); } function download(response) { const contentDisposition = response.headers['content-disposition']; const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(contentDisposition); const filename = matches?.[1] ? matches[1].replace(/['"]/g, '') : 'downloaded-file'; exportFile(filename, response.data); } async function getAppUrl() { return (await getUrl('', 'lilium')).replace('/#/', ''); }