added downloadFile util
This commit is contained in:
parent
571a3c734b
commit
10efcaddb4
|
@ -7,16 +7,15 @@ import {
|
||||||
addToFavorites,
|
addToFavorites,
|
||||||
removeFromFavorites,
|
removeFromFavorites,
|
||||||
} from 'services/collectionService';
|
} from 'services/collectionService';
|
||||||
import { File, FILE_TYPE } from 'services/fileService';
|
import { File } from 'services/fileService';
|
||||||
import constants from 'utils/strings/constants';
|
import constants from 'utils/strings/constants';
|
||||||
import DownloadManger from 'services/downloadManager';
|
|
||||||
import exifr from 'exifr';
|
import exifr from 'exifr';
|
||||||
import Modal from 'react-bootstrap/Modal';
|
import Modal from 'react-bootstrap/Modal';
|
||||||
import Button from 'react-bootstrap/Button';
|
import Button from 'react-bootstrap/Button';
|
||||||
import Form from 'react-bootstrap/Form';
|
import Form from 'react-bootstrap/Form';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import events from './events';
|
import events from './events';
|
||||||
import { fileNameWithoutExtension, formatDateTime } from 'utils/file';
|
import { downloadFile, formatDateTime } from 'utils/file';
|
||||||
import { FormCheck } from 'react-bootstrap';
|
import { FormCheck } from 'react-bootstrap';
|
||||||
import { prettyPrintExif } from 'utils/exif';
|
import { prettyPrintExif } from 'utils/exif';
|
||||||
|
|
||||||
|
@ -296,21 +295,11 @@ function PhotoSwipe(props: Iprops) {
|
||||||
setShowInfo(true);
|
setShowInfo(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const downloadFile = async (file) => {
|
const downloadFileHelper = async (file) => {
|
||||||
const { loadingBar } = props;
|
const { loadingBar } = props;
|
||||||
const a = document.createElement('a');
|
|
||||||
a.style.display = 'none';
|
|
||||||
loadingBar.current.continuousStart();
|
loadingBar.current.continuousStart();
|
||||||
a.href = await DownloadManger.getFile(file);
|
await downloadFile(file);
|
||||||
loadingBar.current.complete();
|
loadingBar.current.complete();
|
||||||
if (file.metadata.fileType === FILE_TYPE.LIVE_PHOTO) {
|
|
||||||
a.download = fileNameWithoutExtension(file.metadata.title) + '.zip';
|
|
||||||
} else {
|
|
||||||
a.download = file.metadata.title;
|
|
||||||
}
|
|
||||||
document.body.appendChild(a);
|
|
||||||
a.click();
|
|
||||||
a.remove();
|
|
||||||
};
|
};
|
||||||
const { id } = props;
|
const { id } = props;
|
||||||
let { className } = props;
|
let { className } = props;
|
||||||
|
@ -344,7 +333,7 @@ function PhotoSwipe(props: Iprops) {
|
||||||
className="pswp-custom download-btn"
|
className="pswp-custom download-btn"
|
||||||
title={constants.DOWNLOAD}
|
title={constants.DOWNLOAD}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
downloadFile(photoSwipe.currItem)
|
downloadFileHelper(photoSwipe.currItem)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import {
|
||||||
import { decodeMotionPhoto } from 'services/motionPhotoService';
|
import { decodeMotionPhoto } from 'services/motionPhotoService';
|
||||||
import { getMimeTypeFromBlob } from 'services/upload/readFileService';
|
import { getMimeTypeFromBlob } from 'services/upload/readFileService';
|
||||||
import { EncryptionResult } from 'services/upload/uploadService';
|
import { EncryptionResult } from 'services/upload/uploadService';
|
||||||
|
import DownloadManger from 'services/downloadManager';
|
||||||
import { logError } from 'utils/sentry';
|
import { logError } from 'utils/sentry';
|
||||||
import { User } from 'services/userService';
|
import { User } from 'services/userService';
|
||||||
import CryptoWorker from 'utils/crypto';
|
import CryptoWorker from 'utils/crypto';
|
||||||
|
@ -36,6 +37,20 @@ export function downloadAsFile(filename: string, content: string) {
|
||||||
a.remove();
|
a.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function downloadFile(file) {
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.style.display = 'none';
|
||||||
|
a.href = await DownloadManger.getFile(file);
|
||||||
|
if (file.metadata.fileType === FILE_TYPE.LIVE_PHOTO) {
|
||||||
|
a.download = fileNameWithoutExtension(file.metadata.title) + '.zip';
|
||||||
|
} else {
|
||||||
|
a.download = file.metadata.title;
|
||||||
|
}
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
}
|
||||||
|
|
||||||
export function fileIsHEIC(mimeType: string) {
|
export function fileIsHEIC(mimeType: string) {
|
||||||
return (
|
return (
|
||||||
mimeType.toLowerCase().endsWith(TYPE_HEIC) ||
|
mimeType.toLowerCase().endsWith(TYPE_HEIC) ||
|
||||||
|
|
Loading…
Reference in a new issue