fix: fetch files over browser rather than node

This commit is contained in:
ThaUnknown 2022-03-17 21:10:40 +01:00
parent dce49feee5
commit bb8d8c5ad5

View file

@ -38,24 +38,37 @@ client.on('torrent', torrent => {
files.set(torrent.files)
})
export function add (torrentID) {
export async function add (torrentID) {
if (torrentID) {
if (client.torrents.length) client.remove(client.torrents[0].infoHash)
files.set([])
page.set('player')
client.add(torrentID, {
private: set.torrentPeX,
path: set.torrentPath,
destroyStoreOnDestroy: !set.torrentPersist,
announce: [
'wss://tracker.openwebtorrent.com',
'wss://spacetradersapi-chatbox.herokuapp.com:443/announce',
'wss://peertube.cpy.re:443/tracker/socket'
]
})
if (typeof torrentID === 'string' && !torrentID.startsWith('magnet:')) {
const res = await fetch(torrentID)
const buffer = await res.arrayBuffer()
const file = new File([buffer], 'file.torrent', {
type: 'application/x-bittorrent'
})
addTorrent(file)
} else {
addTorrent(torrentID)
}
}
}
function addTorrent (id) {
client.add(id, {
private: set.torrentPeX,
path: set.torrentPath,
destroyStoreOnDestroy: !set.torrentPersist,
announce: [
'wss://tracker.openwebtorrent.com',
'wss://spacetradersapi-chatbox.herokuapp.com:443/announce',
'wss://peertube.cpy.re:443/tracker/socket'
]
})
}
client.on('torrent', torrent => {
console.log('ready', torrent.name)
const string = JSON.stringify(Array.from(torrent.torrentFile))