mirror of
https://github.com/NoCrypt/migu.git
synced 2026-04-20 08:02:12 +00:00
fix: fetch files over browser rather than node
This commit is contained in:
parent
dce49feee5
commit
bb8d8c5ad5
1 changed files with 24 additions and 11 deletions
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Reference in a new issue