🔧 Tweaking the CV api call
This commit is contained in:
@@ -197,6 +197,10 @@ export default class ComicVineService extends Service {
|
|||||||
ctx.params.scorerConfiguration.searchParams
|
ctx.params.scorerConfiguration.searchParams
|
||||||
);
|
);
|
||||||
const results: any = [];
|
const results: any = [];
|
||||||
|
console.log(
|
||||||
|
"passed to fetchvolumesfromcv",
|
||||||
|
ctx.params
|
||||||
|
);
|
||||||
const volumes = await this.fetchVolumesFromCV(
|
const volumes = await this.fetchVolumesFromCV(
|
||||||
ctx.params,
|
ctx.params,
|
||||||
results
|
results
|
||||||
@@ -300,15 +304,22 @@ export default class ComicVineService extends Service {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
fetchVolumesFromCV: async (params, output: any[] = []) => {
|
fetchVolumesFromCV: async (payload, output: any[] = []) => {
|
||||||
let currentPage = parseInt(params.page, 10);
|
const { format, query, limit, page, resources } = payload;
|
||||||
|
let currentPage = parseInt(page, 10);
|
||||||
const response = await axios.request({
|
const response = await axios.request({
|
||||||
url:
|
url:
|
||||||
CV_BASE_URL +
|
CV_BASE_URL +
|
||||||
"search" +
|
"search" +
|
||||||
"?api_key=" +
|
"?api_key=" +
|
||||||
process.env.COMICVINE_API_KEY,
|
process.env.COMICVINE_API_KEY,
|
||||||
params,
|
params: {
|
||||||
|
format,
|
||||||
|
query,
|
||||||
|
limit,
|
||||||
|
page,
|
||||||
|
resources,
|
||||||
|
},
|
||||||
headers: {
|
headers: {
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
"User-Agent": "ThreeTwo",
|
"User-Agent": "ThreeTwo",
|
||||||
@@ -319,7 +330,7 @@ export default class ComicVineService extends Service {
|
|||||||
// 1. Calculate total pages
|
// 1. Calculate total pages
|
||||||
const totalPages = Math.floor(
|
const totalPages = Math.floor(
|
||||||
parseInt(data.number_of_total_results, 10) /
|
parseInt(data.number_of_total_results, 10) /
|
||||||
parseInt(params.limit, 10)
|
parseInt(limit, 10)
|
||||||
);
|
);
|
||||||
// 1a. If total results are <= 100, just return the results
|
// 1a. If total results are <= 100, just return the results
|
||||||
if (parseInt(data.number_of_total_results, 10) <= 100) {
|
if (parseInt(data.number_of_total_results, 10) <= 100) {
|
||||||
@@ -329,13 +340,22 @@ export default class ComicVineService extends Service {
|
|||||||
if (currentPage <= totalPages) {
|
if (currentPage <= totalPages) {
|
||||||
output.push(...data.results);
|
output.push(...data.results);
|
||||||
currentPage += 1;
|
currentPage += 1;
|
||||||
params.page = currentPage;
|
// Params.page = currentPage;
|
||||||
console.log(
|
console.log(
|
||||||
`Fetching results for page ${currentPage} (of ${
|
`Fetching results for page ${currentPage} (of ${
|
||||||
totalPages + 1
|
totalPages + 1
|
||||||
})...`
|
})...`
|
||||||
);
|
);
|
||||||
return await this.fetchVolumesFromCV(params, output);
|
return await this.fetchVolumesFromCV(
|
||||||
|
{
|
||||||
|
format,
|
||||||
|
query,
|
||||||
|
limit,
|
||||||
|
page: currentPage,
|
||||||
|
resources,
|
||||||
|
},
|
||||||
|
output
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return [...output];
|
return [...output];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user