fix: debug caching
This commit is contained in:
parent
f6b52826a8
commit
7d80a441d7
1 changed files with 16 additions and 24 deletions
|
@ -1,9 +1,9 @@
|
||||||
const { S3Client, GetObjectCommand, PutObjectCommand } = require('@aws-sdk/client-s3')
|
const { S3Client, GetObjectCommand, PutObjectCommand } = require('@aws-sdk/client-s3')
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
const { AssetCache } = require('@11ty/eleventy-fetch')
|
|
||||||
const artistAliases = require('./json/artist-aliases.json')
|
const artistAliases = require('./json/artist-aliases.json')
|
||||||
const titleCaseExceptions = require('./json/title-case-exceptions.json')
|
const titleCaseExceptions = require('./json/title-case-exceptions.json')
|
||||||
const { getReadableData } = require('../utils/aws')
|
const { getReadableData } = require('../utils/aws')
|
||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accepts a string representing an artist name, checks to see if said artist name
|
* Accepts a string representing an artist name, checks to see if said artist name
|
||||||
|
@ -55,7 +55,7 @@ const titleCase = (string) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const diffTracks = (cache, tracks) => {
|
const diffTracks = (cache, tracks) => {
|
||||||
const trackCompareSet = Object.values(tracks).sort((a, b) => a.time - b.time)
|
const trackCompareSet = Object.values(tracks)
|
||||||
const cacheCompareSet = Object.values(cache).sort((a, b) => a.time - b.time)
|
const cacheCompareSet = Object.values(cache).sort((a, b) => a.time - b.time)
|
||||||
const diffedTracks = {}
|
const diffedTracks = {}
|
||||||
|
|
||||||
|
@ -87,24 +87,20 @@ const formatTracks = (tracks, time) => {
|
||||||
const artistFormatted = titleCase(aliasArtist(track.attributes['artistName']))
|
const artistFormatted = titleCase(aliasArtist(track.attributes['artistName']))
|
||||||
const albumFormatted = titleCase(sanitizeMedia(track.attributes['albumName']))
|
const albumFormatted = titleCase(sanitizeMedia(track.attributes['albumName']))
|
||||||
const trackFormatted = sanitizeMedia(track.attributes['name'])
|
const trackFormatted = sanitizeMedia(track.attributes['name'])
|
||||||
if (!formattedTracks[track.attributes.name]) {
|
formattedTracks[`${track.id}-${time}`] = {
|
||||||
formattedTracks[track.attributes.name] = {
|
name: trackFormatted,
|
||||||
name: trackFormatted,
|
artist: artistFormatted,
|
||||||
artist: artistFormatted,
|
album: albumFormatted,
|
||||||
album: albumFormatted,
|
art: track.attributes.artwork.url.replace('{w}', '300').replace('{h}', '300'),
|
||||||
art: track.attributes.artwork.url.replace('{w}', '300').replace('{h}', '300'),
|
url:
|
||||||
url:
|
track['relationships'] && track['relationships'].albums.data.length > 0
|
||||||
track['relationships'] && track['relationships'].albums.data.length > 0
|
? `https://song.link/${track['relationships'].albums.data.pop().attributes.url}`
|
||||||
? `https://song.link/${track['relationships'].albums.data.pop().attributes.url}`
|
: `https://rateyourmusic.com/search?searchtype=l&searchterm=${encodeURI(
|
||||||
: `https://rateyourmusic.com/search?searchtype=l&searchterm=${encodeURI(
|
albumFormatted
|
||||||
albumFormatted
|
)}%20${encodeURI(artistFormatted)}`,
|
||||||
)}%20${encodeURI(artistFormatted)}`,
|
id: track.id,
|
||||||
id: track.id,
|
time,
|
||||||
time,
|
duration: track.attributes['durationInMillis'],
|
||||||
duration: track.attributes['durationInMillis'],
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
formattedTracks[track.attributes.name].plays++
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return formattedTracks
|
return formattedTracks
|
||||||
|
@ -177,7 +173,6 @@ module.exports = async function () {
|
||||||
.then((data) => data.json())
|
.then((data) => data.json())
|
||||||
.catch()
|
.catch()
|
||||||
const APPLE_TOKEN = APPLE_TOKEN_RESPONSE['music-token']
|
const APPLE_TOKEN = APPLE_TOKEN_RESPONSE['music-token']
|
||||||
const asset = new AssetCache('recent_tracks_data')
|
|
||||||
const PAGE_SIZE = 30
|
const PAGE_SIZE = 30
|
||||||
const PAGES = 10
|
const PAGES = 10
|
||||||
const time = Number(new Date())
|
const time = Number(new Date())
|
||||||
|
@ -189,8 +184,6 @@ module.exports = async function () {
|
||||||
let res = []
|
let res = []
|
||||||
let hasNextPage = true
|
let hasNextPage = true
|
||||||
|
|
||||||
if (asset.isCacheValid('1h')) return await asset.getCachedValue()
|
|
||||||
|
|
||||||
while (CURRENT_PAGE < PAGES && hasNextPage) {
|
while (CURRENT_PAGE < PAGES && hasNextPage) {
|
||||||
const URL = `https://api.music.apple.com/v1/me/recent/played/tracks?limit=${PAGE_SIZE}&offset=${
|
const URL = `https://api.music.apple.com/v1/me/recent/played/tracks?limit=${PAGE_SIZE}&offset=${
|
||||||
PAGE_SIZE * CURRENT_PAGE
|
PAGE_SIZE * CURRENT_PAGE
|
||||||
|
@ -240,6 +233,5 @@ module.exports = async function () {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
await asset.save(charts, 'json')
|
|
||||||
return charts
|
return charts
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue