refactor: clean up code

This commit is contained in:
Hachi-R 2024-12-22 20:20:46 -03:00
parent 859d849d36
commit db01980eb8
7 changed files with 15 additions and 37 deletions

1
.gitignore vendored
View File

@ -1,6 +1,5 @@
.vscode/ .vscode/
node_modules/ node_modules/
fastlist.exe
__pycache__ __pycache__
dist dist
out out

View File

@ -2,6 +2,7 @@ import { registerEvent } from "../register-event";
import { DownloadManager, HydraApi, gamesPlaytime } from "@main/services"; import { DownloadManager, HydraApi, gamesPlaytime } from "@main/services";
import { dataSource } from "@main/data-source"; import { dataSource } from "@main/data-source";
import { DownloadQueue, Game, UserAuth, UserSubscription } from "@main/entity"; import { DownloadQueue, Game, UserAuth, UserSubscription } from "@main/entity";
import { PythonRPC } from "@main/services/python-rpc";
const signOut = async (_event: Electron.IpcMainInvokeEvent) => { const signOut = async (_event: Electron.IpcMainInvokeEvent) => {
const databaseOperations = dataSource const databaseOperations = dataSource
@ -27,8 +28,7 @@ const signOut = async (_event: Electron.IpcMainInvokeEvent) => {
DownloadManager.cancelDownload(); DownloadManager.cancelDownload();
/* Disconnects libtorrent */ /* Disconnects libtorrent */
// TODO PythonRPC.kill();
// TorrentDownloader.killTorrent();
HydraApi.handleSignOut(); HydraApi.handleSignOut();

View File

@ -1,11 +1,14 @@
import { registerEvent } from "../register-event"; import { registerEvent } from "../register-event";
import { PythonRPC } from "@main/services/python-rpc";
const processProfileImage = async ( const processProfileImage = async (
_event: Electron.IpcMainInvokeEvent, _event: Electron.IpcMainInvokeEvent,
path: string path: string
) => { ) => {
return path; return PythonRPC.rpc.post<{ imagePath: string; mimeType: string }>(
// return PythonInstance.processProfileImage(path); "/profile_image_processor/process_image",
{ path },
);
}; };
registerEvent("processProfileImage", processProfileImage); registerEvent("processProfileImage", processProfileImage);

View File

@ -8,11 +8,9 @@ const pauseGameSeed = async (
_event: Electron.IpcMainInvokeEvent, _event: Electron.IpcMainInvokeEvent,
gameId: number gameId: number
) => { ) => {
await dataSource.transaction(async (transactionalEntityManager) => { await dataSource
await transactionalEntityManager
.getRepository(Game) .getRepository(Game)
.update({ id: gameId }, { status: "complete", shouldSeed: false }); .update({ id: gameId }, { status: "complete", shouldSeed: false });
});
await DownloadManager.cancelDownload(gameId); await DownloadManager.cancelDownload(gameId);
}; };

View File

@ -20,11 +20,9 @@ const resumeGameSeed = async (
if (!game) return; if (!game) return;
await dataSource.transaction(async (transactionalEntityManager) => { await dataSource
await transactionalEntityManager
.getRepository(Game) .getRepository(Game)
.update({ id: gameId }, { status: "seeding", shouldSeed: true }); .update({ id: gameId }, { status: "seeding", shouldSeed: true });
});
await DownloadManager.startDownload(game); await DownloadManager.startDownload(game);
}; };

View File

@ -1,8 +1,5 @@
import { Ludusavi, startMainLoop } from "./services"; import { Ludusavi, startMainLoop } from "./services";
import { import { userPreferencesRepository } from "./repository";
// downloadQueueRepository,
userPreferencesRepository,
} from "./repository";
import { UserPreferences } from "./entity"; import { UserPreferences } from "./entity";
import { RealDebridClient } from "./services/download/real-debrid"; import { RealDebridClient } from "./services/download/real-debrid";
import { HydraApi } from "./services/hydra-api"; import { HydraApi } from "./services/hydra-api";
@ -25,24 +22,7 @@ const loadState = async (userPreferences: UserPreferences | null) => {
uploadGamesBatch(); uploadGamesBatch();
}); });
// const [nextQueueItem] = await downloadQueueRepository.find({
// order: {
// id: "DESC",
// },
// relations: {
// game: true,
// },
// });
PythonRPC.spawn(); PythonRPC.spawn();
// start download
// if (nextQueueItem?.game.status === "active") {
// DownloadManager.startDownload(nextQueueItem.game);
// } else {
// PythonInstance.spawn();
// }
startMainLoop(); startMainLoop();
}; };

View File

@ -30,7 +30,7 @@ export class HydraApi {
private static instance: AxiosInstance; private static instance: AxiosInstance;
private static readonly EXPIRATION_OFFSET_IN_MS = 1000 * 60 * 5; // 5 minutes private static readonly EXPIRATION_OFFSET_IN_MS = 1000 * 60 * 5; // 5 minutes
private static readonly ADD_LOG_INTERCEPTOR = false; private static readonly ADD_LOG_INTERCEPTOR = true;
private static secondsToMilliseconds = (seconds: number) => seconds * 1000; private static secondsToMilliseconds = (seconds: number) => seconds * 1000;