update 5 files
This commit is contained in:
37
lib/index.js
37
lib/index.js
@@ -12,27 +12,32 @@ class AmazonBookSearch {
|
||||
|
||||
const fetchBookId = async (isbn) => {
|
||||
const headers = config.headers;
|
||||
|
||||
try {
|
||||
const url = encodeURI(this.url + isbn);
|
||||
const response = await axios.get(url, { headers });
|
||||
if (!response.data) {
|
||||
throw new Error("Kitap bilgisi bulunamadı!");
|
||||
}
|
||||
|
||||
const bookId = modules.extractBookId(response.data);
|
||||
|
||||
|
||||
return bookId;
|
||||
} catch (error) {
|
||||
throw new Error("Hata: " + error.message);
|
||||
throw new Error(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
this.getBookDetails = async (isbn, geminiApiKey) => {
|
||||
|
||||
const headers = config.headers;
|
||||
try {
|
||||
const bookId = await fetchBookId(isbn);
|
||||
const url = encodeURI(location == "tr" ? config.tr_detail_url + bookId : config.en_detail_url + bookId);
|
||||
|
||||
const url = encodeURI(
|
||||
location == "tr"
|
||||
? config.tr_detail_url + bookId
|
||||
: config.en_detail_url + bookId
|
||||
);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
@@ -54,7 +59,7 @@ class AmazonBookSearch {
|
||||
}, config.fetchTimeout);
|
||||
});
|
||||
} catch (error) {
|
||||
throw new Error("Hata: " + error.message);
|
||||
throw new Error(error.message);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -73,13 +78,13 @@ module.exports = AmazonBookSearch;
|
||||
// }
|
||||
// })();
|
||||
|
||||
// //
|
||||
// (async () => {
|
||||
// try {
|
||||
// const BookSearch = new AmazonBookSearch("en");
|
||||
// const bookDetails = await BookSearch.getBookDetails("0593724283");
|
||||
// console.log(bookDetails);
|
||||
// } catch (error) {
|
||||
// console.log(error.message);
|
||||
// }
|
||||
// })();
|
||||
// //
|
||||
(async () => {
|
||||
try {
|
||||
const BookSearch = new AmazonBookSearch("en");
|
||||
const bookDetails = await BookSearch.getBookDetails("0593724283");
|
||||
console.log(bookDetails);
|
||||
} catch (error) {
|
||||
console.log(error.message);
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user