mirror of https://github.com/kiwix/libkiwix.git
Merge pull request #770 from kiwix/magnetLink
Use real magnet link in download modal
This commit is contained in:
commit
8dbf015689
|
@ -142,10 +142,21 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getMagnetLink(downloadLink) {
|
||||||
|
const magnetUrl = downloadLink + '.magnet';
|
||||||
|
const controller = new AbortController();
|
||||||
|
setTimeout(() => controller.abort(), 5000);
|
||||||
|
const magnetLink = await fetch(magnetUrl, { signal: controller.signal }).then(response => {
|
||||||
|
return response.ok ? response.text() : '';
|
||||||
|
}).catch((_error) => '');
|
||||||
|
return magnetLink;
|
||||||
|
}
|
||||||
|
|
||||||
function insertModal(button) {
|
function insertModal(button) {
|
||||||
const downloadLink = button.getAttribute('data-link');
|
const downloadLink = button.getAttribute('data-link');
|
||||||
button.addEventListener('click', (event) => {
|
button.addEventListener('click', async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
const magnetLink = await getMagnetLink(downloadLink);
|
||||||
document.body.insertAdjacentHTML('beforeend', `<div class="modal-wrapper">
|
document.body.insertAdjacentHTML('beforeend', `<div class="modal-wrapper">
|
||||||
<div class="modal">
|
<div class="modal">
|
||||||
<div class="modal-heading">
|
<div class="modal-heading">
|
||||||
|
@ -181,12 +192,13 @@
|
||||||
<div>Sha256 hash</div>
|
<div>Sha256 hash</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-regular-download">
|
${magnetLink ?
|
||||||
<a href="${downloadLink}.magnet" target="_blank">
|
`<div class="modal-regular-download">
|
||||||
|
<a href="${magnetLink}" target="_blank">
|
||||||
<img src="../skin/magnet.png?KIWIXCACHEID" alt="download magnet" />
|
<img src="../skin/magnet.png?KIWIXCACHEID" alt="download magnet" />
|
||||||
<div>Magnet link</div>
|
<div>Magnet link</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>` : ``}
|
||||||
<div class="modal-regular-download">
|
<div class="modal-regular-download">
|
||||||
<a href="${downloadLink}.torrent" download>
|
<a href="${downloadLink}.torrent" download>
|
||||||
<img src="../skin/bittorrent.png?KIWIXCACHEID" alt="download torrent" />
|
<img src="../skin/bittorrent.png?KIWIXCACHEID" alt="download torrent" />
|
||||||
|
|
|
@ -319,7 +319,7 @@ R"EXPECTEDRESULT( src="/ROOT/skin/jquery-ui/external/jquery/jquery.js?cache
|
||||||
src: url("/ROOT/skin/fonts/Roboto.ttf?cacheid=84d10248") format("truetype");
|
src: url("/ROOT/skin/fonts/Roboto.ttf?cacheid=84d10248") format("truetype");
|
||||||
<script src="/ROOT/skin/isotope.pkgd.min.js?cacheid=2e48d392" defer></script>
|
<script src="/ROOT/skin/isotope.pkgd.min.js?cacheid=2e48d392" defer></script>
|
||||||
<script src="/ROOT/skin/iso6391To3.js?cacheid=ecde2bb3"></script>
|
<script src="/ROOT/skin/iso6391To3.js?cacheid=ecde2bb3"></script>
|
||||||
<script type="text/javascript" src="/ROOT/skin/index.js?cacheid=0951f06f" defer></script>
|
<script type="text/javascript" src="/ROOT/skin/index.js?cacheid=c434aa35" defer></script>
|
||||||
)EXPECTEDRESULT"
|
)EXPECTEDRESULT"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue