mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-15 04:32:13 +00:00
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { registerEvent } from "../register-event";
|
|
import { dataSource } from "@main/data-source";
|
|
import { DownloadSource } from "@main/entity";
|
|
import axios from "axios";
|
|
import { downloadSourceSchema } from "../helpers/validators";
|
|
import { insertDownloadsFromSource } from "@main/helpers";
|
|
import { RepacksManager } from "@main/services";
|
|
|
|
const addDownloadSource = async (
|
|
_event: Electron.IpcMainInvokeEvent,
|
|
url: string
|
|
) => {
|
|
const response = await axios.get(url);
|
|
|
|
const source = downloadSourceSchema.parse(response.data);
|
|
|
|
const downloadSource = await dataSource.transaction(
|
|
async (transactionalEntityManager) => {
|
|
const downloadSource = await transactionalEntityManager
|
|
.getRepository(DownloadSource)
|
|
.save({
|
|
url,
|
|
name: source.name,
|
|
downloadCount: source.downloads.length,
|
|
});
|
|
|
|
await insertDownloadsFromSource(
|
|
transactionalEntityManager,
|
|
downloadSource,
|
|
source.downloads
|
|
);
|
|
|
|
return downloadSource;
|
|
}
|
|
);
|
|
|
|
await RepacksManager.updateRepacks();
|
|
|
|
return downloadSource;
|
|
};
|
|
|
|
registerEvent("addDownloadSource", addDownloadSource);
|