Add Drag-and-Drop Torrent File Support

This commit is contained in:
Leo Herzog
2020-11-25 12:17:40 -06:00
parent 26bb58ff05
commit 6406bae502
5 changed files with 60 additions and 22 deletions

View File

@@ -23810,11 +23810,10 @@ function parseTorrent (torrentId) {
}
}
function parseTorrentRemote (torrentId, opts, cb) {
if (typeof opts === 'function') return parseTorrentRemote(torrentId, {}, opts)
function parseTorrentRemote (torrentId, cb) {
let parsedTorrent
if (typeof cb !== 'function') throw new Error('second argument must be a Function')
let parsedTorrent
try {
parsedTorrent = parseTorrent(torrentId)
} catch (err) {
@@ -23833,12 +23832,11 @@ function parseTorrentRemote (torrentId, opts, cb) {
})
} else if (typeof get === 'function' && /^https?:/.test(torrentId)) {
// http, or https url to torrent file
opts = Object.assign({
get.concat({
url: torrentId,
timeout: 30 * 1000,
headers: { 'user-agent': 'WebTorrent (https://webtorrent.io)' }
}, opts)
get.concat(opts, (err, res, torrentBuf) => {
}, (err, res, torrentBuf) => {
if (err) return cb(new Error(`Error downloading torrent: ${err.message}`))
parseOrThrow(torrentBuf)
})
@@ -37957,6 +37955,7 @@ document.addEventListener('DOMContentLoaded', start);
function start() {
// magnet input
document.getElementById('magnet').addEventListener('keyup', function(event) {
event.preventDefault();
if (event.key === "Enter") {
@@ -37967,6 +37966,7 @@ function start() {
}
});
// torrent select button
document.getElementById('torrent').addEventListener('change', function(event) {
event.preventDefault();
event.target.files[0].arrayBuffer().then(function(arrayBuffer) {
@@ -37977,6 +37977,22 @@ function start() {
});
});
// body drag-and-drop torrent file support
document.addEventListener('dragover', function(event) {
event.preventDefault();
});
document.addEventListener('drop', function(event) {
event.preventDefault();
event.dataTransfer.items[0].getAsFile().arrayBuffer().then(function(arrayBuffer) {
source = "torrent-file";
originalSourceIcon.innerHTML = '<span class="fad fa-file-alt fa-fw"></span>';
sourceTooltip.setContent("Currently loaded information sourced from Torrent file");
parse(Buffer.from(arrayBuffer));
});
});
// example buttons
example1.addEventListener('click', function(event) {
event.preventDefault();
notyf.success("Parsing Ubuntu 20.04 Magnet URL");
@@ -37997,6 +38013,7 @@ function start() {
parse(Buffer.from(arrayBuffer));
});
// share buttons
let copyurl = new clipboard('#copyURL');
copyurl.on('success', function(e) {
notyf.success('Copied site URL to clipboard!');
@@ -38024,6 +38041,7 @@ function start() {
console.warn(e);
});
// details field listeners
name.addEventListener('input', propertyChange);
name.addEventListener('change', propertyChange);
name.addEventListener('reset', propertyChange);