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