This commit is contained in:
parent
ad9063704c
commit
22daf36c6c
|
@ -2,25 +2,16 @@ import { useSession } from 'src/composables/useSession';
|
||||||
import { getUrl } from './getUrl';
|
import { getUrl } from './getUrl';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { exportFile } from 'quasar';
|
import { exportFile } from 'quasar';
|
||||||
import useOpenURL from './useOpenURL';
|
|
||||||
|
|
||||||
const { getTokenMultimedia } = useSession();
|
const { getTokenMultimedia } = useSession();
|
||||||
const token = getTokenMultimedia();
|
const token = getTokenMultimedia();
|
||||||
|
|
||||||
export async function downloadFile(
|
export async function downloadFile(id, model = 'dms', urlPath = '/downloadFile', url) {
|
||||||
id,
|
|
||||||
model = 'dms',
|
|
||||||
urlPath = '/downloadFile',
|
|
||||||
url,
|
|
||||||
newTab = true
|
|
||||||
) {
|
|
||||||
const appUrl = (await getUrl('', 'lilium')).replace('/#/', '');
|
const appUrl = (await getUrl('', 'lilium')).replace('/#/', '');
|
||||||
const targetUrl =
|
const response = await axios.get(
|
||||||
url ?? `${appUrl}/api/${model}/${id}${urlPath}?access_token=${token}`;
|
url ?? `${appUrl}/api/${model}/${id}${urlPath}?access_token=${token}`,
|
||||||
|
{ responseType: 'blob' }
|
||||||
if (newTab) return useOpenURL(targetUrl);
|
);
|
||||||
|
|
||||||
const response = await axios.get(targetUrl, { responseType: 'blob' });
|
|
||||||
|
|
||||||
const contentDisposition = response.headers['content-disposition'];
|
const contentDisposition = response.headers['content-disposition'];
|
||||||
const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(contentDisposition);
|
const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(contentDisposition);
|
||||||
|
|
Loading…
Reference in New Issue