feat: adding sources migration

This commit is contained in:
Chubby Granny Chaser
2025-10-26 23:22:20 +00:00
parent 7c272aeed8
commit 87a57f7a37
7 changed files with 43 additions and 12 deletions

View File

@@ -2,6 +2,7 @@ import { registerEvent } from "../register-event";
import { HydraApi } from "@main/services/hydra-api";
import { downloadSourcesSublevel } from "@main/level";
import type { DownloadSource } from "@types";
import { logger } from "@main/services";
const addDownloadSource = async (
_event: Electron.IpcMainInvokeEvent,
@@ -22,22 +23,19 @@ const addDownloadSource = async (
urls: [url],
});
} catch (error) {
console.error("Failed to add download source to profile:", error);
logger.error("Failed to add download source to profile:", error);
}
}
const downloadSourceForStorage = {
await downloadSourcesSublevel.put(downloadSource.id, {
...downloadSource,
fingerprint: downloadSource.fingerprint || "",
};
await downloadSourcesSublevel.put(
downloadSource.id,
downloadSourceForStorage
);
isRemote: true,
createdAt: new Date().toISOString(),
});
return downloadSource;
} catch (error) {
console.error("Failed to add download source:", error);
logger.error("Failed to add download source:", error);
throw error;
}
};

View File

@@ -1,8 +1,10 @@
import { downloadSourcesSublevel } from "@main/level";
import { registerEvent } from "../register-event";
import { orderBy } from "lodash-es";
const getDownloadSources = async (_event: Electron.IpcMainInvokeEvent) => {
return downloadSourcesSublevel.values().all();
const allSources = await downloadSourcesSublevel.values().all();
return orderBy(allSources, "createdAt", "desc");
};
registerEvent("getDownloadSources", getDownloadSources);

View File

@@ -0,0 +1,27 @@
import { downloadSourcesSublevel } from "@main/level";
import { HydraApi } from "@main/services/hydra-api";
import { DownloadSource } from "@types";
export const migrateDownloadSources = async () => {
const downloadSources = downloadSourcesSublevel.iterator();
for await (const [key, value] of downloadSources) {
if (!value.isRemote) {
const downloadSource = await HydraApi.post<DownloadSource>(
"/download-sources",
{
url: value.url,
},
{ needsAuth: false }
);
await downloadSourcesSublevel.put(downloadSource.id, {
...downloadSource,
isRemote: true,
createdAt: new Date().toISOString(),
});
await downloadSourcesSublevel.del(key);
}
}
};

View File

@@ -17,6 +17,7 @@ import {
Lock,
DeckyPlugin,
} from "@main/services";
import { migrateDownloadSources } from "./helpers/migrate-download-sources";
export const loadState = async () => {
await Lock.acquireLock();
@@ -51,6 +52,7 @@ export const loadState = async () => {
await HydraApi.setupApi().then(() => {
uploadGamesBatch();
void migrateDownloadSources();
// WSClient.connect();
});

View File

@@ -38,8 +38,6 @@ export function GameCard({ game, ...props }: GameCardProps) {
const { numberFormatter } = useFormat();
console.log("game", game);
return (
<button
{...props}

View File

@@ -103,6 +103,8 @@ export function SettingsDownloadSources() {
try {
const sources = await window.electron.syncDownloadSources();
setDownloadSources(sources);
showSuccessToast(t("download_sources_synced_successfully"));
} finally {
setIsSyncingDownloadSources(false);
}

View File

@@ -32,6 +32,8 @@ export interface DownloadSource {
status: DownloadSourceStatus;
downloadCount: number;
fingerprint?: string;
isRemote?: true;
createdAt: string;
}
export interface ShopAssets {