Limit Number of File Rows to Reduce OoM Errors

This commit is contained in:
Leo Herzog
2020-12-04 13:02:18 -05:00
parent f79c280de2
commit 6863553b66
3 changed files with 32 additions and 14 deletions

View File

@@ -23810,10 +23810,11 @@ function parseTorrent (torrentId) {
} }
} }
function parseTorrentRemote (torrentId, cb) { function parseTorrentRemote (torrentId, opts, cb) {
let parsedTorrent if (typeof opts === 'function') return parseTorrentRemote(torrentId, {}, opts)
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) {
@@ -23832,11 +23833,12 @@ function parseTorrentRemote (torrentId, 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
get.concat({ opts = Object.assign({
url: torrentId, url: torrentId,
timeout: 30 * 1000, timeout: 30 * 1000,
headers: { 'user-agent': 'WebTorrent (https://webtorrent.io)' } headers: { 'user-agent': 'WebTorrent (https://webtorrent.io)' }
}, (err, res, torrentBuf) => { }, opts)
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)
}) })
@@ -38179,9 +38181,17 @@ function display() {
files.innerHTML = ""; files.innerHTML = "";
if (parsed.files && parsed.files.length) { if (parsed.files && parsed.files.length) {
getFiles.style.display = "none"; getFiles.style.display = "none";
for (let file of parsed.files) { if (parsed.files.length < 100) {
let icon = getFontAwesomeIconForMimetype(mime.lookup(file.name)); for (let file of parsed.files) {
files.appendChild(createFileRow(icon, file.name, file.length)); let icon = getFontAwesomeIconForMimetype(mime.lookup(file.name));
files.appendChild(createFileRow(icon, file.name, file.length));
}
} else {
for (let i = 0; i < 100; i++) {
let icon = getFontAwesomeIconForMimetype(mime.lookup(parsed.files[i].name));
files.appendChild(createFileRow(icon, parsed.files[i].name, parsed.files[i].length));
}
files.appendChild(createFileRow('', '...and another ' + (parsed.files.length - 100) + ' more files', ''));
} }
files.appendChild(createFileRow('folder-tree', '', parsed.length)); files.appendChild(createFileRow('folder-tree', '', parsed.length));
downloadTorrentTooltip.setContent('Download Torrent file'); downloadTorrentTooltip.setContent('Download Torrent file');
@@ -38229,7 +38239,7 @@ function display() {
function createFileRow(icon, name, size) { function createFileRow(icon, name, size) {
let row = document.createElement('tr'); let row = document.createElement('tr');
let iconcell = document.createElement('td'); let iconcell = document.createElement('td');
iconcell.innerHTML = '<span class="far fa-' + icon + '"></span>'; if (icon) iconcell.innerHTML = '<span class="far fa-' + icon + '"></span>';
row.appendChild(iconcell); row.appendChild(iconcell);
let namecell = document.createElement('td'); let namecell = document.createElement('td');
namecell.innerHTML = name; namecell.innerHTML = name;

4
bin/bundle.min.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -303,9 +303,17 @@ function display() {
files.innerHTML = ""; files.innerHTML = "";
if (parsed.files && parsed.files.length) { if (parsed.files && parsed.files.length) {
getFiles.style.display = "none"; getFiles.style.display = "none";
for (let file of parsed.files) { if (parsed.files.length < 100) {
let icon = getFontAwesomeIconForMimetype(mime.lookup(file.name)); for (let file of parsed.files) {
files.appendChild(createFileRow(icon, file.name, file.length)); let icon = getFontAwesomeIconForMimetype(mime.lookup(file.name));
files.appendChild(createFileRow(icon, file.name, file.length));
}
} else {
for (let i = 0; i < 100; i++) {
let icon = getFontAwesomeIconForMimetype(mime.lookup(parsed.files[i].name));
files.appendChild(createFileRow(icon, parsed.files[i].name, parsed.files[i].length));
}
files.appendChild(createFileRow('', '...and another ' + (parsed.files.length - 100) + ' more files', ''));
} }
files.appendChild(createFileRow('folder-tree', '', parsed.length)); files.appendChild(createFileRow('folder-tree', '', parsed.length));
downloadTorrentTooltip.setContent('Download Torrent file'); downloadTorrentTooltip.setContent('Download Torrent file');
@@ -353,7 +361,7 @@ function display() {
function createFileRow(icon, name, size) { function createFileRow(icon, name, size) {
let row = document.createElement('tr'); let row = document.createElement('tr');
let iconcell = document.createElement('td'); let iconcell = document.createElement('td');
iconcell.innerHTML = '<span class="far fa-' + icon + '"></span>'; if (icon) iconcell.innerHTML = '<span class="far fa-' + icon + '"></span>';
row.appendChild(iconcell); row.appendChild(iconcell);
let namecell = document.createElement('td'); let namecell = document.createElement('td');
namecell.innerHTML = name; namecell.innerHTML = name;