mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-30 11:27:50 +01:00
Edit tasks
This commit is contained in:
@@ -1,13 +1,18 @@
|
|||||||
import Logger from '@ioc:Adonis/Core/Logger'
|
import Logger from '@ioc:Adonis/Core/Logger'
|
||||||
import { getCurrentPlayingFromSpotify } from 'App/Utils/SongUtils'
|
import { getCurrentPlayingFromSpotify, getSpotifyAccount } from 'App/Utils/SongUtils'
|
||||||
|
|
||||||
const MS = 1000
|
const MS = 1000
|
||||||
let taskId
|
let taskId
|
||||||
|
|
||||||
|
async function SpotifyCurrentListeningWatcher(): Promise<void> {
|
||||||
|
if (getSpotifyAccount().access === '') return
|
||||||
|
await getCurrentPlayingFromSpotify()
|
||||||
|
}
|
||||||
|
|
||||||
export async function Activate(): Promise<void> {
|
export async function Activate(): Promise<void> {
|
||||||
Logger.info(`Starting task runner for watching spotify current playing [${MS} ms]`)
|
Logger.info(`Starting task runner for watching spotify current playing [${MS} ms]`)
|
||||||
await getCurrentPlayingFromSpotify()
|
await SpotifyCurrentListeningWatcher()
|
||||||
taskId = setInterval(getCurrentPlayingFromSpotify, MS)
|
taskId = setInterval(SpotifyCurrentListeningWatcher, MS)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ShutDown(): void {
|
export function ShutDown(): void {
|
||||||
|
|||||||
@@ -5,10 +5,8 @@ import Redis from '@ioc:Adonis/Addons/Redis'
|
|||||||
import { SpotifyArtist, SpotifyTrack } from 'App/Types/ILocalSpotify'
|
import { SpotifyArtist, SpotifyTrack } from 'App/Types/ILocalSpotify'
|
||||||
import { Artist, InternalPlayerResponse, PlayerResponse, SpotifyToken } from 'App/Types/ISpotify'
|
import { Artist, InternalPlayerResponse, PlayerResponse, SpotifyToken } from 'App/Types/ISpotify'
|
||||||
import Song from 'App/Models/Song'
|
import Song from 'App/Models/Song'
|
||||||
import Logger from '@ioc:Adonis/Core/Logger'
|
|
||||||
|
|
||||||
export function getSpotifyAccount(): { access: string; refresh: string } {
|
export function getSpotifyAccount(): { access: string; refresh: string } {
|
||||||
Logger.info(JSON.parse(readFileSync('spotify.json').toString()))
|
|
||||||
return JSON.parse(readFileSync('spotify.json').toString())
|
return JSON.parse(readFileSync('spotify.json').toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,7 +18,6 @@ export function getAuthorizationURI(): string {
|
|||||||
redirect_uri: `${Env.get('BASE_URL')}/spotify/callback`,
|
redirect_uri: `${Env.get('BASE_URL')}/spotify/callback`,
|
||||||
})
|
})
|
||||||
|
|
||||||
Logger.info(`https://accounts.spotify.com/authorize?${query}`)
|
|
||||||
return `https://accounts.spotify.com/authorize?${query}`
|
return `https://accounts.spotify.com/authorize?${query}`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,8 +37,6 @@ export async function setupSpotify(code: string): Promise<void> {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
Logger.info(String(authorization_tokens))
|
|
||||||
|
|
||||||
if (authorization_tokens.status === 200) {
|
if (authorization_tokens.status === 200) {
|
||||||
writeFileSync(
|
writeFileSync(
|
||||||
'spotify.json',
|
'spotify.json',
|
||||||
@@ -55,7 +50,6 @@ export async function setupSpotify(code: string): Promise<void> {
|
|||||||
|
|
||||||
export async function regenerateTokens(): Promise<void> {
|
export async function regenerateTokens(): Promise<void> {
|
||||||
const refresh_token = getSpotifyAccount().refresh
|
const refresh_token = getSpotifyAccount().refresh
|
||||||
Logger.info(refresh_token)
|
|
||||||
|
|
||||||
const authorization_tokens: AxiosResponse<SpotifyToken> = await axios.post(
|
const authorization_tokens: AxiosResponse<SpotifyToken> = await axios.post(
|
||||||
'https://accounts.spotify.com/api/token',
|
'https://accounts.spotify.com/api/token',
|
||||||
@@ -71,7 +65,6 @@ export async function regenerateTokens(): Promise<void> {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
Logger.info(String(authorization_tokens))
|
|
||||||
if (authorization_tokens.status === 200) {
|
if (authorization_tokens.status === 200) {
|
||||||
writeFileSync(
|
writeFileSync(
|
||||||
'spotify.json',
|
'spotify.json',
|
||||||
|
|||||||
Reference in New Issue
Block a user