mirror of
https://github.com/leoherzog/TorrentParts.git
synced 2026-01-24 04:08:04 -08:00
Add Drag-and-Drop Torrent File Support
This commit is contained in:
@@ -23810,11 +23810,10 @@ function parseTorrent (torrentId) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTorrentRemote (torrentId, opts, cb) {
|
function parseTorrentRemote (torrentId, cb) {
|
||||||
if (typeof opts === 'function') return parseTorrentRemote(torrentId, {}, opts)
|
let parsedTorrent
|
||||||
if (typeof cb !== 'function') throw new Error('second argument must be a Function')
|
if (typeof cb !== 'function') throw new Error('second argument must be a Function')
|
||||||
|
|
||||||
let parsedTorrent
|
|
||||||
try {
|
try {
|
||||||
parsedTorrent = parseTorrent(torrentId)
|
parsedTorrent = parseTorrent(torrentId)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -23833,12 +23832,11 @@ function parseTorrentRemote (torrentId, opts, cb) {
|
|||||||
})
|
})
|
||||||
} else if (typeof get === 'function' && /^https?:/.test(torrentId)) {
|
} else if (typeof get === 'function' && /^https?:/.test(torrentId)) {
|
||||||
// http, or https url to torrent file
|
// http, or https url to torrent file
|
||||||
opts = Object.assign({
|
get.concat({
|
||||||
url: torrentId,
|
url: torrentId,
|
||||||
timeout: 30 * 1000,
|
timeout: 30 * 1000,
|
||||||
headers: { 'user-agent': 'WebTorrent (https://webtorrent.io)' }
|
headers: { 'user-agent': 'WebTorrent (https://webtorrent.io)' }
|
||||||
}, opts)
|
}, (err, res, torrentBuf) => {
|
||||||
get.concat(opts, (err, res, torrentBuf) => {
|
|
||||||
if (err) return cb(new Error(`Error downloading torrent: ${err.message}`))
|
if (err) return cb(new Error(`Error downloading torrent: ${err.message}`))
|
||||||
parseOrThrow(torrentBuf)
|
parseOrThrow(torrentBuf)
|
||||||
})
|
})
|
||||||
@@ -37957,6 +37955,7 @@ document.addEventListener('DOMContentLoaded', start);
|
|||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
|
|
||||||
|
// magnet input
|
||||||
document.getElementById('magnet').addEventListener('keyup', function(event) {
|
document.getElementById('magnet').addEventListener('keyup', function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (event.key === "Enter") {
|
if (event.key === "Enter") {
|
||||||
@@ -37967,6 +37966,7 @@ function start() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// torrent select button
|
||||||
document.getElementById('torrent').addEventListener('change', function(event) {
|
document.getElementById('torrent').addEventListener('change', function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.target.files[0].arrayBuffer().then(function(arrayBuffer) {
|
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) {
|
example1.addEventListener('click', function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
notyf.success("Parsing Ubuntu 20.04 Magnet URL");
|
notyf.success("Parsing Ubuntu 20.04 Magnet URL");
|
||||||
@@ -37997,6 +38013,7 @@ function start() {
|
|||||||
parse(Buffer.from(arrayBuffer));
|
parse(Buffer.from(arrayBuffer));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// share buttons
|
||||||
let copyurl = new clipboard('#copyURL');
|
let copyurl = new clipboard('#copyURL');
|
||||||
copyurl.on('success', function(e) {
|
copyurl.on('success', function(e) {
|
||||||
notyf.success('Copied site URL to clipboard!');
|
notyf.success('Copied site URL to clipboard!');
|
||||||
@@ -38024,6 +38041,7 @@ function start() {
|
|||||||
console.warn(e);
|
console.warn(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// details field listeners
|
||||||
name.addEventListener('input', propertyChange);
|
name.addEventListener('input', propertyChange);
|
||||||
name.addEventListener('change', propertyChange);
|
name.addEventListener('change', propertyChange);
|
||||||
name.addEventListener('reset', propertyChange);
|
name.addEventListener('reset', propertyChange);
|
||||||
|
|||||||
4
bin/bundle.min.js
vendored
4
bin/bundle.min.js
vendored
File diff suppressed because one or more lines are too long
24
package.json
24
package.json
@@ -4,20 +4,20 @@
|
|||||||
"description": "📑 A website to inspect and edit Torrent files and Magnet URLs",
|
"description": "📑 A website to inspect and edit Torrent files and Magnet URLs",
|
||||||
"main": "bin/bundle.js",
|
"main": "bin/bundle.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"browserify": "latest",
|
"browserify": "^17.0.0",
|
||||||
"Buffer": "latest",
|
"bytes": "^3.1.0",
|
||||||
"bytes": "latest",
|
"clipboard": "^2.0.6",
|
||||||
"clipboard": "latest",
|
"mime-types": "^2.1.27",
|
||||||
"dropzone": "latest",
|
"parse-torrent": "^9.0.0",
|
||||||
"mime-types": "latest",
|
"tippy.js": "^6.2.7",
|
||||||
"parse-torrent": "latest",
|
"webtorrent": "^0.110.1"
|
||||||
"tippy.js": "latest",
|
|
||||||
"webtorrent": "latest"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"notyf": "latest",
|
"buffer": "^5.2.1",
|
||||||
"terser": "latest",
|
"Buffer": "^0.0.0",
|
||||||
"watchify": "latest"
|
"notyf": "^3.9.0",
|
||||||
|
"terser": "^5.3.8",
|
||||||
|
"watchify": "^3.11.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"watch": "watchify src/parse.js -o bin/bundle.js",
|
"watch": "watchify src/parse.js -o bin/bundle.js",
|
||||||
|
|||||||
20
src/parse.js
20
src/parse.js
@@ -79,6 +79,7 @@ document.addEventListener('DOMContentLoaded', start);
|
|||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
|
|
||||||
|
// magnet input
|
||||||
document.getElementById('magnet').addEventListener('keyup', function(event) {
|
document.getElementById('magnet').addEventListener('keyup', function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (event.key === "Enter") {
|
if (event.key === "Enter") {
|
||||||
@@ -89,6 +90,7 @@ function start() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// torrent select button
|
||||||
document.getElementById('torrent').addEventListener('change', function(event) {
|
document.getElementById('torrent').addEventListener('change', function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.target.files[0].arrayBuffer().then(function(arrayBuffer) {
|
event.target.files[0].arrayBuffer().then(function(arrayBuffer) {
|
||||||
@@ -99,6 +101,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) {
|
example1.addEventListener('click', function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
notyf.success("Parsing Ubuntu 20.04 Magnet URL");
|
notyf.success("Parsing Ubuntu 20.04 Magnet URL");
|
||||||
@@ -119,6 +137,7 @@ function start() {
|
|||||||
parse(Buffer.from(arrayBuffer));
|
parse(Buffer.from(arrayBuffer));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// share buttons
|
||||||
let copyurl = new clipboard('#copyURL');
|
let copyurl = new clipboard('#copyURL');
|
||||||
copyurl.on('success', function(e) {
|
copyurl.on('success', function(e) {
|
||||||
notyf.success('Copied site URL to clipboard!');
|
notyf.success('Copied site URL to clipboard!');
|
||||||
@@ -146,6 +165,7 @@ function start() {
|
|||||||
console.warn(e);
|
console.warn(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// details field listeners
|
||||||
name.addEventListener('input', propertyChange);
|
name.addEventListener('input', propertyChange);
|
||||||
name.addEventListener('change', propertyChange);
|
name.addEventListener('change', propertyChange);
|
||||||
name.addEventListener('reset', propertyChange);
|
name.addEventListener('reset', propertyChange);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user