mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-11 13:56:16 +00:00
feat: adding sources migration
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
27
src/main/helpers/migrate-download-sources.ts
Normal file
27
src/main/helpers/migrate-download-sources.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
|
||||
@@ -38,8 +38,6 @@ export function GameCard({ game, ...props }: GameCardProps) {
|
||||
|
||||
const { numberFormatter } = useFormat();
|
||||
|
||||
console.log("game", game);
|
||||
|
||||
return (
|
||||
<button
|
||||
{...props}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ export interface DownloadSource {
|
||||
status: DownloadSourceStatus;
|
||||
downloadCount: number;
|
||||
fingerprint?: string;
|
||||
isRemote?: true;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface ShopAssets {
|
||||
|
||||
Reference in New Issue
Block a user