fix: showing album images in Rich Presence

atleast try, lol.
This commit is contained in:
kmmiio99o 2026-07-26 16:01:01 +02:00
parent fc5eb71659
commit 7951d0083a
No known key found for this signature in database
GPG key ID: DCC0431E10FADBF1
4 changed files with 51 additions and 9 deletions

View file

@ -4,7 +4,7 @@ const Constants = {
DEFAULT_APP_NAME: "Music", DEFAULT_APP_NAME: "Music",
DEFAULT_TIME_INTERVAL: 5, DEFAULT_TIME_INTERVAL: 5,
// Discord application ID // Discord application ID
APPLICATION_ID: "1368513179272871956", APPLICATION_ID: "1054951789318909972",
// Don't check more than once every 3 seconds to avoid getting rate limited // Don't check more than once every 3 seconds to avoid getting rate limited
MIN_UPDATE_INTERVAL: 3, MIN_UPDATE_INTERVAL: 3,
// Libre.fm specifically requested a 1-minute minimum to reduce load // Libre.fm specifically requested a 1-minute minimum to reduce load

View file

@ -66,9 +66,6 @@ class PluginManager {
const serviceName = serviceFactory.getCurrentService().getServiceName(); const serviceName = serviceFactory.getCurrentService().getServiceName();
logVerbose(`Fetching latest track from ${serviceName}...`); logVerbose(`Fetching latest track from ${serviceName}...`);
// keep track of whether we actually need to update Discord
let willUpdateRPC = false;
try { try {
// Check if any ignored app is active // Check if any ignored app is active
if (currentSettings.ignoreList && currentSettings.ignoreList.length > 0) { if (currentSettings.ignoreList && currentSettings.ignoreList.length > 0) {
@ -122,8 +119,6 @@ class PluginManager {
return; return;
} }
willUpdateRPC = true;
log(`🎵 Track changed: ${lastTrack.artist} - ${lastTrack.name}`); log(`🎵 Track changed: ${lastTrack.artist} - ${lastTrack.name}`);
// set up timestamps for the track // set up timestamps for the track

View file

@ -10,6 +10,14 @@ export const AssetManager = findByProps("getAssetIds") as {
[key: PropertyKey]: any; [key: PropertyKey]: any;
}; };
// Discord's internal HTTP client — automatically includes auth token
export const HTTPUtils = findByProps("getAPIBaseURL", "get") as {
get: (opts: { url: string; query?: string; rejectWithError?: boolean; oldFormErrors?: boolean }) => Promise<any>;
post: (opts: { url: string; body?: any; rejectWithError?: boolean; oldFormErrors?: boolean }) => Promise<any>;
getAPIBaseURL: () => string;
[key: PropertyKey]: any;
};
export const SelfPresenceStore = findByStoreName("SelfPresenceStore") as { export const SelfPresenceStore = findByStoreName("SelfPresenceStore") as {
getActivities: () => any[]; getActivities: () => any[];
findActivity: (filter: (activity) => boolean) => any; findActivity: (filter: (activity) => boolean) => any;

View file

@ -4,7 +4,7 @@ import { pluginState } from "..";
import { Activity } from "../../../defs"; import { Activity } from "../../../defs";
import Constants from "../constants"; import Constants from "../constants";
import { stop } from "../manager"; import { stop } from "../manager";
import { AssetManager } from "../modules"; import { AssetManager, HTTPUtils } from "../modules";
/** Clears the user's activity */ /** Clears the user's activity */
export function clearActivity() { export function clearActivity() {
@ -28,7 +28,33 @@ export function sendRequest(activity: Activity | null) {
}); });
} }
/** Fetches Discord application assets */ async function resolveExternalAssets(
urls: string[],
appId: string,
): Promise<string[]> {
const baseUrl = HTTPUtils.getAPIBaseURL();
const endpoint = `${baseUrl}/applications/${appId}/external-assets`;
const resp = await HTTPUtils.post({
url: endpoint,
body: { urls },
oldFormErrors: true,
rejectWithError: false,
});
console.log("[Multi-Scrobbler] External assets response:", JSON.stringify(resp));
const body = resp?.body;
console.log("[Multi-Scrobbler] Response body:", JSON.stringify(body));
if (!Array.isArray(body)) return [];
return body.map(
(item: { url: string; external_asset_path: string }) =>
`mp:${item.external_asset_path}`,
);
}
/** Resolves external image URLs to Discord asset paths */
export async function fetchAsset( export async function fetchAsset(
asset: string[], asset: string[],
appId: string = Constants.APPLICATION_ID, appId: string = Constants.APPLICATION_ID,
@ -36,7 +62,20 @@ export async function fetchAsset(
if (!asset?.length) return []; if (!asset?.length) return [];
try { try {
return await AssetManager.fetchAssetIds(appId, asset); const result = await AssetManager.fetchAssetIds(appId, asset);
// If it returned an actual array with results, use it
if (Array.isArray(result) && result.length > 0 && result[0]) {
return result;
}
// fetchAssetIds returned empty/broken — try external-assets API
const externalUrls = asset.filter(
(url) => url && (url.startsWith("http:") || url.startsWith("https:")),
);
if (externalUrls.length === 0) return [];
return await resolveExternalAssets(externalUrls, appId);
} catch (error) { } catch (error) {
console.error("[Multi-Scrobbler] Failed to fetch assets:", error); console.error("[Multi-Scrobbler] Failed to fetch assets:", error);
return []; return [];