improved fetch-from-blockchain layout
This commit is contained in:
parent
47e4baee15
commit
943f708a99
19
ip.js
19
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 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)
|
var parsed = magnet(uri)
|
||||||
|
|
||||||
console.log(parsed.infoHash) // 'e3811b9539cacff680e418124272177c47477157'
|
//console.log(parsed.infoHash) // 'e3811b9539cacff680e418124272177c47477157'
|
||||||
|
|
||||||
var dht = new DHT()
|
var dht = new DHT()
|
||||||
|
|
||||||
dht.listen(20000, function () {
|
dht.listen(20000, function () {
|
||||||
console.log('now listening')
|
console.log('now listening')
|
||||||
|
//console.log(dht.address());
|
||||||
})
|
})
|
||||||
|
|
||||||
dht.on('peer', function (peer, infoHash, from) {
|
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)
|
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.lookup(parsed.infoHash)
|
||||||
|
|
||||||
|
// dht.on('node', function (node) {
|
||||||
|
// console.log(node);
|
||||||
|
// })
|
||||||
|
|
||||||
|
// dht.on('announce', function (peer, infoHash) {
|
||||||
|
// console.log(peer);
|
||||||
|
// console.log(infoHash)
|
||||||
|
// })
|
||||||
|
|||||||
@ -65,4 +65,7 @@ footer {
|
|||||||
|
|
||||||
.pd-10 {
|
.pd-10 {
|
||||||
padding: 10px 10px;
|
padding: 10px 10px;
|
||||||
|
}
|
||||||
|
.mg-10 {
|
||||||
|
margin: 10px 10px;
|
||||||
}
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
const client = require('../../server')
|
const client = require('../../server')
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
|
var magnet = require('magnet-uri')
|
||||||
|
|
||||||
let getFloData = (tx) => {
|
let getFloData = (tx) => {
|
||||||
return new Promise((resolve, reject)=>{
|
return new Promise((resolve, reject)=>{
|
||||||
@ -11,7 +12,9 @@ let getFloData = (tx) => {
|
|||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}).then(response=>{
|
}).then(response=>{
|
||||||
return resolve(response.floData)
|
var parsedTorrent = magnet(response.floData)
|
||||||
|
let resp = [parsedTorrent.name, response.floData]
|
||||||
|
return resolve(resp)
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return reject(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
35
routes.js
35
routes.js
@ -65,13 +65,30 @@ router.post('/download-magnetic-uri', (req, res)=>{
|
|||||||
var torrentId = params.torrentId
|
var torrentId = params.torrentId
|
||||||
|
|
||||||
if (_.trim(torrentId) == '') {
|
if (_.trim(torrentId) == '') {
|
||||||
//alert("Please specify a magnetic url.");
|
|
||||||
console.error("Empty torrent id");
|
console.error("Empty torrent id");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
client.add(torrentId, function (torrent) {
|
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 files = torrent.files
|
||||||
var length = files.length
|
var length = files.length
|
||||||
// Stream each file to the disk
|
// Stream each file to the disk
|
||||||
@ -86,12 +103,6 @@ router.post('/download-magnetic-uri', (req, res)=>{
|
|||||||
source.on('end', function () {
|
source.on('end', function () {
|
||||||
console.log('file:\t\t', file.name)
|
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})
|
res.json({file:file.name, location:fullpath})
|
||||||
|
|
||||||
// close after all files are saved
|
// close after all files are saved
|
||||||
@ -147,8 +158,8 @@ router.post('/send-to-blockchain', [
|
|||||||
res.json({error:true, "txnid":null, msg:'Magnetic uri is empty', data:null})
|
res.json({error:true, "txnid":null, msg:'Magnetic uri is empty', data:null})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let toaddress = "oSjBiuTE1aFNBjaSGq6UNhU9ddpD2YXdg8";
|
let toaddress = "oHyzdt8xW1A81qcZ5VcM25RbC6RVbynAg4";
|
||||||
let amount = 1;
|
let amount = 1;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -225,7 +236,7 @@ router.post('/fetch-from-blockchain', [
|
|||||||
return tx_arr;
|
return tx_arr;
|
||||||
|
|
||||||
}).then(tx_arr=>{
|
}).then(tx_arr=>{
|
||||||
console.log(tx_arr);
|
//console.log(tx_arr);
|
||||||
let tor_arr = []
|
let tor_arr = []
|
||||||
for (const tx in tx_arr) {
|
for (const tx in tx_arr) {
|
||||||
let promise = funcs.getFloData(_.trim(tx_arr[tx]))
|
let promise = funcs.getFloData(_.trim(tx_arr[tx]))
|
||||||
@ -239,8 +250,8 @@ router.post('/fetch-from-blockchain', [
|
|||||||
})
|
})
|
||||||
return msg_arr
|
return msg_arr
|
||||||
}).then(flo_data=>{
|
}).then(flo_data=>{
|
||||||
console.log(flo_data);
|
//console.log(flo_data);
|
||||||
res.json({error:false, msg:'floData fetching complete', data:flo_data})
|
res.json({error:false, msg:'List of Torrent files:', data:flo_data})
|
||||||
})
|
})
|
||||||
}).catch(e=>{
|
}).catch(e=>{
|
||||||
console.error(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 %>
|
<%include partials/header.ejs %>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<!-- duckdns-> oVrbkDUrX727MjQd4zq7nRw1XEHkkpGErE -->
|
<div class="row">
|
||||||
<label for="flo-addr">Enter the flo address (oSjBiuTE1aFNBjaSGq6UNhU9ddpD2YXdg8)</label>
|
<div class="col-md-8">
|
||||||
<input type="text" id="flo-addr" class="form-control" />
|
<!-- 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>
|
<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 Torrent</button></p>
|
||||||
<p><button id="dwn-seed" class="btn btn-primary">View</button></p>
|
</div>
|
||||||
|
|
||||||
<p id="dwld"></p>
|
<div class="col-md-4">
|
||||||
|
|
||||||
<div class="pd-10">
|
<div class="mt-2 mb-2">
|
||||||
<div id="mag-res"></div>
|
<p id="tmsg" class="text-info"></p>
|
||||||
|
<p id="dwld"></p>
|
||||||
|
<div id="mag-res"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@ -38,23 +45,33 @@
|
|||||||
type: 'post',
|
type: 'post',
|
||||||
data: {job:job, floaddr:floaddr},
|
data: {job:job, floaddr:floaddr},
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
console.log(response);
|
|
||||||
var t = '';
|
var t = '';
|
||||||
if (response.msg.length>0) {
|
if (response.msg.length>0) {
|
||||||
t += `<li><h5 class="text-info">${response.msg}</h5></li>`;
|
t += `<li class="list-group-item list-group-item-light"><h5 class="text-info">${response.msg}</h5></li>`;
|
||||||
t += ``;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.error==false && typeof response.data != undefined) {
|
if (response.error==false && typeof response.data != undefined) {
|
||||||
for (let fd = 0; fd < response.data.length; fd++) {
|
for (let fd = 0; fd < response.data.length; fd++) {
|
||||||
const fdata = response.data[fd];
|
if (response.data[fd][0] != null && response.data[fd][1] != null) {
|
||||||
t += `<li><p>${fdata}</p></li>`;
|
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);
|
$("#flo-res").html(t);
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function(e) {
|
||||||
|
console.error(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -63,12 +80,15 @@
|
|||||||
|
|
||||||
var client = new WebTorrent()
|
var client = new WebTorrent()
|
||||||
|
|
||||||
var torrentId = document.getElementById('mag_text').value;
|
var torrentId = $('input[name=magrads]:checked').val();
|
||||||
|
|
||||||
if (torrentId.trim() == '') {
|
if (torrentId.trim() == '') {
|
||||||
alert("Please specify a magnetic url.");
|
alert("Please specify a magnetic url.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
torrentId = torrentId.replace("text:", "");
|
||||||
|
|
||||||
|
document.getElementById("tmsg").innerText = "The download link will appear here in few momments."
|
||||||
|
|
||||||
client.add(torrentId, function (torrent) {
|
client.add(torrentId, function (torrent) {
|
||||||
// Torrents can contain many files. Let's use the .mp4 file
|
// Torrents can contain many files. Let's use the .mp4 file
|
||||||
@ -105,7 +125,7 @@
|
|||||||
var a = document.createElement('a')
|
var a = document.createElement('a')
|
||||||
a.download = file.name
|
a.download = file.name
|
||||||
a.href = url
|
a.href = url
|
||||||
a.textContent = 'Download ' + file.name
|
a.textContent = 'Download ' + file.name + ' (' +file.length/1000+ ' Kb)'
|
||||||
document.getElementById("dwld").appendChild(a)
|
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/jquery-1.12.4.js"></script>
|
||||||
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.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>
|
<script src="https://rawgit.com/feross/drag-drop/master/dragdrop.min.js"></script>
|
||||||
<!-- Moment is used to show a human-readable remaining time -->
|
<!-- Moment is used to show a human-readable remaining time -->
|
||||||
<script src="https://momentjs.com/downloads/moment.min.js"></script>
|
<script src="https://momentjs.com/downloads/moment.min.js"></script>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user