useEffect(() => {
console.log('useEffect strated')
if (location.state && location.state.apk) {
updSpinner(true);
const fileUploaded = usePassFile(location.state.package, location.state.apk);
console.log('fileUploaded', fileUploaded)
const fileName = fileUploaded.name;
const appSize = setCorrectSize(fileUploaded.size);
const formData = new FormData();
formData.append('file', fileUploaded);
try {
const res = async () => await axios({
method: 'post',
url: 'api/admin/parse',
data: formData,
headers: {'Content-Type': 'multipart/form-data'},
});
console.log(res)
getAnalyzedAppData(res.data, appSize, fileName, fileUploaded, false);
updSpinner(false);
} catch (error) {
console.log(error);
updSpinner(false);
}
}
}, []);
const usePassFile = async (name, url) => {
console.log('usePassFile')
try {
const blob = (await fetch(apkURL(url)).catch(e=>console.error(e))).blob();
console.log('blob', blob)
const dt = new DataTransfer();
dt.items.add(new File([blob], name, {type: blob.type}));
console.log('passed successfully:', dt);
return dt.items[0]
} catch (err) {
console.error('the file wasn\'t passed:');
console.error(err);
}
};