mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-11 03:24:16 +00:00
added spotify search endpoint
This commit is contained in:
parent
3f88523be7
commit
0890b5fba6
@ -143,6 +143,55 @@ export default class SyncController extends Controller {
|
|||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (response) {
|
||||||
|
return res.json(response.data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/spotify/search": {
|
||||||
|
middlewares: ["withAuthentication"],
|
||||||
|
fn: async (req, res) => {
|
||||||
|
const user_id = req.user._id.toString()
|
||||||
|
const authToken = await SecureSyncEntry.get(user_id, "spotify_access_token")
|
||||||
|
|
||||||
|
if (!authToken) {
|
||||||
|
return res.status(400).json({
|
||||||
|
message: "Missing auth token",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const { query, type, limit, offset } = req.query
|
||||||
|
|
||||||
|
if (!query) {
|
||||||
|
return res.status(400).json({
|
||||||
|
message: "Missing query",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!type) {
|
||||||
|
return res.status(400).json({
|
||||||
|
message: "Missing type",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await axios.get("https://api.spotify.com/v1/search", {
|
||||||
|
headers: {
|
||||||
|
"Authorization": `Bearer ${authToken}`
|
||||||
|
},
|
||||||
|
params: {
|
||||||
|
q: query,
|
||||||
|
type: type,
|
||||||
|
limit: limit,
|
||||||
|
offset: offset,
|
||||||
|
}
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error(error.response.data)
|
||||||
|
|
||||||
|
res.status(error.response.status).json(error.response.data)
|
||||||
|
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
if (response) {
|
if (response) {
|
||||||
return res.json(response.data)
|
return res.json(response.data)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user