From 1ea178ea4be8392c9cdf82c6f43544a1d18a967d Mon Sep 17 00:00:00 2001 From: zen Date: Sat, 1 Feb 2025 11:56:06 +0800 Subject: [PATCH 1/4] feat(YNOProject): handle discord cache problem --- websites/Y/YNOProject/presence.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/websites/Y/YNOProject/presence.ts b/websites/Y/YNOProject/presence.ts index cb27603655be..0b3739a663dc 100644 --- a/websites/Y/YNOProject/presence.ts +++ b/websites/Y/YNOProject/presence.ts @@ -106,6 +106,8 @@ class GameState { /** * Resize pixelated image. Beware of high perf cost. + * The result image is unique even though it originates from the same source, + * for dealing with discord cache problem. * @param href url * @param dw destination width * @param dh destination height @@ -126,12 +128,30 @@ async function fetchWithResizePixelatedImage( canvas.width = dw; canvas.height = dh; const g = canvas.getContext("2d"); + g.fillStyle = `#${randomRGBColor()}01`; + g.fillRect(0, 0, 1, 1); g.imageSmoothingEnabled = false; g.drawImage(img, 0, 0, img.width, img.height, 0, 0, dw, dh); return new Promise(resolve => canvas.toBlob(resolve, "image/png")); }); } +/** + * Pick a random RGB color in hex + * @example "665557", "0fce53", "87c9db" + */ +function randomRGBColor() { + const colorInHex = Math.floor(Math.random() * 0xffffff).toString(16); + // Do the same as padStart(color, 6, "0") + const slot = Array.from(Array(6), () => "0"); + slot.splice( + slot.length - colorInHex.length, + colorInHex.length, + ...colorInHex.split("") + ); + return slot.join(""); +} + /** We still need this function for inspecting what format the image is in */ async function blob2dataurl(blob: Blob) { return new Promise((resolve, reject) => { @@ -211,9 +231,9 @@ class SimpleLRU { * Keys stand for characters' faces urls start with "blob", * and the values are their faces but large-scaled in Data URLs * - * In case of something glitches on re-sampling... + * In case of something glitches on re-sampling, or discord cache problem... * Switching to other effects for 5 times or taking any animated actions - * to let the oldest cache is re-generated. + * to evict the oldest cache. */ const characterFacesCache = new SimpleLRU(5), /** From 8eb6543f25c8921e69e7d55538888bb4224c98f3 Mon Sep 17 00:00:00 2001 From: zen Date: Sat, 1 Feb 2025 12:20:08 +0800 Subject: [PATCH 2/4] chore: fmt --- websites/A/Anghami/metadata.json | 6 +++--- websites/Y/YNOProject/presence.ts | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/websites/A/Anghami/metadata.json b/websites/A/Anghami/metadata.json index 92ff695db856..58d96440af46 100644 --- a/websites/A/Anghami/metadata.json +++ b/websites/A/Anghami/metadata.json @@ -7,9 +7,9 @@ }, "contributors": [ { - "name": "Aphex2in", - "id": "577284974001258507" - } + "name": "Aphex2in", + "id": "577284974001258507" + } ], "service": "Anghami", "altnames": [ diff --git a/websites/Y/YNOProject/presence.ts b/websites/Y/YNOProject/presence.ts index 6d0fad8e74fe..0a7209fa128b 100644 --- a/websites/Y/YNOProject/presence.ts +++ b/websites/Y/YNOProject/presence.ts @@ -141,9 +141,8 @@ async function fetchWithResizePixelatedImage( * @example "665557", "0fce53", "87c9db" */ function randomRGBColor() { - const colorInHex = Math.floor(Math.random() * 0xffffff).toString(16); - // Do the same as padStart(color, 6, "0") - const slot = Array.from(Array(6), () => "0"); + const colorInHex = Math.floor(Math.random() * 0xffffff).toString(16), + slot = Array.from(Array(6), () => "0"); slot.splice( slot.length - colorInHex.length, colorInHex.length, From cf47799f03b70bdb0ad945f53b1a13e6d6c53b5c Mon Sep 17 00:00:00 2001 From: zen Date: Sat, 1 Feb 2025 12:38:34 +0800 Subject: [PATCH 3/4] chore: versioning --- websites/A/Anghami/metadata.json | 2 +- websites/Y/YNOProject/metadata.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/websites/A/Anghami/metadata.json b/websites/A/Anghami/metadata.json index 58d96440af46..97193f7fce48 100644 --- a/websites/A/Anghami/metadata.json +++ b/websites/A/Anghami/metadata.json @@ -19,7 +19,7 @@ "en": "Make some noise, the world is listening." }, "url": "play.anghami.com", - "version": "1.4.0", + "version": "1.4.1", "logo": "https://cdn.rcd.gg/PreMiD/websites/A/Anghami/assets/logo.png", "thumbnail": "https://cdn.rcd.gg/PreMiD/websites/A/Anghami/assets/thumbnail.jpg", "color": "#FF00FE", diff --git a/websites/Y/YNOProject/metadata.json b/websites/Y/YNOProject/metadata.json index cfbbea483766..af9b958e0303 100644 --- a/websites/Y/YNOProject/metadata.json +++ b/websites/Y/YNOProject/metadata.json @@ -13,7 +13,7 @@ "ynoproject.net", "www.ynoproject.net" ], - "version": "1.0.3", + "version": "1.0.4", "logo": "https://cdn.rcd.gg/PreMiD/websites/Y/YNOProject/assets/logo.png", "thumbnail": "https://cdn.rcd.gg/PreMiD/websites/Y/YNOProject/assets/thumbnail.png", "color": "#785377", From bb96517a89b160437b80bbb29d8a544bde2f81ef Mon Sep 17 00:00:00 2001 From: zen Date: Sun, 2 Feb 2025 20:17:21 +0800 Subject: [PATCH 4/4] chore: syntactic sugarr --- websites/Y/YNOProject/presence.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/websites/Y/YNOProject/presence.ts b/websites/Y/YNOProject/presence.ts index 0a7209fa128b..b3552efdf7f6 100644 --- a/websites/Y/YNOProject/presence.ts +++ b/websites/Y/YNOProject/presence.ts @@ -146,7 +146,7 @@ function randomRGBColor() { slot.splice( slot.length - colorInHex.length, colorInHex.length, - ...colorInHex.split("") + ...colorInHex ); return slot.join(""); }