1
0
mirror of https://github.com/SomboChea/ui synced 2026-01-19 01:25:51 +07:00

refactor: add download file method

This commit is contained in:
Juan Picado @jotadeveloper
2019-07-28 14:12:18 +02:00
parent 83b6a9d247
commit f47ab2490b
2 changed files with 21 additions and 2 deletions

View File

@@ -8,7 +8,7 @@ import Tooltip from '@material-ui/core/Tooltip';
import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/version/Version';
import { Fab, ActionListItem } from './styles';
import { isURL } from '../../utils/url';
import { isURL, extractFileName, downloadFile } from '../../utils/url';
import api from '../../utils/api';
export interface Action {
@@ -18,12 +18,14 @@ export interface Action {
}
async function downloadHandler(link: string): Promise<void> {
await api.request(link, 'GET', {
const fileStream: Blob = await api.request(link, 'GET', {
headers: {
['accept']: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
},
credentials: 'include',
});
const fileName = extractFileName(link);
downloadFile(fileStream, fileName);
}
const ACTIONS = {