chore: url fixes

This commit is contained in:
Cory Dransfeldt 2024-03-30 09:12:06 -07:00
parent ba389dab59
commit c6f9ec7ced
No known key found for this signature in database
4 changed files with 20 additions and 10 deletions

View file

@ -3,8 +3,13 @@ import { DateTime } from 'luxon'
const sanitizeMediaString = (string) => { const sanitizeMediaString = (string) => {
const normalizedStr = string.normalize('NFD'); const normalizedStr = string.normalize('NFD');
return normalizedStr.replace(/[\u0300-\u036f]/g, '').replace(/\.{3}/g, ''); return normalizedStr
}; .replace(/[\u0300-\u036f]/g, '')
.replace(/[\u2010]/g, '-')
.replace(/\.{3}/g, '')
.replace(/\?/g, '')
.replace(/[\(\)\[\]\{\}]/g, '')
}
const weekStop = () => { const weekStop = () => {
const currentDate = DateTime.now() const currentDate = DateTime.now()
@ -59,7 +64,7 @@ export default async (request) => {
// if there is no artist blob, populate one // if there is no artist blob, populate one
if (!artistInfo) { if (!artistInfo) {
const artistRes = await fetch( const artistRes = await fetch(
`https://ws.audioscrobbler.com/2.0/?method=artist.getInfo&api_key=${MUSIC_KEY}&artist=${encodeURIComponent(sanitizeMediaString(artist).replace(/\s+/g, '+').toLowerCase())}&format=json`, `https://ws.audioscrobbler.com/2.0/?method=artist.getInfo&api_key=${MUSIC_KEY}&artist=${sanitizeMediaString(artist).replace(/\s+/g, '+').toLowerCase()}&format=json`,
{ {
type: "json", type: "json",
} }
@ -123,8 +128,8 @@ export default async (request) => {
const mbid = albumRes['album']['mbid'] || '' const mbid = albumRes['album']['mbid'] || ''
const albumObj = { const albumObj = {
mbid, mbid,
image: `https://cdn.coryd.dev/albums/${encodeURIComponent(sanitizeMediaString(artist).replace(/\s+/g, '-').toLowerCase())}-${encodeURIComponent(sanitizeMediaString(album.replace(/[:\/\\,'']+/g image: `https://cdn.coryd.dev/albums/${sanitizeMediaString(artist).replace(/\s+/g, '-').toLowerCase()}-${sanitizeMediaString(album.replace(/[:\/\\,'']+/g
, '').replace(/\s+/g, '-').toLowerCase()))}.jpg` , '').replace(/\s+/g, '-').toLowerCase())}.jpg`
} }
await albums.setJSON(albumKey, albumObj) await albums.setJSON(albumKey, albumObj)
} }

View file

@ -10,8 +10,8 @@ export default async function () {
artist: artistCapitalization(album['artist']['name']), artist: artistCapitalization(album['artist']['name']),
plays: album['playcount'], plays: album['playcount'],
rank: album['@attr']['rank'], rank: album['@attr']['rank'],
image: `https://cdn.coryd.dev/albums/${encodeURIComponent(sanitizeMediaString(album['artist']['name']).replace(/\s+/g, '-').toLowerCase())}-${encodeURIComponent(sanitizeMediaString(album['name'].replace(/[:\/\\,'']+/g image: `https://cdn.coryd.dev/albums/${sanitizeMediaString(album['artist']['name']).replace(/\s+/g, '-').toLowerCase()}-${sanitizeMediaString(album['name'].replace(/[:\/\\,'']+/g
, '').replace(/\s+/g, '-').toLowerCase()))}.jpg`, , '').replace(/\s+/g, '-').toLowerCase())}.jpg`,
url: album['mbid'] url: album['mbid']
? `https://musicbrainz.org/album/${album['mbid']}` ? `https://musicbrainz.org/album/${album['mbid']}`
: `https://musicbrainz.org/taglookup/index?tag-lookup.artist=${album['artist'][ : `https://musicbrainz.org/taglookup/index?tag-lookup.artist=${album['artist'][

View file

@ -14,7 +14,7 @@ export default async function () {
title: artistCapitalization(artist['name']), title: artistCapitalization(artist['name']),
plays: artist['playcount'], plays: artist['playcount'],
rank: artist['@attr']['rank'], rank: artist['@attr']['rank'],
image: `https://cdn.coryd.dev/artists/${encodeURIComponent(sanitizeMediaString(artist['name']).replace(/\s+/g, '-').toLowerCase())}.jpg`, image: `https://cdn.coryd.dev/artists/${sanitizeMediaString(artist['name']).replace(/\s+/g, '-').toLowerCase()}.jpg`,
url: mbid url: mbid
? `https://musicbrainz.org/artist/${mbid}` ? `https://musicbrainz.org/artist/${mbid}`
: `https://musicbrainz.org/search?query=${artist['name'].replace( : `https://musicbrainz.org/search?query=${artist['name'].replace(

View file

@ -5,7 +5,12 @@ export const artistCapitalization = (artist) => artistCapitalizationPatches[arti
export const sanitizeMediaString = (string) => { export const sanitizeMediaString = (string) => {
const normalizedStr = string.normalize('NFD'); const normalizedStr = string.normalize('NFD');
return normalizedStr.replace(/[\u0300-\u036f]/g, '').replace(/\.{3}/g, ''); return normalizedStr
}; .replace(/[\u0300-\u036f]/g, '')
.replace(/[\u2010]/g, '-')
.replace(/\.{3}/g, '')
.replace(/\?/g, '')
.replace(/[\(\)\[\]\{\}]/g, '')
}
export const mbidMap = (artist) => mbidPatches[artist.toLowerCase()] || '' export const mbidMap = (artist) => mbidPatches[artist.toLowerCase()] || ''