Skip to content

Commit

Permalink
Merge pull request #78 from Doarakko/topic/update-api-format
Browse files Browse the repository at this point in the history
update api response format
  • Loading branch information
Doarakko authored Aug 21, 2024
2 parents 2e7ec33 + 386b570 commit ebf9bcf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
12 changes: 8 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async function run() {
const githubToken = getInput("github-token");
const octokit = new Octokit({ auth: githubToken });

fetch("https://db.ygoprodeck.com/api/v7/randomcard.php")
fetch("https://db.ygoprodeck.com/api/v7/cardinfo.php?num=1&offset=0&sort=random&cachebust")
.then((response) => {
if(!response.ok){
console.error('response.ok:', response.ok);
Expand All @@ -19,11 +19,15 @@ async function run() {
return response.json();
})
.then((data) => {
const cardName = data.name;
if (!(('card_images' in data) && Array.isArray(data.card_images) && data.card_images.length > 0)) {
if (!(Array.isArray(data.card_images) && data.length > 0)) {
throw new Error("Failed to get card");
}
const card = data[0];
const cardName = card.name;
if (!(('card_images' in card) && Array.isArray(card.card_images) && card.card_images.length > 0)) {
throw new Error("Failed to get card images");
}
const imageUrl = data.card_images[0].image_url;
const imageUrl = card.card_images[0].image_url;

octokit.request(
"POST /repos/{owner}/{repo}/issues/{issue_number}/comments",
Expand Down

0 comments on commit ebf9bcf

Please sign in to comment.