mirror of
https://github.com/twisterarmy/twister-html.git
synced 2025-02-06 20:14:48 +00:00
replace getScript to ajax method by CSP update #354
This commit is contained in:
parent
6993ac2939
commit
4f1b817869
@ -344,79 +344,90 @@ function initWebTorrent() {
|
|||||||
twister.torrentIds = $.localStorage.get('torrentIds');
|
twister.torrentIds = $.localStorage.get('torrentIds');
|
||||||
|
|
||||||
WEBTORRENT_ANNOUNCE = $.Options.WebTorrentTrackers.val.split(/[ ,]+/)
|
WEBTORRENT_ANNOUNCE = $.Options.WebTorrentTrackers.val.split(/[ ,]+/)
|
||||||
$.getScript('js/webtorrent.min.js', function() {
|
|
||||||
WebTorrentClient = new WebTorrent();
|
|
||||||
console.log("WebTorrent started")
|
|
||||||
WebTorrentClient.on('error', function (err) {
|
|
||||||
console.error('ERROR: ' + err.message);
|
|
||||||
});
|
|
||||||
WebTorrentClient.on('warning', function (err) {
|
|
||||||
console.error('WARNING: ' + err.message);
|
|
||||||
});
|
|
||||||
|
|
||||||
$.getScript('js/localforage.min.js', function() {
|
jQuery.ajax({
|
||||||
localforage.setDriver([localforage.INDEXEDDB,localforage.WEBSQL]).then(function() {
|
crossDomain: true,
|
||||||
for (var torrentId in twister.torrentIds) {
|
dataType: 'script',
|
||||||
if( twister.torrentIds[torrentId] ) {
|
url: 'js/webtorrent.min.js',
|
||||||
if (typeof(twister.torrentIds[torrentId]) === "string") {
|
success: function() {
|
||||||
// get blob file to restart seeding this file
|
WebTorrentClient = new WebTorrent();
|
||||||
var onGetItem = function(torrentId, err, data) {
|
console.log("WebTorrent started")
|
||||||
console.log("onget:", torrentId, err, data)
|
WebTorrentClient.on('error', function (err) {
|
||||||
if (err || data === null) {
|
console.error('ERROR: ' + err.message);
|
||||||
// error reading blob, just add torrentId
|
});
|
||||||
console.log("WebTorrent auto-download: " + torrentId +
|
WebTorrentClient.on('warning', function (err) {
|
||||||
" (previously seeded as: " + twister.torrentIds[torrentId] + ")" );
|
console.error('WARNING: ' + err.message);
|
||||||
|
});
|
||||||
|
|
||||||
|
jQuery.ajax({
|
||||||
|
crossDomain: true,
|
||||||
|
dataType: 'script',
|
||||||
|
url: 'js/localforage.min.js',
|
||||||
|
success: function() {
|
||||||
|
localforage.setDriver([localforage.INDEXEDDB,localforage.WEBSQL]).then(function() {
|
||||||
|
for (var torrentId in twister.torrentIds) {
|
||||||
|
if( twister.torrentIds[torrentId] ) {
|
||||||
|
if (typeof(twister.torrentIds[torrentId]) === "string") {
|
||||||
|
// get blob file to restart seeding this file
|
||||||
|
var onGetItem = function(torrentId, err, data) {
|
||||||
|
console.log("onget:", torrentId, err, data)
|
||||||
|
if (err || data === null) {
|
||||||
|
// error reading blob, just add torrentId
|
||||||
|
console.log("WebTorrent auto-download: " + torrentId +
|
||||||
|
" (previously seeded as: " + twister.torrentIds[torrentId] + ")" );
|
||||||
|
WebTorrentClient.add(torrentId);
|
||||||
|
} else {
|
||||||
|
var fileBlob = new File([data], twister.torrentIds[torrentId]);
|
||||||
|
console.log('WebTorrent seeding: "' + twister.torrentIds[torrentId] +
|
||||||
|
'" size: ' + data.size);
|
||||||
|
WebTorrentClient.seed(fileBlob);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
localforage.getItem(torrentId, onGetItem.bind(null, torrentId));
|
||||||
|
} else if ($.Options.WebTorrentAutoDownload.val === 'enable') {
|
||||||
|
console.log("WebTorrent auto-download: " + torrentId);
|
||||||
WebTorrentClient.add(torrentId);
|
WebTorrentClient.add(torrentId);
|
||||||
} else {
|
|
||||||
var fileBlob = new File([data], twister.torrentIds[torrentId]);
|
|
||||||
console.log('WebTorrent seeding: "' + twister.torrentIds[torrentId] +
|
|
||||||
'" size: ' + data.size);
|
|
||||||
WebTorrentClient.seed(fileBlob);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
localforage.getItem(torrentId, onGetItem.bind(null, torrentId));
|
|
||||||
} else if ($.Options.WebTorrentAutoDownload.val === 'enable') {
|
|
||||||
console.log("WebTorrent auto-download: " + torrentId);
|
|
||||||
WebTorrentClient.add(torrentId);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// setup attach button
|
// setup attach button
|
||||||
$(".post-area-attach").show();
|
$(".post-area-attach").show();
|
||||||
var fileInput = $("#fileInputAttach");
|
var fileInput = $("#fileInputAttach");
|
||||||
fileInput.on('change', function(event) {
|
fileInput.on('change', function(event) {
|
||||||
var file = fileInput[0].files[0];
|
var file = fileInput[0].files[0];
|
||||||
var seedingTorrent = undefined;
|
var seedingTorrent = undefined;
|
||||||
for (var i = 0; i < WebTorrentClient.torrents.length; i++) {
|
for (var i = 0; i < WebTorrentClient.torrents.length; i++) {
|
||||||
var torrent = WebTorrentClient.torrents[i];
|
var torrent = WebTorrentClient.torrents[i];
|
||||||
if (torrent.length === file.size &&
|
if (torrent.length === file.size &&
|
||||||
torrent.files[0].name === file.name) {
|
torrent.files[0].name === file.name) {
|
||||||
seedingTorrent = torrent;
|
seedingTorrent = torrent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var saveBlobFile = function(infoHash,file) {
|
var saveBlobFile = function(infoHash,file) {
|
||||||
var magnetLink = "magnet:?xt=urn:btih:" + infoHash
|
var magnetLink = "magnet:?xt=urn:btih:" + infoHash
|
||||||
var blobFile = new Blob([file]);
|
var blobFile = new Blob([file]);
|
||||||
localforage.setItem(magnetLink, blobFile);
|
localforage.setItem(magnetLink, blobFile);
|
||||||
twister.torrentIds[magnetLink] = file.name;
|
twister.torrentIds[magnetLink] = file.name;
|
||||||
$.localStorage.set('torrentIds', twister.torrentIds);
|
$.localStorage.set('torrentIds', twister.torrentIds);
|
||||||
return magnetLink;
|
return magnetLink;
|
||||||
}
|
}
|
||||||
if (seedingTorrent) {
|
if (seedingTorrent) {
|
||||||
var magnetLink = saveBlobFile(seedingTorrent.infoHash,file);
|
var magnetLink = saveBlobFile(seedingTorrent.infoHash,file);
|
||||||
console.log('Already seeding ' + magnetLink);
|
console.log('Already seeding ' + magnetLink);
|
||||||
shortenMagnetLink(event,magnetLink);
|
shortenMagnetLink(event,magnetLink);
|
||||||
} else {
|
} else {
|
||||||
WebTorrentClient.seed(file, function (torrent) {
|
WebTorrentClient.seed(file, function (torrent) {
|
||||||
var magnetLink = saveBlobFile(torrent.infoHash,file);
|
var magnetLink = saveBlobFile(torrent.infoHash,file);
|
||||||
console.log('Client is seeding ' + magnetLink);
|
console.log('Client is seeding ' + magnetLink);
|
||||||
shortenMagnetLink(event,magnetLink);
|
shortenMagnetLink(event,magnetLink);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user