import { getDetailFile, getDetailEncryptedFile } from "@eueno/lib-browser";
import { useDispatch, useSelector } from "react-redux";
const dispatch = useDispatch();
const getFile = async (id, token) => {
try {
const fileDetail = await getDetailFile(id);
if (!fileDetail) {
return console.error("File not found");
}
let bufferData;
if (fileDetail.encryptKey) {
bufferData = await getDetailEncryptedFile(
fileDetail.torrentUrl,
fileDetail.encryptKey,
token,
isShare: false,
[fileDetail.url, fileDetail.backupUrl],
account,
(torrent, remaining) => {
dispatch(
setTorrentInfo({
download: torrent.downloadSpeed,
upload: torrent.uploadSpeed,
remain: remaining,
})
);
}
);
}
} catch (error) {
console.log(error);
}
};