35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
import { useSession } from 'src/composables/useSession';
|
|
import { getUrl } from './getUrl';
|
|
import axios from 'axios';
|
|
import { exportFile } from 'quasar';
|
|
|
|
const { getTokenMultimedia } = useSession();
|
|
const token = getTokenMultimedia();
|
|
const appUrl = (await getUrl('', 'lilium')).replace('/#/', '');
|
|
|
|
export async function downloadFile(id, model = 'dms', urlPath = '/downloadFile', url) {
|
|
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 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);
|
|
}
|