Update spotify connection

This commit is contained in:
2022-01-17 16:51:49 +01:00
parent 9e822ba674
commit f02635b83c
13 changed files with 130 additions and 88 deletions

View File

@@ -1,11 +1,11 @@
import Logger from '@ioc:Adonis/Core/Logger'
import { getCurrentPlayingFromSpotify, getSpotifyAccount } from 'App/Utils/SongUtils'
const MS = 1000
const MS = 3000
let taskId
async function SpotifyCurrentListeningWatcher(): Promise<void> {
if (getSpotifyAccount().access === '') return
if ((await getSpotifyAccount()).access_token === '') return
await getCurrentPlayingFromSpotify()
}

View File

@@ -12,15 +12,16 @@ async function LogSpotifyHistory(): Promise<void> {
if (current.progress && current.progress < 1000) return
const last_entry = await Song.query().where('id', current.id!).orderBy('date', 'desc').first()
const last_entry = await Song.query().where('item_id', current.id!).orderBy('date', 'desc').first()
if (last_entry && new Date().getTime() - last_entry.duration <= new Date(last_entry.date).getTime()) return
await Song.create({
date: current.started_at,
date: new Date(current.started_at!),
duration: current.duration,
item_name: current.name,
item_type: current.type,
item_id: current.id,
author: current.author,
device_name: current.device_name,
device_type: current.device_type,