保存所有可用的源信息

This commit is contained in:
zhl 2019-04-03 17:30:30 +08:00
parent 34fc29cf68
commit 1cdc450b42

View File

@ -152,29 +152,28 @@ const parseOneBook = async (book) => {
if (!book.data || !book.data.sites || book.data.sites.length === 0) { if (!book.data || !book.data.sites || book.data.sites.length === 0) {
return; return;
} }
let siteId = book.data.sites[0].site; let hasChapter = false;
let chapterList;
// 书籍章节列表 // 书籍章节列表
// 有些源无法获取到章节列表, 所以挨个获取,直到获取到数据 // 有些源无法获取到章节列表, 所以挨个获取,直到获取到数据
if (book.data.sites && book.data.sites.length > 0) {
for(let site of book.data.sites) { for(let site of book.data.sites) {
let chapterListData = await bookChapterList(bookId, site.site); let chapterListData = await bookChapterList(bookId, site.site);
if (chapterListData.code === 1) { if (chapterListData.code === 1) {
chapterList = chapterListData.data; hasChapter = true;
site = site.site; chapterListData.book_id = bookId;
break; chapterListData.site = siteId;
}
}
if (!siteId) {
return ;
}
let chapterRecord = new SpiderData({ let chapterRecord = new SpiderData({
data: {list: chapterList, data: chapterListData,
book_id: bookId,
site: siteId,
},
type: 'book_chapter' type: 'book_chapter'
}); });
await chapterRecord.save(); await chapterRecord.save();
}
}
}
if (hasChapter) {
book.status = 2;
await book.save();
}
// let bar = multi.newBar(' '+book.data.name+' [:bar] :percent :etas', { // let bar = multi.newBar(' '+book.data.name+' [:bar] :percent :etas', {
// complete: '=', // complete: '=',
// incomplete: ' ', // incomplete: ' ',
@ -188,8 +187,6 @@ const parseOneBook = async (book) => {
// chapter.book_id = bookId; // chapter.book_id = bookId;
// chapter.site = siteId; // chapter.site = siteId;
// } // }
book.status = 2;
await book.save();
} }
const parseAllBookList = async (sex, ltype) => { const parseAllBookList = async (sex, ltype) => {
let bookList = await SpiderData.find({ let bookList = await SpiderData.find({