Fix Discord details url exceeding max length (#1620)

* fix discord details url exceeding max length
This commit is contained in:
das_
2026-01-29 06:08:00 +01:00
committed by GitHub
parent 796629b4e6
commit 590a7c7dfa
@@ -26,6 +26,7 @@ const discordRpc = isElectron() ? window.api.discordRpc : null;
type ActivityState = [QueueSong | undefined, number, PlayerStatus];
const MAX_FIELD_LENGTH = 127;
const MAX_URL_LENGTH = 256;
const truncate = (field: string) =>
field.length <= MAX_FIELD_LENGTH ? field : field.substring(0, MAX_FIELD_LENGTH - 1) + '…';
@@ -163,13 +164,19 @@ export const useDiscordRpc = () => {
) {
activity.stateUrl =
'https://www.last.fm/music/' + encodeURIComponent(song.artists[0].name);
activity.detailsUrl =
const detailsUrl =
'https://www.last.fm/music/' +
encodeURIComponent(song.albumArtists[0].name) +
'/' +
encodeURIComponent(song.album || '_') +
'/' +
encodeURIComponent(song.name);
// The details URL has a max length, only set it if it doesn't exceed it
if (detailsUrl.length <= MAX_URL_LENGTH) {
activity.detailsUrl = detailsUrl;
}
}
if (