improved fetch-from-blockchain layout
This commit is contained in:
parent
47e4baee15
commit
943f708a99
17
ip.js
17
ip.js
@ -4,17 +4,30 @@ var magnet = require('magnet-uri')
|
||||
var uri = 'magnet:?xt=urn:btih:4a7b842632ca42cdd3c8d54017a8da756839b84d&dn=D0112-Chacha.Choudhary.Sabu.Kaale.Tapu.Mein.pdf&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com'
|
||||
var parsed = magnet(uri)
|
||||
|
||||
console.log(parsed.infoHash) // 'e3811b9539cacff680e418124272177c47477157'
|
||||
//console.log(parsed.infoHash) // 'e3811b9539cacff680e418124272177c47477157'
|
||||
|
||||
var dht = new DHT()
|
||||
|
||||
dht.listen(20000, function () {
|
||||
console.log('now listening')
|
||||
//console.log(dht.address());
|
||||
})
|
||||
|
||||
dht.on('peer', function (peer, infoHash, from) {
|
||||
//console.log(peer);
|
||||
console.log(from);
|
||||
|
||||
console.log('found potential peer ' + peer.host + ':' + peer.port + ' through ' + from.address + ':' + from.port)
|
||||
})
|
||||
|
||||
// find peers for the given torrent info hash
|
||||
//find peers for the given torrent info hash
|
||||
dht.lookup(parsed.infoHash)
|
||||
|
||||
// dht.on('node', function (node) {
|
||||
// console.log(node);
|
||||
// })
|
||||
|
||||
// dht.on('announce', function (peer, infoHash) {
|
||||
// console.log(peer);
|
||||
// console.log(infoHash)
|
||||
// })
|
||||
|
||||
@ -66,3 +66,6 @@ footer {
|
||||
.pd-10 {
|
||||
padding: 10px 10px;
|
||||
}
|
||||
.mg-10 {
|
||||
margin: 10px 10px;
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
const client = require('../../server')
|
||||
const _ = require('lodash')
|
||||
var magnet = require('magnet-uri')
|
||||
|
||||
let getFloData = (tx) => {
|
||||
return new Promise((resolve, reject)=>{
|
||||
@ -11,7 +12,9 @@ let getFloData = (tx) => {
|
||||
}
|
||||
return res;
|
||||
}).then(response=>{
|
||||
return resolve(response.floData)
|
||||
var parsedTorrent = magnet(response.floData)
|
||||
let resp = [parsedTorrent.name, response.floData]
|
||||
return resolve(resp)
|
||||
})
|
||||
} catch (error) {
|
||||
return reject(error)
|
||||
|
||||
9
public/js/webtorrent.min.js
vendored
Normal file
9
public/js/webtorrent.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
33
routes.js
33
routes.js
@ -65,13 +65,30 @@ router.post('/download-magnetic-uri', (req, res)=>{
|
||||
var torrentId = params.torrentId
|
||||
|
||||
if (_.trim(torrentId) == '') {
|
||||
//alert("Please specify a magnetic url.");
|
||||
console.error("Empty torrent id");
|
||||
return;
|
||||
}
|
||||
|
||||
client.add(torrentId, function (torrent) {
|
||||
|
||||
//torrent.on('wire', (wire)=>{
|
||||
// console.log(wire);
|
||||
// console.log(wire._readableState.pipes.remoteAddress);
|
||||
// console.log(wire._readableState.pipes.remoteFamily);
|
||||
// console.log(wire._readableState.pipes.remotePort);
|
||||
// console.log(wire._readableState.pipes.localAddress);
|
||||
// console.log(wire._readableState.pipes.localPort);
|
||||
|
||||
//console.log(wire._readableState.pipes._pc);
|
||||
|
||||
|
||||
|
||||
// var id = wire.peerId.toString()
|
||||
// var addr = wire.remoteAddress
|
||||
// console.log(id);
|
||||
// console.log(addr);
|
||||
//})
|
||||
|
||||
var files = torrent.files
|
||||
var length = files.length
|
||||
// Stream each file to the disk
|
||||
@ -86,12 +103,6 @@ router.post('/download-magnetic-uri', (req, res)=>{
|
||||
source.on('end', function () {
|
||||
console.log('file:\t\t', file.name)
|
||||
|
||||
// Seed file
|
||||
client.seed(file, function (tor) {
|
||||
console.log(tor);
|
||||
console.log('Client is seeding ' + tor.magnetURI)
|
||||
})
|
||||
|
||||
res.json({file:file.name, location:fullpath})
|
||||
|
||||
// close after all files are saved
|
||||
@ -148,7 +159,7 @@ router.post('/send-to-blockchain', [
|
||||
return
|
||||
}
|
||||
|
||||
let toaddress = "oSjBiuTE1aFNBjaSGq6UNhU9ddpD2YXdg8";
|
||||
let toaddress = "oHyzdt8xW1A81qcZ5VcM25RbC6RVbynAg4";
|
||||
let amount = 1;
|
||||
|
||||
try {
|
||||
@ -225,7 +236,7 @@ router.post('/fetch-from-blockchain', [
|
||||
return tx_arr;
|
||||
|
||||
}).then(tx_arr=>{
|
||||
console.log(tx_arr);
|
||||
//console.log(tx_arr);
|
||||
let tor_arr = []
|
||||
for (const tx in tx_arr) {
|
||||
let promise = funcs.getFloData(_.trim(tx_arr[tx]))
|
||||
@ -239,8 +250,8 @@ router.post('/fetch-from-blockchain', [
|
||||
})
|
||||
return msg_arr
|
||||
}).then(flo_data=>{
|
||||
console.log(flo_data);
|
||||
res.json({error:false, msg:'floData fetching complete', data:flo_data})
|
||||
//console.log(flo_data);
|
||||
res.json({error:false, msg:'List of Torrent files:', data:flo_data})
|
||||
})
|
||||
}).catch(e=>{
|
||||
console.error(e)
|
||||
|
||||
38
search.js
Normal file
38
search.js
Normal file
@ -0,0 +1,38 @@
|
||||
// const postData = querystring.stringify({
|
||||
// 'msg': 'Hello World!'
|
||||
// });
|
||||
|
||||
const http = require('http')
|
||||
|
||||
const options = {
|
||||
//hostname: 'udp://tracker.opentrackr.org:1337?infohash=4a7b842632ca42cdd3c8d54017a8da756839b84d',
|
||||
hostname: 'http://torrent.ubuntu.com:6969/announce?info_hash=%9b%db%bbI%f0%85%a2%d1%5d%96%ac%fa%bf%f81%06%001O%e0&peer_id=ABCDABCDABCDABCDABCD&port=6882&downloaded=0&uploaded=0&left=0&event=started&compact=1',
|
||||
port: 80,
|
||||
//path: '/upload',
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
//'Content-Length': Buffer.byteLength(postData)
|
||||
}
|
||||
};
|
||||
|
||||
const req = http.request(options, (res) => {
|
||||
console.log(`STATUS: ${res.statusCode}`);
|
||||
console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', (chunk) => {
|
||||
console.log(`BODY: ${chunk}`);
|
||||
});
|
||||
res.on('end', () => {
|
||||
console.log('No more data in response.');
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (e) => {
|
||||
console.error(`problem with request: ${e.message}`);
|
||||
});
|
||||
|
||||
// write data to request body
|
||||
//req.write(postData);
|
||||
req.end();
|
||||
|
||||
@ -1,22 +1,29 @@
|
||||
<%include partials/header.ejs %>
|
||||
|
||||
<div class="container">
|
||||
<!-- duckdns-> oVrbkDUrX727MjQd4zq7nRw1XEHkkpGErE -->
|
||||
<label for="flo-addr">Enter the flo address (oSjBiuTE1aFNBjaSGq6UNhU9ddpD2YXdg8)</label>
|
||||
<input type="text" id="flo-addr" class="form-control" />
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<!-- duckdns-> oVrbkDUrX727MjQd4zq7nRw1XEHkkpGErE -->
|
||||
<label for="flo-addr">Enter the flo address (oHyzdt8xW1A81qcZ5VcM25RbC6RVbynAg4)</label>
|
||||
<input type="text" id="flo-addr" class="form-control" />
|
||||
|
||||
<p><button id="flo-addr-btn" class="btn btn-primary">Get Torrents List</button></p>
|
||||
<p><button id="flo-addr-btn" class="btn btn-primary">Get Torrents List</button></p>
|
||||
|
||||
<ul id="flo-res"></ul>
|
||||
<ul id="flo-res" class="list-group"></ul>
|
||||
|
||||
<label for="mag_text">Provide a magnetic URL below:</label>
|
||||
<textarea class="form-control" id="mag_text" rows="3"></textarea>
|
||||
<p><button id="dwn-seed" class="btn btn-primary">View</button></p>
|
||||
<label for="mag_text">Provide a magnetic URL below:</label>
|
||||
<p><button id="dwn-seed" class="btn btn-primary">View Torrent</button></p>
|
||||
</div>
|
||||
|
||||
<p id="dwld"></p>
|
||||
<div class="col-md-4">
|
||||
|
||||
<div class="pd-10">
|
||||
<div id="mag-res"></div>
|
||||
<div class="mt-2 mb-2">
|
||||
<p id="tmsg" class="text-info"></p>
|
||||
<p id="dwld"></p>
|
||||
<div id="mag-res"></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@ -38,23 +45,33 @@
|
||||
type: 'post',
|
||||
data: {job:job, floaddr:floaddr},
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
var t = '';
|
||||
if (response.msg.length>0) {
|
||||
t += `<li><h5 class="text-info">${response.msg}</h5></li>`;
|
||||
t += ``;
|
||||
t += `<li class="list-group-item list-group-item-light"><h5 class="text-info">${response.msg}</h5></li>`;
|
||||
}
|
||||
|
||||
if (response.error==false && typeof response.data != undefined) {
|
||||
for (let fd = 0; fd < response.data.length; fd++) {
|
||||
const fdata = response.data[fd];
|
||||
t += `<li><p>${fdata}</p></li>`;
|
||||
if (response.data[fd][0] != null && response.data[fd][1] != null) {
|
||||
const fdata = response.data[fd];
|
||||
|
||||
t += `<li class="list-group-item">`;
|
||||
t += `<div class="input-group">`;
|
||||
t += `<div class="input-group-prepend">`;
|
||||
t += `<div class="input-group-text">`;
|
||||
t += `<input type="radio" name="magrads" value="${fdata[1]}" aria-label="Radio button for magnetic url">`;
|
||||
t += `</div>`;
|
||||
t += `</div>`;
|
||||
t += `<input type="text" value="${fdata[0]}" class="form-control" aria-label="Text input with radio button">`;
|
||||
t += `</div>`;
|
||||
t += `</li>`;
|
||||
}
|
||||
}
|
||||
}
|
||||
$("#flo-res").html(t);
|
||||
},
|
||||
error: function() {
|
||||
|
||||
error: function(e) {
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -63,12 +80,15 @@
|
||||
|
||||
var client = new WebTorrent()
|
||||
|
||||
var torrentId = document.getElementById('mag_text').value;
|
||||
var torrentId = $('input[name=magrads]:checked').val();
|
||||
|
||||
if (torrentId.trim() == '') {
|
||||
alert("Please specify a magnetic url.");
|
||||
return;
|
||||
}
|
||||
torrentId = torrentId.replace("text:", "");
|
||||
|
||||
document.getElementById("tmsg").innerText = "The download link will appear here in few momments."
|
||||
|
||||
client.add(torrentId, function (torrent) {
|
||||
// Torrents can contain many files. Let's use the .mp4 file
|
||||
@ -105,7 +125,7 @@
|
||||
var a = document.createElement('a')
|
||||
a.download = file.name
|
||||
a.href = url
|
||||
a.textContent = 'Download ' + file.name
|
||||
a.textContent = 'Download ' + file.name + ' (' +file.length/1000+ ' Kb)'
|
||||
document.getElementById("dwld").appendChild(a)
|
||||
})
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
|
||||
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/webtorrent@latest/webtorrent.min.js"></script>
|
||||
<script src="/js/webtorrent.min.js"></script>
|
||||
<script src="https://rawgit.com/feross/drag-drop/master/dragdrop.min.js"></script>
|
||||
<!-- Moment is used to show a human-readable remaining time -->
|
||||
<script src="https://momentjs.com/downloads/moment.min.js"></script>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user