fix: undefined error when no magnet & torrent (#7745)

This commit is contained in:
junfengP
2021-11-27 07:28:45 +00:00
committed by GitHub
parent 5b36e0b70d
commit 604e05b369
+13 -6
View File
@@ -92,18 +92,25 @@ module.exports = async (ctx) => {
}
const description = (postMessage.html() || '抓取原帖失败').replace(/ignore_js_op/g, 'div');
const magnet = postMessage.find('div.blockcode li').text();
const isMag = magnet.startsWith('magnet');
const enclosureUrl = isMag ? magnet : url.resolve(host, postMessage.find('a[href^=forum\\.php\\?mod\\=attachment]:not([href$=nothumb\\=yes])').attr('href'));
const single = {
title,
link: itemUrl,
description,
pubDate: new Date(date).toUTCString(),
enclosure_url: enclosureUrl,
enclosure_type: isMag ? 'application/x-bittorrent' : 'application/octet-stream',
};
const magnet = postMessage.find('div.blockcode li').text();
const isMag = magnet.startsWith('magnet');
const torrent = postMessage.find('a[href^=forum\\.php\\?mod\\=attachment]:not([href$=nothumb\\=yes])').attr('href');
const hasEnclosureUrl = isMag || torrent !== undefined;
if (hasEnclosureUrl) {
const enclosureUrl = isMag ? magnet : url.resolve(host, torrent);
const enclosure = {
enclosure_url: enclosureUrl,
enclosure_type: isMag ? 'application/x-bittorrent' : 'application/octet-stream',
};
Object.assign(single, enclosure);
}
if (description !== '抓取原帖失败') {
ctx.cache.set(itemUrl, JSON.stringify(single));
}