mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-26 01:20:27 +01:00
Fix changing state condition
This commit is contained in:
@@ -6,6 +6,7 @@ import { Artist, InternalPlayerResponse, PlayerResponse, SpotifyToken } from 'Ap
|
|||||||
import Song from 'App/Models/Song'
|
import Song from 'App/Models/Song'
|
||||||
import queryString from 'query-string'
|
import queryString from 'query-string'
|
||||||
import { updateGithubReadmeSpotify } from 'App/Utils/UpdateGithubReadme'
|
import { updateGithubReadmeSpotify } from 'App/Utils/UpdateGithubReadme'
|
||||||
|
import { diff } from 'deep-object-diff'
|
||||||
|
|
||||||
export async function getSpotifyAccount(): Promise<SpotifyToken> {
|
export async function getSpotifyAccount(): Promise<SpotifyToken> {
|
||||||
return await Redis.exists('spotify:account')
|
return await Redis.exists('spotify:account')
|
||||||
@@ -126,7 +127,8 @@ export async function getCurrentPlayingFromSpotify(): Promise<InternalPlayerResp
|
|||||||
current = { is_playing: false }
|
current = { is_playing: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((await Redis.get('spotify:current') as string) !== JSON.stringify(current))
|
const old_track: InternalPlayerResponse = JSON.parse(await Redis.get('spotify:current') || '{}')
|
||||||
|
if (old_track.is_playing !== current.is_playing || old_track.name !== current.name)
|
||||||
await updateCurrentSong(current)
|
await updateCurrentSong(current)
|
||||||
|
|
||||||
return current
|
return current
|
||||||
@@ -137,11 +139,12 @@ export async function resetCurrentSongCache(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function updateCurrentSong(song: InternalPlayerResponse): Promise<void> {
|
export async function updateCurrentSong(song: InternalPlayerResponse): Promise<void> {
|
||||||
// const current = JSON.parse(await Redis.get('spotify/current') as string)
|
const current = JSON.parse(await Redis.get('spotify/current') as string)
|
||||||
await Redis.set('spotify:current', JSON.stringify(song))
|
await Redis.set('spotify:current', JSON.stringify(song))
|
||||||
await updateGithubReadmeSpotify()
|
await updateGithubReadmeSpotify()
|
||||||
|
|
||||||
// const changed = diff(current, song)
|
const changed = diff(current, song)
|
||||||
|
console.log(changed)
|
||||||
// todo send message to Rabbit
|
// todo send message to Rabbit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user