refactor trash files
This commit is contained in:
parent
7c047f2306
commit
ddb37de58c
|
@ -159,7 +159,6 @@ export const trashFiles = async (filesToTrash: EnteFile[]) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentBatchSize = 0;
|
|
||||||
const trashBatch: TrashRequest = {
|
const trashBatch: TrashRequest = {
|
||||||
items: [],
|
items: [],
|
||||||
};
|
};
|
||||||
|
@ -169,30 +168,14 @@ export const trashFiles = async (filesToTrash: EnteFile[]) => {
|
||||||
collectionID: file.collectionID,
|
collectionID: file.collectionID,
|
||||||
fileID: file.id,
|
fileID: file.id,
|
||||||
});
|
});
|
||||||
currentBatchSize++;
|
if (trashBatch.items.length >= MAX_TRASH_BATCH_SIZE) {
|
||||||
if (currentBatchSize >= MAX_TRASH_BATCH_SIZE) {
|
await trashFilesFromServer(trashBatch, token);
|
||||||
await HTTPService.post(
|
|
||||||
`${ENDPOINT}/files/trash`,
|
|
||||||
trashBatch,
|
|
||||||
null,
|
|
||||||
{
|
|
||||||
'X-Auth-Token': token,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
currentBatchSize = 0;
|
|
||||||
trashBatch.items = [];
|
trashBatch.items = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentBatchSize > 0) {
|
if (trashBatch.items.length > 0) {
|
||||||
await HTTPService.post(
|
await trashFilesFromServer(trashBatch, token);
|
||||||
`${ENDPOINT}/files/trash`,
|
|
||||||
trashBatch,
|
|
||||||
null,
|
|
||||||
{
|
|
||||||
'X-Auth-Token': token,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logError(e, 'trash file failed');
|
logError(e, 'trash file failed');
|
||||||
|
@ -292,3 +275,9 @@ export const updatePublicMagicMetadata = async (files: EnteFile[]) => {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function trashFilesFromServer(trashBatch: TrashRequest, token: any) {
|
||||||
|
await HTTPService.post(`${ENDPOINT}/files/trash`, trashBatch, null, {
|
||||||
|
'X-Auth-Token': token,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue