refactor: improve image URL generation and enhance activity display
This commit is contained in:
parent
9a0619eeb5
commit
2319984d1d
1 changed files with 12 additions and 6 deletions
|
@ -16,6 +16,11 @@ const activityTypes: Record<number, string> = {
|
|||
};
|
||||
|
||||
const getImageUrl = (activity: LanyardActivity, size: "large" | "small") => {
|
||||
const width = size === "large" ? 120 : 40;
|
||||
if (!activity.assets || !activity.assets.large_image) {
|
||||
if (size === "large") return `https://dcdn.dstn.to/app-icons/${activity.application_id}?size=128`;
|
||||
}
|
||||
|
||||
if (!activity.assets) return null;
|
||||
|
||||
const image = activity.assets[`${size}_image`];
|
||||
|
@ -23,14 +28,15 @@ const getImageUrl = (activity: LanyardActivity, size: "large" | "small") => {
|
|||
if (!image) return null;
|
||||
|
||||
if (image.startsWith("mp:external")) {
|
||||
return `https://wsrv.nl/?w=${size === "large" ? 120 : 40}&url=https://${image.split("/").slice(3).join("/")}`.replace(
|
||||
"1280x1280",
|
||||
"160x160",
|
||||
); // last bit assumes tidal.
|
||||
return `https://wsrv.nl/?w=${width}&url=https://media.discordapp.net/${image.slice(3)}`
|
||||
}
|
||||
|
||||
if (image.startsWith("mp:app-assets")) {
|
||||
return `https://cdn.discordapp.com/${image.slice(3)}?size=${width}`;
|
||||
}
|
||||
|
||||
if (image.startsWith("mp:")) {
|
||||
return `https://cdn.discordapp.com/app-assets/${activity.application_id}/${image.slice(3)}.webp`;
|
||||
return `https://cdn.discordapp.com/app-assets/${activity.application_id}/${image.slice(3)}.webp?size=${width}`;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -68,7 +74,7 @@ export default () => {
|
|||
<mdui-card variant="filled" class={style.card}>
|
||||
{" "}
|
||||
<div class={style.activityCard}>
|
||||
<div class={style.status}>{activityTypes[activity.type]}</div>
|
||||
<div class={style.status}>{activityTypes[activity.type]}{!largeImage && ` ${activity.name}`}</div>
|
||||
<div class={style.content}>
|
||||
{largeImage && (
|
||||
<div class={style.bigImage}>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue