Files
2025-11-07 22:44:47 +03:00

46 lines
1.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const modules = require("./module");
const config = require("../config");
const axios = require("axios");
class GoodreadsBookSearch {
getBookDetails = async (isbn) => {
const headers = config.headers;
const url = encodeURI(config.goodreadsBaseUrl + isbn);
try {
return new Promise((resolve, reject) => {
setTimeout(async () => {
try {
const response = await axios.get(url, { headers });
if (!response.data) {
throw new Error("Detay bilgisi bulunamadı!");
}
const details = await modules.extractBookDetails(
response.data,
isbn,
);
resolve(details);
} catch (error) {
reject(error);
}
}, config.fetchTimeout);
});
} catch (error) {
throw new Error("Hata: " + error.message);
}
};
}
module.exports = GoodreadsBookSearch;
(async () => {
try {
const BookSearch = new GoodreadsBookSearch();
const bookDetails = await BookSearch.getBookDetails("863173540X");
console.log(bookDetails);
} catch (error) {
console.log(error.message);
}
})();