From 25070ae7177a4583cec8da961a14f9f4e94705cb Mon Sep 17 00:00:00 2001 From: aadarsh805 Date: Fri, 7 Oct 2022 19:40:16 +0530 Subject: [PATCH 1/5] set up api endpoint for fetching topCharts --- .env | 4 +- package-lock.json | 152 ++++++++++++++++++++++++++++++++++++++++ package.json | 1 + pages/api/top/charts.js | 20 ++++++ yarn.lock | 68 +++++++++++++++++- 5 files changed, 241 insertions(+), 4 deletions(-) create mode 100644 pages/api/top/charts.js diff --git a/.env b/.env index 008f316..a143629 100644 --- a/.env +++ b/.env @@ -1,4 +1,6 @@ GOOGLE_CLIENT_ID=461824563020-ohqpshrs1vh41289rle6kjqcdhv58j4f.apps.googleusercontent.com GOOGLE_CLIENT_SECRET = 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 NEXTAUTH_URL=http://localhost:3000 -JWT_SECRET =fUAcqpb6X/Qo33B7N7nKezh7IwLf0h2XdwsQ6X2Y+oE= \ No newline at end of file +JWT_SECRET =fUAcqpb6X/Qo33B7N7nKezh7IwLf0h2XdwsQ6X2Y+oE= + +NEXT_PUBLIC_RAPIDAPI_KEY= 0ac7392c46msha4f3dfc287416ffp189c80jsnd7cf096105d4 \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ccbc0fe..ca4299e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@heroicons/react": "^1.0.6", "@mui/icons-material": "^5.10.6", "@mui/material": "^5.10.7", + "axios": "^1.1.2", "classnames": "^2.3.2", "next": "^12.3.1", "next-auth": "^4.12.3", @@ -1653,6 +1654,11 @@ "integrity": "sha512-eBvWn1lvIApYMhzQMsu9ciLfkBY499mFZlNqG+/9WR7PVlroQw0vG30cOQQbaKz3sCEc44TAOu2ykzqXSNnwag==", "dev": true }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, "node_modules/autoprefixer": { "version": "10.4.12", "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.12.tgz", @@ -1695,6 +1701,16 @@ "node": ">=4" } }, + "node_modules/axios": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.1.2.tgz", + "integrity": "sha512-bznQyETwElsXl2RK7HLLwb5GPpOLlycxHCtrpDR/4RqqBzjARaOTo3jz4IgtntWUYee7Ne4S8UHd92VCuzPaWA==", + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/axobject-query": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.2.0.tgz", @@ -1910,6 +1926,17 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -2039,6 +2066,14 @@ "integrity": "sha512-Y2caI5+ZwS5c3RiNDJ6u53VhQHv+hHKwhkI1iHvceKUHw9Df6EK2zRLfjejRgMuCuxK7PfSWIMwWecceVvThjQ==", "dev": true }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/detective": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/detective/-/detective-5.2.1.tgz", @@ -2765,6 +2800,38 @@ "integrity": "sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==", "dev": true }, + "node_modules/follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fraction.js": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.2.0.tgz", @@ -3489,6 +3556,25 @@ "node": ">=8.6" } }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -4127,6 +4213,11 @@ "react-is": "^16.13.1" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", @@ -5962,6 +6053,11 @@ "integrity": "sha512-eBvWn1lvIApYMhzQMsu9ciLfkBY499mFZlNqG+/9WR7PVlroQw0vG30cOQQbaKz3sCEc44TAOu2ykzqXSNnwag==", "dev": true }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, "autoprefixer": { "version": "10.4.12", "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.12.tgz", @@ -5982,6 +6078,16 @@ "integrity": "sha512-32+ub6kkdhhWick/UjvEwRchgoetXqTK14INLqbGm5U2TzBkBNF3nQtLYm8ovxSkQWArjEQvftCKryjZaATu3w==", "dev": true }, + "axios": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.1.2.tgz", + "integrity": "sha512-bznQyETwElsXl2RK7HLLwb5GPpOLlycxHCtrpDR/4RqqBzjARaOTo3jz4IgtntWUYee7Ne4S8UHd92VCuzPaWA==", + "requires": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "axobject-query": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.2.0.tgz", @@ -6128,6 +6234,14 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "requires": { + "delayed-stream": "~1.0.0" + } + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -6223,6 +6337,11 @@ "integrity": "sha512-Y2caI5+ZwS5c3RiNDJ6u53VhQHv+hHKwhkI1iHvceKUHw9Df6EK2zRLfjejRgMuCuxK7PfSWIMwWecceVvThjQ==", "dev": true }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==" + }, "detective": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/detective/-/detective-5.2.1.tgz", @@ -6795,6 +6914,21 @@ "integrity": "sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==", "dev": true }, + "follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==" + }, + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, "fraction.js": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.2.0.tgz", @@ -7310,6 +7444,19 @@ "picomatch": "^2.3.1" } }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "requires": { + "mime-db": "1.52.0" + } + }, "minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -7723,6 +7870,11 @@ "react-is": "^16.13.1" } }, + "proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", diff --git a/package.json b/package.json index e49e26e..8dcd93b 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "@heroicons/react": "^1.0.6", "@mui/icons-material": "^5.10.6", "@mui/material": "^5.10.7", + "axios": "^1.1.2", "classnames": "^2.3.2", "next": "^12.3.1", "next-auth": "^4.12.3", diff --git a/pages/api/top/charts.js b/pages/api/top/charts.js new file mode 100644 index 0000000..6574bd6 --- /dev/null +++ b/pages/api/top/charts.js @@ -0,0 +1,20 @@ +import axios from 'axios'; + +const options = { + method: 'GET', + url: 'https://shazam.p.rapidapi.com/charts/track', + params: { pageSize: '5', startFrom: '5' }, + headers: { + 'X-RapidAPI-Key': '0ac7392c46msha4f3dfc287416ffp189c80jsnd7cf096105d4', + 'X-RapidAPI-Host': 'shazam.p.rapidapi.com', + }, +}; + +axios + .request(options) + .then(function (response) { + console.log(response.data); + }) + .catch(function (error) { + console.error(error); + }); diff --git a/yarn.lock b/yarn.lock index c376d8a..be19bd7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -518,9 +518,14 @@ dependencies: "glob" "7.1.7" -"@next/swc-win32-x64-msvc@12.3.1": - "integrity" "sha512-W1ijvzzg+kPEX6LAc+50EYYSEo0FVu7dmTE+t+DM4iOLqgGHoW9uYSz9wCVdkXOEEMP9xhXfGpcSxsfDucyPkA==" - "resolved" "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-12.3.1.tgz" +"@next/swc-linux-x64-gnu@12.3.1": + "integrity" "sha512-JWEaMyvNrXuM3dyy9Pp5cFPuSSvG82+yABqsWugjWlvfmnlnx9HOQZY23bFq3cNghy5V/t0iPb6cffzRWylgsA==" + "resolved" "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-12.3.1.tgz" + "version" "12.3.1" + +"@next/swc-linux-x64-musl@12.3.1": + "integrity" "sha512-xoEWQQ71waWc4BZcOjmatuvPUXKTv6MbIFzpm4LFeCHsg2iwai0ILmNXf81rJR+L1Wb9ifEke2sQpZSPNz1Iyg==" + "resolved" "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-12.3.1.tgz" "version" "12.3.1" "@nodelib/fs.scandir@2.1.5": @@ -783,6 +788,11 @@ "resolved" "https://registry.npmjs.org/ast-types-flow/-/ast-types-flow-0.0.7.tgz" "version" "0.0.7" +"asynckit@^0.4.0": + "integrity" "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + "resolved" "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz" + "version" "0.4.0" + "autoprefixer@^10.4.12": "integrity" "sha512-WrCGV9/b97Pa+jtwf5UGaRjgQIg7OK3D06GnoYoZNcG1Xb8Gt3EfuKjlhh9i/VtT16g6PYjZ69jdJ2g8FxSC4Q==" "resolved" "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.12.tgz" @@ -800,6 +810,15 @@ "resolved" "https://registry.npmjs.org/axe-core/-/axe-core-4.4.3.tgz" "version" "4.4.3" +"axios@^1.1.2": + "integrity" "sha512-bznQyETwElsXl2RK7HLLwb5GPpOLlycxHCtrpDR/4RqqBzjARaOTo3jz4IgtntWUYee7Ne4S8UHd92VCuzPaWA==" + "resolved" "https://registry.npmjs.org/axios/-/axios-1.1.2.tgz" + "version" "1.1.2" + dependencies: + "follow-redirects" "^1.15.0" + "form-data" "^4.0.0" + "proxy-from-env" "^1.1.0" + "axobject-query@^2.2.0": "integrity" "sha512-Td525n+iPOOyUQIeBfcASuG6uJsDOITl7Mds5gFyerkWiX7qhUTdYUBlSgNMyVqtSJqwpt1kXGLdUt6SykLMRA==" "resolved" "https://registry.npmjs.org/axobject-query/-/axobject-query-2.2.0.tgz" @@ -938,6 +957,13 @@ "resolved" "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz" "version" "1.1.3" +"combined-stream@^1.0.8": + "integrity" "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==" + "resolved" "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz" + "version" "1.0.8" + dependencies: + "delayed-stream" "~1.0.0" + "concat-map@0.0.1": "integrity" "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" "resolved" "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz" @@ -1034,6 +1060,11 @@ "resolved" "https://registry.npmjs.org/defined/-/defined-1.0.0.tgz" "version" "1.0.0" +"delayed-stream@~1.0.0": + "integrity" "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==" + "resolved" "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz" + "version" "1.0.0" + "detective@^5.2.1": "integrity" "sha512-v9XE1zRnz1wRtgurGu0Bs8uHKFSTdteYZNbIPFVhUZ39L/S79ppMpdmVOZAnoz1jfEFodc48n6MX483Xo3t1yw==" "resolved" "https://registry.npmjs.org/detective/-/detective-5.2.1.tgz" @@ -1440,6 +1471,20 @@ "resolved" "https://registry.npmjs.org/flatted/-/flatted-3.2.7.tgz" "version" "3.2.7" +"follow-redirects@^1.15.0": + "integrity" "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==" + "resolved" "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz" + "version" "1.15.2" + +"form-data@^4.0.0": + "integrity" "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==" + "resolved" "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz" + "version" "4.0.0" + dependencies: + "asynckit" "^0.4.0" + "combined-stream" "^1.0.8" + "mime-types" "^2.1.12" + "fraction.js@^4.2.0": "integrity" "sha512-MhLuK+2gUcnZe8ZHlaaINnQLl0xRIGRfcGk2yl8xoQAfHrSsL3rYu6FCmBdkdbhc9EPlwyGHewaRsvwRMJtAlA==" "resolved" "https://registry.npmjs.org/fraction.js/-/fraction.js-4.2.0.tgz" @@ -1901,6 +1946,18 @@ "braces" "^3.0.2" "picomatch" "^2.3.1" +"mime-db@1.52.0": + "integrity" "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" + "resolved" "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz" + "version" "1.52.0" + +"mime-types@^2.1.12": + "integrity" "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==" + "resolved" "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz" + "version" "2.1.35" + dependencies: + "mime-db" "1.52.0" + "minimatch@^3.0.4", "minimatch@^3.1.1", "minimatch@^3.1.2": "integrity" "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==" "resolved" "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz" @@ -2262,6 +2319,11 @@ "object-assign" "^4.1.1" "react-is" "^16.13.1" +"proxy-from-env@^1.1.0": + "integrity" "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + "resolved" "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz" + "version" "1.1.0" + "punycode@^2.1.0": "integrity" "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" "resolved" "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz" From daed5d537921e53094fa63b4a0df9baf892afe36 Mon Sep 17 00:00:00 2001 From: aadarsh805 Date: Fri, 7 Oct 2022 20:16:59 +0530 Subject: [PATCH 2/5] fixed api endpoint --- components/TopCharts/TopCharts.jsx | 3 ++- pages/Explore.jsx | 18 +++++++++++++-- pages/api/top/charts.js | 36 ++++++++++++++++-------------- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/components/TopCharts/TopCharts.jsx b/components/TopCharts/TopCharts.jsx index 4e05ef0..edd085a 100644 --- a/components/TopCharts/TopCharts.jsx +++ b/components/TopCharts/TopCharts.jsx @@ -1,9 +1,10 @@ import Link from 'next/link'; -import React from 'react'; +import React, { useEffect } from 'react'; import Image from 'next/image'; import { charts } from '../../data/data'; import AddBoxIcon from '@mui/icons-material/AddBox'; import { useStateContext } from '../../contexts/ContextProvider'; + const TopCharts = () => { const { setcurrentSong } = useStateContext(); diff --git a/pages/Explore.jsx b/pages/Explore.jsx index 1ea0268..7aa0901 100644 --- a/pages/Explore.jsx +++ b/pages/Explore.jsx @@ -1,7 +1,9 @@ +import { useEffect } from 'react'; import { TopArtists, Genres, TopCharts, Player, Trending } from '../components'; import { useStateContext } from '../contexts/ContextProvider'; +import axios from 'axios'; -const Explore = () => { +const Explore = ({ topCharts }) => { const { activeMenu, setActiveMenu } = useStateContext(); return ( @@ -16,10 +18,22 @@ const Explore = () => { - + ); }; export default Explore; + +export async function getStaticProps() { + const res = await axios.get('api/top/charts'); + const { data } = res; + // console.log('yoo', data); + + return { + props: { + topCharts: data, + }, + }; +} diff --git a/pages/api/top/charts.js b/pages/api/top/charts.js index 6574bd6..781e978 100644 --- a/pages/api/top/charts.js +++ b/pages/api/top/charts.js @@ -1,20 +1,22 @@ import axios from 'axios'; -const options = { - method: 'GET', - url: 'https://shazam.p.rapidapi.com/charts/track', - params: { pageSize: '5', startFrom: '5' }, - headers: { - 'X-RapidAPI-Key': '0ac7392c46msha4f3dfc287416ffp189c80jsnd7cf096105d4', - 'X-RapidAPI-Host': 'shazam.p.rapidapi.com', - }, -}; +export default async function handler(req, res) { + const options = { + method: 'GET', + url: 'https://shazam.p.rapidapi.com/charts/track', + params: { pageSize: '5', startFrom: '0' }, + headers: { + 'X-RapidAPI-Key': '0ac7392c46msha4f3dfc287416ffp189c80jsnd7cf096105d4', + 'X-RapidAPI-Host': 'shazam.p.rapidapi.com', + }, + }; -axios - .request(options) - .then(function (response) { - console.log(response.data); - }) - .catch(function (error) { - console.error(error); - }); + axios + .request(options) + .then(function (response) { + res.status(200).json(response.data); + }) + .catch(function (error) { + console.error(error); + }); +} From 2a99546384fcbcc4f6a23754ad8b93dd53e530eb Mon Sep 17 00:00:00 2001 From: aadarsh805 Date: Fri, 7 Oct 2022 21:05:53 +0530 Subject: [PATCH 3/5] made top charts to fetch dynamically using shazam api add images domain in next.config.js file --- components/TopCharts/TopCharts.jsx | 25 ++++++++++++++--------- next.config.js | 7 +++++-- pages/Explore.jsx | 32 +++++++++++++++++------------- pages/api/top/charts.js | 2 +- 4 files changed, 40 insertions(+), 26 deletions(-) diff --git a/components/TopCharts/TopCharts.jsx b/components/TopCharts/TopCharts.jsx index edd085a..3dc5599 100644 --- a/components/TopCharts/TopCharts.jsx +++ b/components/TopCharts/TopCharts.jsx @@ -5,9 +5,11 @@ import { charts } from '../../data/data'; import AddBoxIcon from '@mui/icons-material/AddBox'; import { useStateContext } from '../../contexts/ContextProvider'; -const TopCharts = () => { +const TopCharts = ({ topCharts }) => { const { setcurrentSong } = useStateContext(); + console.log(topCharts); + const selectSongHandler = (song) => { setcurrentSong((prev) => { return { @@ -26,7 +28,7 @@ const TopCharts = () => {
- {charts.map( + {topCharts.map( (chart, index) => index < 3 && (
{ key={chart.songName} onClick={() => selectSongHandler({ - image: chart.img, - title: chart.songName, - artist: chart.artistName, + image: chart?.images.coverart, + title: chart?.title, + artist: chart?.artists[0].alias, }) } >
- {chart.songName} + {chart?.title}

- {chart.songName} + {chart?.title}

- {chart.artistName} + {chart?.artists[0].alias}
- {chart.time} + 3:09

+ diff --git a/next.config.js b/next.config.js index ae88795..093ea33 100644 --- a/next.config.js +++ b/next.config.js @@ -2,6 +2,9 @@ const nextConfig = { reactStrictMode: true, swcMinify: true, -} + images: { + domains: ['is4-ssl.mzstatic.com','is5-ssl.mzstatic.com'], + }, +}; -module.exports = nextConfig +module.exports = nextConfig; \ No newline at end of file diff --git a/pages/Explore.jsx b/pages/Explore.jsx index 7aa0901..887b23f 100644 --- a/pages/Explore.jsx +++ b/pages/Explore.jsx @@ -1,10 +1,26 @@ -import { useEffect } from 'react'; +import { useEffect, useState } from 'react'; import { TopArtists, Genres, TopCharts, Player, Trending } from '../components'; import { useStateContext } from '../contexts/ContextProvider'; import axios from 'axios'; -const Explore = ({ topCharts }) => { +const Explore = () => { const { activeMenu, setActiveMenu } = useStateContext(); + const [topCharts, setTopCharts] = useState([]); + + // api fetch + const getTopCharts = async () => { + try { + const res = await axios.get('api/top/charts'); + const { data } = res; + setTopCharts(data.tracks); + } catch (error) { + console.log('yo', error); + } + }; + + useEffect(() => { + getTopCharts(); + }, []); return (

{ }; export default Explore; - -export async function getStaticProps() { - const res = await axios.get('api/top/charts'); - const { data } = res; - // console.log('yoo', data); - - return { - props: { - topCharts: data, - }, - }; -} diff --git a/pages/api/top/charts.js b/pages/api/top/charts.js index 781e978..160d8ae 100644 --- a/pages/api/top/charts.js +++ b/pages/api/top/charts.js @@ -4,7 +4,7 @@ export default async function handler(req, res) { const options = { method: 'GET', url: 'https://shazam.p.rapidapi.com/charts/track', - params: { pageSize: '5', startFrom: '0' }, + params: { pageSize: '5', startFrom: '10' }, headers: { 'X-RapidAPI-Key': '0ac7392c46msha4f3dfc287416ffp189c80jsnd7cf096105d4', 'X-RapidAPI-Host': 'shazam.p.rapidapi.com', From da07f83dc443d66c7da436d2515c30bcc0896b48 Mon Sep 17 00:00:00 2001 From: aadarsh805 Date: Fri, 7 Oct 2022 21:22:44 +0530 Subject: [PATCH 4/5] alright tracks are being fetch and rendered on topcharts maybe will need to set the req in getstaticprops func idk --- components/TopCharts/TopCharts.jsx | 4 ++-- pages/Explore.jsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/TopCharts/TopCharts.jsx b/components/TopCharts/TopCharts.jsx index 3dc5599..f937c03 100644 --- a/components/TopCharts/TopCharts.jsx +++ b/components/TopCharts/TopCharts.jsx @@ -47,8 +47,8 @@ const TopCharts = ({ topCharts }) => { {chart?.title}
diff --git a/pages/Explore.jsx b/pages/Explore.jsx index 887b23f..4840b80 100644 --- a/pages/Explore.jsx +++ b/pages/Explore.jsx @@ -12,7 +12,7 @@ const Explore = () => { try { const res = await axios.get('api/top/charts'); const { data } = res; - setTopCharts(data.tracks); + setTopCharts(data.tracks) } catch (error) { console.log('yo', error); } From 3d3dbdf7cb80edbc1f7c68ae94d97ccb77722bdc Mon Sep 17 00:00:00 2001 From: aadarsh805 Date: Fri, 7 Oct 2022 21:31:03 +0530 Subject: [PATCH 5/5] moved api key to env.local --- pages/api/top/charts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/api/top/charts.js b/pages/api/top/charts.js index 160d8ae..08680c9 100644 --- a/pages/api/top/charts.js +++ b/pages/api/top/charts.js @@ -6,7 +6,7 @@ export default async function handler(req, res) { url: 'https://shazam.p.rapidapi.com/charts/track', params: { pageSize: '5', startFrom: '10' }, headers: { - 'X-RapidAPI-Key': '0ac7392c46msha4f3dfc287416ffp189c80jsnd7cf096105d4', + 'X-RapidAPI-Key': NEXT_PUBLIC_RAPIDAPI_KEY, 'X-RapidAPI-Host': 'shazam.p.rapidapi.com', }, };