From b9b42c5ea7192c0ee3851cc5dfe20b472db803f4 Mon Sep 17 00:00:00 2001 From: bravo68web Date: Mon, 21 Feb 2022 17:46:39 +0530 Subject: [PATCH] Added Spotify Support --- .env.example | 20 +++++++++++++++++++- src/api/spotify/controller.js | 25 +++++++++++++++++++++++-- src/api/spotify/index.js | 11 +++++------ src/api/youtube/controller.js | 1 - 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index 81ab3c2..80be87c 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,19 @@ -MASTER_KEY=masterKey +# API Webserver +MASTER_KEY= +PORT= + +# Spotify API +SPOTIFY_API_AUTH_KEY= +SPOTIFY_REFRESH_TOKEN= + +# Osu! API +OSU_API_KEY= +OSU_API_CLIENT_ID= +OSU_API_CLIENT_SECRET= + +# Youtube API +YOUTUBE_API_KEY= + +# Bravo68web API Key +B68W_API_EMAIL= +B68W_API_KEY= diff --git a/src/api/spotify/controller.js b/src/api/spotify/controller.js index 4f30e31..f5e697b 100644 --- a/src/api/spotify/controller.js +++ b/src/api/spotify/controller.js @@ -1,3 +1,24 @@ -export const show = ({ params }, res, next) => { - res.status(200).json({}); +import axios from "axios"; +const { v2 } = require("osu-api-extended"); + +v2.login(process.env.OSU_API_CLIENT_ID, process.env.OSU_API_CLIENT_SECRET); + +export const show = (req, res, next) => { + var config = { + method: "get", + url: `http://bravo68web-api.herokuapp.com/api/private/spotify/track/${req.params.trackID}`, + headers: { + apikey: process.env.B68W_API_KEY, + email: process.env.B68W_API_EMAIL, + }, + }; + + axios(config) + .then(async function (response) { + const data = await v2.beatmaps.search({ query: response.data.name.name }); + res.json(data); + }) + .catch(function (err) { + res.status(500).json({ error: err.message }); + }); }; diff --git a/src/api/spotify/index.js b/src/api/spotify/index.js index aa11593..0a140cd 100644 --- a/src/api/spotify/index.js +++ b/src/api/spotify/index.js @@ -1,7 +1,7 @@ -import { Router } from 'express' -import { show } from './controller' +import { Router } from "express"; +import { show } from "./controller"; -const router = new Router() +const router = new Router(); /** * @api {get} /spot/:id Retrieve spotify @@ -11,7 +11,6 @@ const router = new Router() * @apiError {Object} 400 Some parameters may contain invalid values. * @apiError 404 Spotify not found. */ -router.get('/:id', - show) +router.get("/:trackID", show); -export default router +export default router; diff --git a/src/api/youtube/controller.js b/src/api/youtube/controller.js index 48305e8..6bf80d8 100644 --- a/src/api/youtube/controller.js +++ b/src/api/youtube/controller.js @@ -26,7 +26,6 @@ export const show = ({ params }, res, next) => { title = videoTitle.substring(0, bracketIndex); } const data = await v2.beatmaps.search({ query: title }); - console.log(title); res.json(data); }) .catch(function (error) {