pull/1296/head
Ozzieisaacs 5 years ago
parent ec6b346ca1
commit 587174b771

@ -29,15 +29,15 @@ $(function () {
var msg = i18nMsg; var msg = i18nMsg;
var douban = "https://api.douban.com"; var douban = "https://api.douban.com";
var dbSearch = "/v2/book/search"; var dbSearch = "/v2/book/search";
var dbDone = true; var dbDone = 0;
var google = "https://www.googleapis.com"; var google = "https://www.googleapis.com";
var ggSearch = "/books/v1/volumes"; var ggSearch = "/books/v1/volumes";
var ggDone = false; var ggDone = 0;
var comicvine = "https://comicvine.gamespot.com"; var comicvine = "https://comicvine.gamespot.com";
var cvSearch = "/api/search/"; var cvSearch = "/api/search/";
var cvDone = false; var cvDone = 0;
var showFlag = 0; var showFlag = 0;
@ -73,7 +73,9 @@ $(function () {
if (showFlag === 1) { if (showFlag === 1) {
$("#meta-info").html("<ul id=\"book-list\" class=\"media-list\"></ul>"); $("#meta-info").html("<ul id=\"book-list\" class=\"media-list\"></ul>");
} }
if (!ggDone && !dbDone) { if ((ggDone == 3 || (ggDone == 1 && ggResults.length === 0)) &&
(dbDone == 3 || (ggDone == 1 && dbResults.length === 0)) &&
(cvDone == 3 || (ggDone == 1 && cvResults.length === 0))) {
$("#meta-info").html("<p class=\"text-danger\">" + msg.no_result + "</p>"); $("#meta-info").html("<p class=\"text-danger\">" + msg.no_result + "</p>");
return; return;
} }
@ -93,128 +95,141 @@ $(function () {
return [year, month, day].join("-"); return [year, month, day].join("-");
} }
if (ggDone && ggResults.length > 0) { if (ggResults.length > 0) {
ggResults.forEach(function(result) { if (ggDone < 2) {
var book = { ggResults.forEach(function(result) {
id: result.id, var book = {
title: result.volumeInfo.title, id: result.id,
authors: result.volumeInfo.authors || [], title: result.volumeInfo.title,
description: result.volumeInfo.description || "", authors: result.volumeInfo.authors || [],
publisher: result.volumeInfo.publisher || "", description: result.volumeInfo.description || "",
publishedDate: result.volumeInfo.publishedDate || "", publisher: result.volumeInfo.publisher || "",
tags: result.volumeInfo.categories || [], publishedDate: result.volumeInfo.publishedDate || "",
rating: result.volumeInfo.averageRating || 0, tags: result.volumeInfo.categories || [],
cover: result.volumeInfo.imageLinks ? rating: result.volumeInfo.averageRating || 0,
result.volumeInfo.imageLinks.thumbnail : "/static/generic_cover.jpg", cover: result.volumeInfo.imageLinks ?
url: "https://books.google.com/books?id=" + result.id, result.volumeInfo.imageLinks.thumbnail : "/static/generic_cover.jpg",
source: { url: "https://books.google.com/books?id=" + result.id,
id: "google", source: {
description: "Google Books", id: "google",
url: "https://books.google.com/" description: "Google Books",
} url: "https://books.google.com/"
}; }
};
var $book = $(templates.bookResult(book)); var $book = $(templates.bookResult(book));
$book.find("img").on("click", function () { $book.find("img").on("click", function () {
populateForm(book); populateForm(book);
}); });
$("#book-list").append($book); $("#book-list").append($book);
}); });
ggDone = false; ggDone = 2;
} else {
ggDone = 3;
}
} }
if (dbDone && dbResults.length > 0) {
dbResults.forEach(function(result) {
var seriesTitle = "";
if (result.series) {
seriesTitle = result.series.title;
}
var dateFomers = result.pubdate.split("-");
var publishedYear = parseInt(dateFomers[0]);
var publishedMonth = parseInt(dateFomers[1]);
var publishedDate = new Date(publishedYear, publishedMonth - 1, 1);
publishedDate = formatDate(publishedDate); if (dbResults.length > 0) {
if (dbDone < 2) {
dbResults.forEach(function(result) {
var seriesTitle = "";
if (result.series) {
seriesTitle = result.series.title;
}
var dateFomers = result.pubdate.split("-");
var publishedYear = parseInt(dateFomers[0]);
var publishedMonth = parseInt(dateFomers[1]);
var publishedDate = new Date(publishedYear, publishedMonth - 1, 1);
publishedDate = formatDate(publishedDate);
var book = {
id: result.id,
title: result.title,
authors: result.author || [],
description: result.summary,
publisher: result.publisher || "",
publishedDate: publishedDate || "",
tags: result.tags.map(function(tag) {
return tag.title.toLowerCase().replace(/,/g, "_");
}),
rating: result.rating.average || 0,
series: seriesTitle || "",
cover: result.image,
url: "https://book.douban.com/subject/" + result.id,
source: {
id: "douban",
description: "Douban Books",
url: "https://book.douban.com/"
}
};
var book = { if (book.rating > 0) {
id: result.id, book.rating /= 2;
title: result.title,
authors: result.author || [],
description: result.summary,
publisher: result.publisher || "",
publishedDate: publishedDate || "",
tags: result.tags.map(function(tag) {
return tag.title.toLowerCase().replace(/,/g, "_");
}),
rating: result.rating.average || 0,
series: seriesTitle || "",
cover: result.image,
url: "https://book.douban.com/subject/" + result.id,
source: {
id: "douban",
description: "Douban Books",
url: "https://book.douban.com/"
} }
};
if (book.rating > 0) { var $book = $(templates.bookResult(book));
book.rating /= 2; $book.find("img").on("click", function () {
} populateForm(book);
});
var $book = $(templates.bookResult(book)); $("#book-list").append($book);
$book.find("img").on("click", function () {
populateForm(book);
}); });
dbDone = 2;
$("#book-list").append($book); } else {
}); dbDone = 3;
dbDone = false; }
} }
if (cvDone && cvResults.length > 0) { if (cvResults.length > 0) {
cvResults.forEach(function(result) { if (cvDone < 2) {
var seriesTitle = ""; cvResults.forEach(function(result) {
if (result.volume.name) { var seriesTitle = "";
seriesTitle = result.volume.name; if (result.volume.name) {
} seriesTitle = result.volume.name;
var dateFomers = ""; }
if (result.store_date) { var dateFomers = "";
dateFomers = result.store_date.split("-"); if (result.store_date) {
}else{ dateFomers = result.store_date.split("-");
dateFomers = result.date_added.split("-"); }else{
} dateFomers = result.date_added.split("-");
var publishedYear = parseInt(dateFomers[0]); }
var publishedMonth = parseInt(dateFomers[1]); var publishedYear = parseInt(dateFomers[0]);
var publishedDate = new Date(publishedYear, publishedMonth - 1, 1); var publishedMonth = parseInt(dateFomers[1]);
var publishedDate = new Date(publishedYear, publishedMonth - 1, 1);
publishedDate = formatDate(publishedDate); publishedDate = formatDate(publishedDate);
var book = { var book = {
id: result.id, id: result.id,
title: seriesTitle + ' #' +('00' + result.issue_number).slice(-3) + ' - ' + result.name, title: seriesTitle + ' #' +('00' + result.issue_number).slice(-3) + ' - ' + result.name,
authors: result.author || [], authors: result.author || [],
description: result.description, description: result.description,
publisher: "", publisher: "",
publishedDate: publishedDate || "", publishedDate: publishedDate || "",
tags: ['Comics', seriesTitle], tags: ['Comics', seriesTitle],
rating: 0, rating: 0,
series: seriesTitle || "", series: seriesTitle || "",
cover: result.image.original_url, cover: result.image.original_url,
url: result.site_detail_url, url: result.site_detail_url,
source: { source: {
id: "comicvine", id: "comicvine",
description: "ComicVine Books", description: "ComicVine Books",
url: "https://comicvine.gamespot.com/" url: "https://comicvine.gamespot.com/"
} }
}; };
var $book = $(templates.bookResult(book)); var $book = $(templates.bookResult(book));
$book.find("img").on("click", function () { $book.find("img").on("click", function () {
populateForm(book); populateForm(book);
}); });
$("#book-list").append($book); $("#book-list").append($book);
}); });
cvDone = false; cvDone = 2;
} else {
cvDone = 3;
}
} }
} }
@ -227,11 +242,10 @@ $(function () {
success: function success(data) { success: function success(data) {
if ("items" in data) { if ("items" in data) {
ggResults = data.items; ggResults = data.items;
ggDone = true;
} }
}, },
complete: function complete() { complete: function complete() {
ggDone = true; ggDone = 1;
showResult(); showResult();
$("#show-google").trigger("change"); $("#show-google").trigger("change");
} }
@ -252,7 +266,7 @@ $(function () {
$("#meta-info").html("<p class=\"text-danger\">" + msg.search_error + "!</p>" + $("#meta-info")[0].innerHTML); $("#meta-info").html("<p class=\"text-danger\">" + msg.search_error + "!</p>" + $("#meta-info")[0].innerHTML);
}, },
complete: function complete() { complete: function complete() {
dbDone = true; dbDone = 1;
showResult(); showResult();
$("#show-douban").trigger("change"); $("#show-douban").trigger("change");
} }
@ -274,7 +288,7 @@ $(function () {
$("#meta-info").html("<p class=\"text-danger\">" + msg.search_error + "!</p>" + $("#meta-info")[0].innerHTML); $("#meta-info").html("<p class=\"text-danger\">" + msg.search_error + "!</p>" + $("#meta-info")[0].innerHTML);
}, },
complete: function complete() { complete: function complete() {
cvDone = true; cvDone = 1;
showResult(); showResult();
$("#show-comics").trigger("change"); $("#show-comics").trigger("change");
} }
@ -283,6 +297,10 @@ $(function () {
function doSearch (keyword) { function doSearch (keyword) {
showFlag = 0; showFlag = 0;
dbDone = ggDone = cvDone = 0;
dbResults = [];
ggResults = [];
cvResults = [];
$("#meta-info").text(msg.loading); $("#meta-info").text(msg.loading);
if (keyword) { if (keyword) {
dbSearchBook(keyword); dbSearchBook(keyword);

Loading…
Cancel
Save