mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 08:43:48 +03:00
feat: migrating download source validation to worker thread
This commit is contained in:
parent
dc94a886e6
commit
4e422bdf91
@ -1,17 +1,12 @@
|
|||||||
import { registerEvent } from "../register-event";
|
import { registerEvent } from "../register-event";
|
||||||
import axios from "axios";
|
|
||||||
import { downloadSourceRepository } from "@main/repository";
|
import { downloadSourceRepository } from "@main/repository";
|
||||||
import { downloadSourceSchema } from "../helpers/validators";
|
|
||||||
import { RepacksManager } from "@main/services";
|
import { RepacksManager } from "@main/services";
|
||||||
|
import { downloadSourceWorker } from "@main/workers";
|
||||||
|
|
||||||
const validateDownloadSource = async (
|
const validateDownloadSource = async (
|
||||||
_event: Electron.IpcMainInvokeEvent,
|
_event: Electron.IpcMainInvokeEvent,
|
||||||
url: string
|
url: string
|
||||||
) => {
|
) => {
|
||||||
const response = await axios.get(url);
|
|
||||||
|
|
||||||
const source = downloadSourceSchema.parse(response.data);
|
|
||||||
|
|
||||||
const existingSource = await downloadSourceRepository.findOne({
|
const existingSource = await downloadSourceRepository.findOne({
|
||||||
where: { url },
|
where: { url },
|
||||||
});
|
});
|
||||||
@ -21,14 +16,12 @@ const validateDownloadSource = async (
|
|||||||
|
|
||||||
const repacks = RepacksManager.repacks;
|
const repacks = RepacksManager.repacks;
|
||||||
|
|
||||||
const existingUris = source.downloads
|
return downloadSourceWorker.run(
|
||||||
.flatMap((download) => download.uris)
|
{ url, repacks },
|
||||||
.filter((uri) => repacks.some((repack) => repack.magnet === uri));
|
{
|
||||||
|
name: "validateDownloadSource",
|
||||||
return {
|
}
|
||||||
name: source.name,
|
);
|
||||||
downloadCount: source.downloads.length - existingUris.length,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
registerEvent("validateDownloadSource", validateDownloadSource);
|
registerEvent("validateDownloadSource", validateDownloadSource);
|
||||||
|
@ -15,7 +15,7 @@ import { uploadGamesBatch } from "./services/library-sync";
|
|||||||
startMainLoop();
|
startMainLoop();
|
||||||
|
|
||||||
const loadState = async (userPreferences: UserPreferences | null) => {
|
const loadState = async (userPreferences: UserPreferences | null) => {
|
||||||
await RepacksManager.updateRepacks();
|
RepacksManager.updateRepacks();
|
||||||
|
|
||||||
import("./events");
|
import("./events");
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
import { Repack } from "@main/entity";
|
||||||
import { downloadSourceSchema } from "@main/events/helpers/validators";
|
import { downloadSourceSchema } from "@main/events/helpers/validators";
|
||||||
import { DownloadSourceStatus } from "@shared";
|
import { DownloadSourceStatus } from "@shared";
|
||||||
import type { DownloadSource } from "@types";
|
import type { DownloadSource, GameRepack } from "@types";
|
||||||
import axios, { AxiosError, AxiosHeaders } from "axios";
|
import axios, { AxiosError, AxiosHeaders } from "axios";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
@ -48,3 +49,24 @@ export const getUpdatedRepacks = async (downloadSources: DownloadSource[]) => {
|
|||||||
|
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const validateDownloadSource = async ({
|
||||||
|
url,
|
||||||
|
repacks,
|
||||||
|
}: {
|
||||||
|
url: string;
|
||||||
|
repacks: GameRepack[];
|
||||||
|
}) => {
|
||||||
|
const response = await axios.get(url);
|
||||||
|
|
||||||
|
const source = downloadSourceSchema.parse(response.data);
|
||||||
|
|
||||||
|
const existingUris = source.downloads
|
||||||
|
.flatMap((download) => download.uris)
|
||||||
|
.filter((uri) => repacks.some((repack) => repack.magnet === uri));
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: source.name,
|
||||||
|
downloadCount: source.downloads.length - existingUris.length,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user