Merge pull request #743 from ente-io/clear-object-urls-after-use
Clear object urls after use
This commit is contained in:
commit
3c028f5655
|
@ -62,8 +62,7 @@ export async function updateFileCreationDateInEXIF(
|
||||||
updatedDate: Date
|
updatedDate: Date
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const fileURL = URL.createObjectURL(fileBlob);
|
let imageDataURL = await convertImageToDataURL(reader, fileBlob);
|
||||||
let imageDataURL = await convertImageToDataURL(reader, fileURL);
|
|
||||||
imageDataURL =
|
imageDataURL =
|
||||||
'data:image/jpeg;base64' +
|
'data:image/jpeg;base64' +
|
||||||
imageDataURL.slice(imageDataURL.indexOf(','));
|
imageDataURL.slice(imageDataURL.indexOf(','));
|
||||||
|
@ -83,8 +82,7 @@ export async function updateFileCreationDateInEXIF(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function convertImageToDataURL(reader: FileReader, url: string) {
|
async function convertImageToDataURL(reader: FileReader, blob: Blob) {
|
||||||
const blob = await fetch(url).then((r) => r.blob());
|
|
||||||
const dataURL = await new Promise<string>((resolve) => {
|
const dataURL = await new Promise<string>((resolve) => {
|
||||||
reader.onload = () => resolve(reader.result as string);
|
reader.onload = () => resolve(reader.result as string);
|
||||||
reader.readAsDataURL(blob);
|
reader.readAsDataURL(blob);
|
||||||
|
|
|
@ -117,6 +117,7 @@ export async function generateImageThumbnail(file: File, isHEIC: boolean) {
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
image.onload = () => {
|
image.onload = () => {
|
||||||
try {
|
try {
|
||||||
|
URL.revokeObjectURL(imageURL);
|
||||||
const imageDimension = {
|
const imageDimension = {
|
||||||
width: image.width,
|
width: image.width,
|
||||||
height: image.height,
|
height: image.height,
|
||||||
|
@ -165,6 +166,7 @@ export async function generateVideoThumbnail(file: File) {
|
||||||
videoURL = URL.createObjectURL(file);
|
videoURL = URL.createObjectURL(file);
|
||||||
video.addEventListener('loadeddata', function () {
|
video.addEventListener('loadeddata', function () {
|
||||||
try {
|
try {
|
||||||
|
URL.revokeObjectURL(videoURL);
|
||||||
if (!video) {
|
if (!video) {
|
||||||
throw Error('video load failed');
|
throw Error('video load failed');
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,16 +32,8 @@ export function downloadAsFile(filename: string, content: string) {
|
||||||
const file = new Blob([content], {
|
const file = new Blob([content], {
|
||||||
type: 'text/plain',
|
type: 'text/plain',
|
||||||
});
|
});
|
||||||
const a = document.createElement('a');
|
const fileURL = URL.createObjectURL(file);
|
||||||
a.href = URL.createObjectURL(file);
|
downloadUsingAnchor(fileURL, filename);
|
||||||
a.download = filename;
|
|
||||||
|
|
||||||
a.style.display = 'none';
|
|
||||||
document.body.appendChild(a);
|
|
||||||
|
|
||||||
a.click();
|
|
||||||
|
|
||||||
a.remove();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadFile(
|
export async function downloadFile(
|
||||||
|
@ -116,10 +108,6 @@ export async function downloadFile(
|
||||||
tempURL = URL.createObjectURL(fileBlob);
|
tempURL = URL.createObjectURL(fileBlob);
|
||||||
downloadUsingAnchor(tempURL, file.metadata.title);
|
downloadUsingAnchor(tempURL, file.metadata.title);
|
||||||
}
|
}
|
||||||
|
|
||||||
tempURL && URL.revokeObjectURL(tempURL);
|
|
||||||
tempImageURL && URL.revokeObjectURL(tempImageURL);
|
|
||||||
tempVideoURL && URL.revokeObjectURL(tempVideoURL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function downloadUsingAnchor(link: string, name: string) {
|
function downloadUsingAnchor(link: string, name: string) {
|
||||||
|
@ -129,6 +117,7 @@ function downloadUsingAnchor(link: string, name: string) {
|
||||||
a.download = name;
|
a.download = name;
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
|
URL.revokeObjectURL(link);
|
||||||
a.remove();
|
a.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue