Skip to content

Commit

Permalink
fix(AssetManager): deleting should now actually work (PreMiD#7554)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bas950 authored Aug 7, 2023
1 parent d8de795 commit 78eea47
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
11 changes: 8 additions & 3 deletions tools/auto/assetsUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,17 @@ if (deletedPresenceFolders.length) {
for (const folder of deletedPresenceFolders) {
const start = Date.now(),
assetsManager = new AssetsManager(folder),
allAssets = await assetsManager.allAssets(),
allAssets = await assetsManager.getCdnAssets(),
assets = [
allAssets.logo,
allAssets.thumbnail,
...allAssets.assets,
].filter(asset => asset.startsWith(assetsManager.assetBaseUrl));
allAssets.assets ? [...allAssets.assets.values()] : [],
]
.flat()
.filter(
(asset): asset is string =>
!!asset && asset.startsWith(assetsManager.assetBaseUrl)
);

if (!assets.length) {
actions.info(
Expand Down
13 changes: 7 additions & 6 deletions tools/classes/AssetsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import sharp from "sharp";
import { lookup as mimeLookup } from "mime-types";

import { Metadata } from "./PresenceCompiler";
import { getFolderLetter } from "../util";

const require = createRequire(import.meta.url),
rootPath = resolve(fileURLToPath(new URL(".", import.meta.url)), "../.."),
Expand All @@ -22,7 +23,6 @@ const require = createRequire(import.meta.url),

export default class AssetsManager {
cwd: string;
presenceFolder: string;

constructor(
public service: string,
Expand All @@ -31,7 +31,6 @@ export default class AssetsManager {
}
) {
this.cwd = options?.cwd ?? rootPath;
this.presenceFolder = this.getPresenceFolder();
}

get assetBaseUrl() {
Expand All @@ -40,10 +39,12 @@ export default class AssetsManager {
).replace("#", "%23")}/assets`;
}

getPresenceFolder() {
return glob
.sync(`{websites,programs}/**/${this.service}`)[0]
.replace(/\\/g, "/");
get presenceFolder() {
//TODO Detect if the presence is a website or a program without using glob since the file may not exist anymore at this point
const type: "websites" | "programs" = "websites";
return `${this.cwd}/${type}/${getFolderLetter(this.service)}/${
this.service
}`;
}

getFileExtension(url: string) {
Expand Down
6 changes: 3 additions & 3 deletions websites/A/aniwave/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
},
"url": "aniwave.to",
"regExp": "([a-z0-9-]+[.*])?(aniwave(.*)?[.][a-z]+)",
"version": "1.0.0",
"logo": "https://i.imgur.com/akfxN5c.png",
"thumbnail": "https://i.imgur.com/dgxPb4E.png",
"version": "1.0.1",
"logo": "https://cdn.rcd.gg/PreMiD/websites/A/aniwave/assets/logo.png",
"thumbnail": "https://cdn.rcd.gg/PreMiD/websites/A/aniwave/assets/thumbnail.png",
"color": "#694ba1",
"category": "anime",
"tags": [
Expand Down
2 changes: 1 addition & 1 deletion websites/A/aniwave/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const presence = new Presence({
});

const enum Assets {
Logo = "https://i.imgur.com/akfxN5c.png",
Logo = "https://cdn.rcd.gg/PreMiD/websites/A/aniwave/assets/logo.png",
}

let video = {
Expand Down
6 changes: 3 additions & 3 deletions websites/K/Kick/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"kick.com",
"help.kick.com"
],
"version": "1.0.0",
"logo": "https://i.imgur.com/7pAQJgm.png",
"thumbnail": "https://i.imgur.com/DrveDUP.png",
"version": "1.0.1",
"logo": "https://cdn.rcd.gg/PreMiD/websites/K/Kick/assets/logo.png",
"thumbnail": "https://cdn.rcd.gg/PreMiD/websites/K/Kick/assets/thumbnail.png",
"color": "#53fc18",
"category": "videos",
"tags": [
Expand Down
2 changes: 1 addition & 1 deletion websites/K/Kick/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const presence = new Presence({ clientId: "1125405319594512404" }),
browsingTimestamp = Math.floor(Date.now() / 1000);

const enum Assets {
Logo = "https://i.imgur.com/7pAQJgm.png",
Logo = "https://cdn.rcd.gg/PreMiD/websites/K/Kick/assets/logo.png",
}

presence.on("UpdateData", async () => {
Expand Down

0 comments on commit 78eea47

Please sign in to comment.