mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-31 23:01:02 +00:00
fix: cleaned comments and simplified function
This commit is contained in:
@@ -14,18 +14,22 @@ const removeGameFromLibrary = async (
|
|||||||
if (game) {
|
if (game) {
|
||||||
// Collect asset paths that need to be cleaned up before marking as deleted
|
// Collect asset paths that need to be cleaned up before marking as deleted
|
||||||
const assetPathsToDelete: string[] = [];
|
const assetPathsToDelete: string[] = [];
|
||||||
|
|
||||||
const assetUrls = game.shop === "custom"
|
const assetUrls =
|
||||||
? [game.iconUrl, game.logoImageUrl, game.libraryHeroImageUrl]
|
game.shop === "custom"
|
||||||
: [game.customIconUrl, game.customLogoImageUrl, game.customHeroImageUrl];
|
? [game.iconUrl, game.logoImageUrl, game.libraryHeroImageUrl]
|
||||||
|
: [
|
||||||
assetUrls.forEach(url => {
|
game.customIconUrl,
|
||||||
|
game.customLogoImageUrl,
|
||||||
|
game.customHeroImageUrl,
|
||||||
|
];
|
||||||
|
|
||||||
|
assetUrls.forEach((url) => {
|
||||||
if (url?.startsWith("local:")) {
|
if (url?.startsWith("local:")) {
|
||||||
assetPathsToDelete.push(url.replace("local:", ""));
|
assetPathsToDelete.push(url.replace("local:", ""));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const updatedGame = {
|
const updatedGame = {
|
||||||
...game,
|
...game,
|
||||||
isDeleted: true,
|
isDeleted: true,
|
||||||
@@ -39,13 +43,12 @@ const removeGameFromLibrary = async (
|
|||||||
|
|
||||||
await gamesSublevel.put(gameKey, updatedGame);
|
await gamesSublevel.put(gameKey, updatedGame);
|
||||||
|
|
||||||
|
|
||||||
if (game.shop !== "custom") {
|
if (game.shop !== "custom") {
|
||||||
const existingAssets = await gamesShopAssetsSublevel.get(gameKey);
|
const existingAssets = await gamesShopAssetsSublevel.get(gameKey);
|
||||||
if (existingAssets) {
|
if (existingAssets) {
|
||||||
const resetAssets = {
|
const resetAssets = {
|
||||||
...existingAssets,
|
...existingAssets,
|
||||||
title: existingAssets.title,
|
title: existingAssets.title,
|
||||||
};
|
};
|
||||||
await gamesShopAssetsSublevel.put(gameKey, resetAssets);
|
await gamesShopAssetsSublevel.put(gameKey, resetAssets);
|
||||||
}
|
}
|
||||||
@@ -55,7 +58,6 @@ const removeGameFromLibrary = async (
|
|||||||
HydraApi.delete(`/profile/games/${game.remoteId}`).catch(() => {});
|
HydraApi.delete(`/profile/games/${game.remoteId}`).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (assetPathsToDelete.length > 0) {
|
if (assetPathsToDelete.length > 0) {
|
||||||
const fs = await import("fs");
|
const fs = await import("fs");
|
||||||
for (const assetPath of assetPathsToDelete) {
|
for (const assetPath of assetPathsToDelete) {
|
||||||
|
|||||||
@@ -18,29 +18,19 @@ const updateCustomGame = async (
|
|||||||
throw new Error("Game not found");
|
throw new Error("Game not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect old asset paths that will be replaced
|
|
||||||
const oldAssetPaths: string[] = [];
|
const oldAssetPaths: string[] = [];
|
||||||
|
|
||||||
if (existingGame.iconUrl && iconUrl && existingGame.iconUrl !== iconUrl && existingGame.iconUrl.startsWith("local:")) {
|
const assetPairs = [
|
||||||
oldAssetPaths.push(existingGame.iconUrl.replace("local:", ""));
|
{ existing: existingGame.iconUrl, new: iconUrl },
|
||||||
}
|
{ existing: existingGame.logoImageUrl, new: logoImageUrl },
|
||||||
if (existingGame.iconUrl && !iconUrl && existingGame.iconUrl.startsWith("local:")) {
|
{ existing: existingGame.libraryHeroImageUrl, new: libraryHeroImageUrl }
|
||||||
oldAssetPaths.push(existingGame.iconUrl.replace("local:", ""));
|
];
|
||||||
}
|
|
||||||
|
|
||||||
if (existingGame.logoImageUrl && logoImageUrl && existingGame.logoImageUrl !== logoImageUrl && existingGame.logoImageUrl.startsWith("local:")) {
|
assetPairs.forEach(({ existing, new: newUrl }) => {
|
||||||
oldAssetPaths.push(existingGame.logoImageUrl.replace("local:", ""));
|
if (existing?.startsWith("local:") && (!newUrl || existing !== newUrl)) {
|
||||||
}
|
oldAssetPaths.push(existing.replace("local:", ""));
|
||||||
if (existingGame.logoImageUrl && !logoImageUrl && existingGame.logoImageUrl.startsWith("local:")) {
|
}
|
||||||
oldAssetPaths.push(existingGame.logoImageUrl.replace("local:", ""));
|
});
|
||||||
}
|
|
||||||
|
|
||||||
if (existingGame.libraryHeroImageUrl && libraryHeroImageUrl && existingGame.libraryHeroImageUrl !== libraryHeroImageUrl && existingGame.libraryHeroImageUrl.startsWith("local:")) {
|
|
||||||
oldAssetPaths.push(existingGame.libraryHeroImageUrl.replace("local:", ""));
|
|
||||||
}
|
|
||||||
if (existingGame.libraryHeroImageUrl && !libraryHeroImageUrl && existingGame.libraryHeroImageUrl.startsWith("local:")) {
|
|
||||||
oldAssetPaths.push(existingGame.libraryHeroImageUrl.replace("local:", ""));
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatedGame = {
|
const updatedGame = {
|
||||||
...existingGame,
|
...existingGame,
|
||||||
@@ -67,7 +57,6 @@ const updateCustomGame = async (
|
|||||||
await gamesShopAssetsSublevel.put(gameKey, updatedAssets);
|
await gamesShopAssetsSublevel.put(gameKey, updatedAssets);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manually delete specific old asset files instead of running full cleanup
|
|
||||||
if (oldAssetPaths.length > 0) {
|
if (oldAssetPaths.length > 0) {
|
||||||
const fs = await import("fs");
|
const fs = await import("fs");
|
||||||
for (const assetPath of oldAssetPaths) {
|
for (const assetPath of oldAssetPaths) {
|
||||||
|
|||||||
@@ -18,17 +18,21 @@ const updateGameCustomAssets = async (
|
|||||||
throw new Error("Game not found");
|
throw new Error("Game not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect old custom asset paths that will be replaced
|
|
||||||
const oldAssetPaths: string[] = [];
|
const oldAssetPaths: string[] = [];
|
||||||
|
|
||||||
const assetPairs = [
|
const assetPairs = [
|
||||||
{ existing: existingGame.customIconUrl, new: customIconUrl },
|
{ existing: existingGame.customIconUrl, new: customIconUrl },
|
||||||
{ existing: existingGame.customLogoImageUrl, new: customLogoImageUrl },
|
{ existing: existingGame.customLogoImageUrl, new: customLogoImageUrl },
|
||||||
{ existing: existingGame.customHeroImageUrl, new: customHeroImageUrl }
|
{ existing: existingGame.customHeroImageUrl, new: customHeroImageUrl },
|
||||||
];
|
];
|
||||||
|
|
||||||
assetPairs.forEach(({ existing, new: newUrl }) => {
|
assetPairs.forEach(({ existing, new: newUrl }) => {
|
||||||
if (existing && newUrl !== undefined && existing !== newUrl && existing.startsWith("local:")) {
|
if (
|
||||||
|
existing &&
|
||||||
|
newUrl !== undefined &&
|
||||||
|
existing !== newUrl &&
|
||||||
|
existing.startsWith("local:")
|
||||||
|
) {
|
||||||
oldAssetPaths.push(existing.replace("local:", ""));
|
oldAssetPaths.push(existing.replace("local:", ""));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -43,18 +47,16 @@ const updateGameCustomAssets = async (
|
|||||||
|
|
||||||
await gamesSublevel.put(gameKey, updatedGame);
|
await gamesSublevel.put(gameKey, updatedGame);
|
||||||
|
|
||||||
// Also update the shop assets for non-custom games
|
|
||||||
const existingAssets = await gamesShopAssetsSublevel.get(gameKey);
|
const existingAssets = await gamesShopAssetsSublevel.get(gameKey);
|
||||||
if (existingAssets) {
|
if (existingAssets) {
|
||||||
const updatedAssets = {
|
const updatedAssets = {
|
||||||
...existingAssets,
|
...existingAssets,
|
||||||
title, // Update the title in shop assets as well
|
title,
|
||||||
};
|
};
|
||||||
|
|
||||||
await gamesShopAssetsSublevel.put(gameKey, updatedAssets);
|
await gamesShopAssetsSublevel.put(gameKey, updatedAssets);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manually delete specific old custom asset files instead of running full cleanup
|
|
||||||
if (oldAssetPaths.length > 0) {
|
if (oldAssetPaths.length > 0) {
|
||||||
const fs = await import("fs");
|
const fs = await import("fs");
|
||||||
for (const assetPath of oldAssetPaths) {
|
for (const assetPath of oldAssetPaths) {
|
||||||
|
|||||||
Reference in New Issue
Block a user