mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-21 15:31:35 +01:00
Connect Athena to Spotify
This commit is contained in:
44
app/Controllers/Http/SongsController.ts
Normal file
44
app/Controllers/Http/SongsController.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import {
|
||||
fetchTopArtist,
|
||||
fetchTopTrack,
|
||||
getAuthorizationURI,
|
||||
getCurrentPlayingFromCache,
|
||||
getHistory,
|
||||
setupSpotify,
|
||||
} from 'App/Utils/SongUtils'
|
||||
import SongHistoryValidator from 'App/Validators/song/SongHistoryValidator'
|
||||
|
||||
export default class SongsController {
|
||||
public async getCurrentSong({ response }: HttpContextContract) {
|
||||
return response.status(200).send(getCurrentPlayingFromCache())
|
||||
}
|
||||
|
||||
public async getHistory({ request, response }: HttpContextContract) {
|
||||
const { range } = await request.validate(SongHistoryValidator)
|
||||
const history = await getHistory(range)
|
||||
return response.status(200).send({
|
||||
history,
|
||||
})
|
||||
}
|
||||
|
||||
public async getTopTrack({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
tracks: await fetchTopTrack(),
|
||||
})
|
||||
}
|
||||
|
||||
public async getTopArtist({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
tracks: await fetchTopArtist(),
|
||||
})
|
||||
}
|
||||
|
||||
public async authorize({ response }: HttpContextContract) {
|
||||
return response.status(200).redirect(getAuthorizationURI())
|
||||
}
|
||||
|
||||
public async callback({ request }: HttpContextContract) {
|
||||
await setupSpotify(request.param('code'))
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Redis from '@ioc:Adonis/Addons/Redis'
|
||||
import StateSleepingValidator from 'App/Validators/states/StateSleepingValidator'
|
||||
import { getCurrentPlayingFromCache } from 'App/Utils/SongUtils'
|
||||
|
||||
export default class StatesController {
|
||||
// Listening Music
|
||||
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const sleeping = this.formatValue(await Redis.get('states:sleeping'))
|
||||
const developing = this.formatValue(await Redis.get('states:developing'))
|
||||
return response.status(200).send({
|
||||
sleeping,
|
||||
developing,
|
||||
listening_music: 'Soon',
|
||||
listening_music: await getCurrentPlayingFromCache(),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user