mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-09 20:29:36 +02:00
Fix Discord details url exceeding max length (#1620)
* fix discord details url exceeding max length
This commit is contained in:
@@ -26,6 +26,7 @@ const discordRpc = isElectron() ? window.api.discordRpc : null;
|
|||||||
type ActivityState = [QueueSong | undefined, number, PlayerStatus];
|
type ActivityState = [QueueSong | undefined, number, PlayerStatus];
|
||||||
|
|
||||||
const MAX_FIELD_LENGTH = 127;
|
const MAX_FIELD_LENGTH = 127;
|
||||||
|
const MAX_URL_LENGTH = 256;
|
||||||
|
|
||||||
const truncate = (field: string) =>
|
const truncate = (field: string) =>
|
||||||
field.length <= MAX_FIELD_LENGTH ? field : field.substring(0, MAX_FIELD_LENGTH - 1) + '…';
|
field.length <= MAX_FIELD_LENGTH ? field : field.substring(0, MAX_FIELD_LENGTH - 1) + '…';
|
||||||
@@ -163,13 +164,19 @@ export const useDiscordRpc = () => {
|
|||||||
) {
|
) {
|
||||||
activity.stateUrl =
|
activity.stateUrl =
|
||||||
'https://www.last.fm/music/' + encodeURIComponent(song.artists[0].name);
|
'https://www.last.fm/music/' + encodeURIComponent(song.artists[0].name);
|
||||||
activity.detailsUrl =
|
|
||||||
|
const detailsUrl =
|
||||||
'https://www.last.fm/music/' +
|
'https://www.last.fm/music/' +
|
||||||
encodeURIComponent(song.albumArtists[0].name) +
|
encodeURIComponent(song.albumArtists[0].name) +
|
||||||
'/' +
|
'/' +
|
||||||
encodeURIComponent(song.album || '_') +
|
encodeURIComponent(song.album || '_') +
|
||||||
'/' +
|
'/' +
|
||||||
encodeURIComponent(song.name);
|
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 (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user