🔧 Debugging the 403 from CV
This commit is contained in:
@@ -191,95 +191,106 @@ export default class ComicVineService extends Service {
|
|||||||
rawFileDetails: object;
|
rawFileDetails: object;
|
||||||
}>
|
}>
|
||||||
) => {
|
) => {
|
||||||
console.log(
|
try {
|
||||||
"Searching against: ",
|
console.log(
|
||||||
ctx.params.scorerConfiguration.searchParams
|
"Searching against: ",
|
||||||
);
|
|
||||||
const results: any = [];
|
|
||||||
const volumes = await this.fetchVolumesFromCV(
|
|
||||||
ctx.params,
|
|
||||||
results
|
|
||||||
);
|
|
||||||
// 1. Run the current batch of volumes through the matcher
|
|
||||||
const potentialVolumeMatches = rankVolumes(
|
|
||||||
volumes,
|
|
||||||
ctx.params.scorerConfiguration
|
|
||||||
);
|
|
||||||
|
|
||||||
// 2. Construct the filter string
|
|
||||||
// 2a. volume: 1111|2222|3333
|
|
||||||
let volumeIdString = "volume:";
|
|
||||||
potentialVolumeMatches.map(
|
|
||||||
(volumeId: string, idx: number) => {
|
|
||||||
if (idx >= potentialVolumeMatches.length - 1) {
|
|
||||||
volumeIdString += `${volumeId}`;
|
|
||||||
return volumeIdString;
|
|
||||||
}
|
|
||||||
volumeIdString += `${volumeId}|`;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// 2b. cover_date:2014-01-01|2016-12-31 for the issue year 2015
|
|
||||||
let coverDateFilter = "";
|
|
||||||
if (
|
|
||||||
!isNil(
|
|
||||||
ctx.params.scorerConfiguration.searchParams.year
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
const issueYear = parseInt(
|
|
||||||
ctx.params.scorerConfiguration.searchParams
|
ctx.params.scorerConfiguration.searchParams
|
||||||
.year,
|
|
||||||
10
|
|
||||||
);
|
);
|
||||||
coverDateFilter = `cover_date:${
|
const results: any = [];
|
||||||
issueYear - 1
|
const volumes = await this.fetchVolumesFromCV(
|
||||||
}-01-01|${issueYear + 1}-12-31`;
|
ctx.params,
|
||||||
}
|
results
|
||||||
const filterString = `issue_number:${ctx.params.scorerConfiguration.searchParams.number},${volumeIdString},${coverDateFilter}`;
|
);
|
||||||
console.log(filterString);
|
// 1. Run the current batch of volumes through the matcher
|
||||||
|
const potentialVolumeMatches = rankVolumes(
|
||||||
|
volumes,
|
||||||
|
ctx.params.scorerConfiguration
|
||||||
|
);
|
||||||
|
|
||||||
const issueMatches = await axios({
|
// 2. Construct the filter string
|
||||||
url: `https://comicvine.gamespot.com/api/issues?api_key=${process.env.COMICVINE_API_KEY}`,
|
// 2a. volume: 1111|2222|3333
|
||||||
method: "GET",
|
let volumeIdString = "volume:";
|
||||||
params: {
|
potentialVolumeMatches.map(
|
||||||
resources: "issues",
|
(volumeId: string, idx: number) => {
|
||||||
limit: "100",
|
if (
|
||||||
format: "json",
|
idx >=
|
||||||
filter: filterString,
|
potentialVolumeMatches.length - 1
|
||||||
},
|
) {
|
||||||
// headers: {
|
volumeIdString += `${volumeId}`;
|
||||||
// "User-Agent": "ThreeTwo",
|
return volumeIdString;
|
||||||
// "Accept": "application/json",
|
}
|
||||||
// },
|
volumeIdString += `${volumeId}|`;
|
||||||
});
|
|
||||||
console.log(
|
|
||||||
`Total issues matching the criteria: ${issueMatches.data.results.length}`
|
|
||||||
);
|
|
||||||
// 3. get volume information for the issue matches
|
|
||||||
if (issueMatches.data.results.length === 1) {
|
|
||||||
const volumeInformation = await this.broker.call(
|
|
||||||
"comicvine.getVolumes",
|
|
||||||
{
|
|
||||||
volumeURI:
|
|
||||||
issueMatches.data.results[0].volume
|
|
||||||
.api_detail_url,
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
issueMatches.data.results[0].volumeInformation =
|
|
||||||
volumeInformation;
|
// 2b. cover_date:2014-01-01|2016-12-31 for the issue year 2015
|
||||||
return issueMatches.data;
|
let coverDateFilter = "";
|
||||||
}
|
if (
|
||||||
const finalMatches = issueMatches.data.results.map(
|
!isNil(
|
||||||
async (issue: any) => {
|
ctx.params.scorerConfiguration.searchParams
|
||||||
const volumeDetails = await this.broker.call(
|
.year
|
||||||
"comicvine.getVolumes",
|
)
|
||||||
{ volumeURI: issue.volume.api_detail_url }
|
) {
|
||||||
|
const issueYear = parseInt(
|
||||||
|
ctx.params.scorerConfiguration.searchParams
|
||||||
|
.year,
|
||||||
|
10
|
||||||
);
|
);
|
||||||
issue.volumeInformation = volumeDetails;
|
coverDateFilter = `cover_date:${
|
||||||
return issue;
|
issueYear - 1
|
||||||
|
}-01-01|${issueYear + 1}-12-31`;
|
||||||
}
|
}
|
||||||
);
|
const filterString = `issue_number:${ctx.params.scorerConfiguration.searchParams.number},${volumeIdString},${coverDateFilter}`;
|
||||||
return Promise.all(finalMatches);
|
console.log(filterString);
|
||||||
|
|
||||||
|
const issueMatches = await axios({
|
||||||
|
url: `${CV_BASE_URL}issues?api_key=${process.env.COMICVINE_API_KEY}`,
|
||||||
|
params: {
|
||||||
|
resources: "issues",
|
||||||
|
limit: "100",
|
||||||
|
format: "json",
|
||||||
|
filter: filterString,
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
Accept: "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log(
|
||||||
|
`Total issues matching the criteria: ${issueMatches.data.results.length}`
|
||||||
|
);
|
||||||
|
// 3. get volume information for the issue matches
|
||||||
|
if (issueMatches.data.results.length === 1) {
|
||||||
|
const volumeInformation =
|
||||||
|
await this.broker.call(
|
||||||
|
"comicvine.getVolumes",
|
||||||
|
{
|
||||||
|
volumeURI:
|
||||||
|
issueMatches.data.results[0]
|
||||||
|
.volume.api_detail_url,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
issueMatches.data.results[0].volumeInformation =
|
||||||
|
volumeInformation;
|
||||||
|
return issueMatches.data;
|
||||||
|
}
|
||||||
|
const finalMatches = issueMatches.data.results.map(
|
||||||
|
async (issue: any) => {
|
||||||
|
const volumeDetails =
|
||||||
|
await this.broker.call(
|
||||||
|
"comicvine.getVolumes",
|
||||||
|
{
|
||||||
|
volumeURI:
|
||||||
|
issue.volume.api_detail_url,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
issue.volumeInformation = volumeDetails;
|
||||||
|
return issue;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return Promise.all(finalMatches);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -287,13 +298,11 @@ export default class ComicVineService extends Service {
|
|||||||
fetchVolumesFromCV: async (params, output: any[] = []) => {
|
fetchVolumesFromCV: async (params, output: any[] = []) => {
|
||||||
let currentPage = parseInt(params.page, 10);
|
let currentPage = parseInt(params.page, 10);
|
||||||
const response = await axios.request({
|
const response = await axios.request({
|
||||||
url: `https://comicvine.gamespot.com/api/search?api_key=${process.env.COMICVINE_API_KEY}`,
|
url: `${CV_BASE_URL}search?api_key=${process.env.COMICVINE_API_KEY}`,
|
||||||
method: "GET",
|
|
||||||
params,
|
params,
|
||||||
// headers: {
|
headers: {
|
||||||
// "User-Agent": "ThreeTwo",
|
Accept: "application/json",
|
||||||
// "Accept": "application/json",
|
},
|
||||||
// },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data } = response;
|
const { data } = response;
|
||||||
|
|||||||
Reference in New Issue
Block a user