ci: testing pipeline

This commit is contained in:
Hydra
2024-04-29 11:01:34 +01:00
parent 5bec457ba6
commit 3b5f3da2ab
27 changed files with 1349 additions and 1399 deletions

View File

@@ -4,7 +4,6 @@ import { formatUploadDate } from "@main/helpers";
import { Repack } from "@main/entity";
import { requestWebPage, savePage } from "./helpers";
import type { GameRepackInput } from "./helpers";
export const request1337x = async (path: string) =>
requestWebPage(`https://1337xx.to${path}`);
@@ -68,7 +67,7 @@ export const extractTorrentsFromDocument = async (
user: string,
document: Document,
existingRepacks: Repack[] = []
): Promise<GameRepackInput[]> => {
) => {
const $trs = Array.from(document.querySelectorAll("tbody tr"));
return Promise.all(
@@ -108,7 +107,7 @@ export const getNewRepacksFromUser = async (
user: string,
existingRepacks: Repack[],
page = 1
): Promise<Repack[]> => {
) => {
const response = await request1337x(`/user/${user}/${page}`);
const { window } = new JSDOM(response);

View File

@@ -3,7 +3,6 @@ import { JSDOM } from "jsdom";
import { Repack } from "@main/entity";
import { requestWebPage, savePage } from "./helpers";
import type { GameRepackInput } from "./helpers";
import { logger } from "../logger";
export const getNewRepacksFromCPG = async (
@@ -14,7 +13,7 @@ export const getNewRepacksFromCPG = async (
const { window } = new JSDOM(data);
const repacks: GameRepackInput[] = [];
const repacks = [];
try {
Array.from(window.document.querySelectorAll(".post")).forEach(($post) => {

View File

@@ -1,7 +1,8 @@
import { JSDOM, VirtualConsole } from "jsdom";
import { GameRepackInput, requestWebPage, savePage } from "./helpers";
import { requestWebPage, savePage } from "./helpers";
import { Repack } from "@main/entity";
import { logger } from "../logger";
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
const virtualConsole = new VirtualConsole();
@@ -36,43 +37,35 @@ const getGOGGame = async (url: string) => {
};
export const getNewGOGGames = async (existingRepacks: Repack[] = []) => {
try {
const data = await requestWebPage(
"https://freegogpcgames.com/a-z-games-list/"
);
const data = await requestWebPage(
"https://freegogpcgames.com/a-z-games-list/"
);
const { window } = new JSDOM(data, { virtualConsole });
const { window } = new JSDOM(data, { virtualConsole });
const $uls = Array.from(window.document.querySelectorAll(".az-columns"));
const $uls = Array.from(window.document.querySelectorAll(".az-columns"));
for (const $ul of $uls) {
const repacks: GameRepackInput[] = [];
const $lis = Array.from($ul.querySelectorAll("li"));
for (const $ul of $uls) {
const repacks: QueryDeepPartialEntity<Repack>[] = [];
const $lis = Array.from($ul.querySelectorAll("li"));
for (const $li of $lis) {
const $a = $li.querySelector("a");
const href = $a.href;
for (const $li of $lis) {
const $a = $li.querySelector("a");
const href = $a.href;
const title = $a.textContent.trim();
const title = $a.textContent.trim();
const gameExists = existingRepacks.some(
(existingRepack) => existingRepack.title === title
);
const gameExists = existingRepacks.some(
(existingRepack) => existingRepack.title === title
);
if (!gameExists) {
try {
const game = await getGOGGame(href);
if (!gameExists) {
const game = await getGOGGame(href);
repacks.push({ ...game, title });
} catch (err) {
logger.error(err.message, { method: "getGOGGame", url: href });
}
}
repacks.push({ ...game, title });
}
if (repacks.length) await savePage(repacks);
}
} catch (err) {
logger.error(err.message, { method: "getNewGOGGames" });
if (repacks.length) await savePage(repacks);
}
};

View File

@@ -1,6 +1,5 @@
import { Repack } from "@main/entity";
import { savePage } from "./helpers";
import type { GameRepackInput } from "./helpers";
import { logger } from "../logger";
import parseTorrent, {
toMagnetURI,
@@ -85,7 +84,7 @@ export const getNewRepacksFromOnlineFix = async (
});
const document = new JSDOM(home.body).window.document;
const repacks: GameRepackInput[] = [];
const repacks = [];
const articles = Array.from(document.querySelectorAll(".news"));
const totalPages = Number(
document.querySelector("nav > a:nth-child(13)")?.textContent

View File

@@ -1,16 +1,14 @@
import { JSDOM } from "jsdom";
import parseTorrent, { toMagnetURI } from "parse-torrent";
import { Repack } from "@main/entity";
import { logger } from "../logger";
import { requestWebPage, savePage } from "./helpers";
import type { GameRepackInput } from "./helpers";
const getTorrentBuffer = (url: string) =>
fetch(url, { method: "GET" }).then((response) =>
response.arrayBuffer().then((buffer) => Buffer.from(buffer))
);
import createWorker from "@main/workers/torrent-parser.worker?nodeWorker";
import { toMagnetURI } from "parse-torrent";
import type { Instance } from "parse-torrent";
const worker = createWorker({});
const formatXatabDate = (str: string) => {
const date = new Date();
@@ -28,29 +26,36 @@ const formatXatabDate = (str: string) => {
const formatXatabDownloadSize = (str: string) =>
str.replace(",", ".").replace(/Гб/g, "GB").replace(/Мб/g, "MB");
const getXatabRepack = async (url: string) => {
const data = await requestWebPage(url);
const { window } = new JSDOM(data);
const { document } = window;
const getXatabRepack = (url: string) => {
return new Promise((resolve) => {
(async () => {
const data = await requestWebPage(url);
const { window } = new JSDOM(data);
const { document } = window;
const $uploadDate = document.querySelector(".entry__date");
const $size = document.querySelector(".entry__info-size");
const $uploadDate = document.querySelector(".entry__date");
const $size = document.querySelector(".entry__info-size");
const $downloadButton = document.querySelector(
".download-torrent"
) as HTMLAnchorElement;
const $downloadButton = document.querySelector(
".download-torrent"
) as HTMLAnchorElement;
if (!$downloadButton) throw new Error("Download button not found");
if (!$downloadButton) throw new Error("Download button not found");
const torrentBuffer = await getTorrentBuffer($downloadButton.href);
const onMessage = (torrent: Instance) => {
resolve({
fileSize: formatXatabDownloadSize($size.textContent).toUpperCase(),
magnet: toMagnetURI(torrent),
uploadDate: formatXatabDate($uploadDate.textContent),
});
return {
fileSize: formatXatabDownloadSize($size.textContent).toUpperCase(),
magnet: toMagnetURI({
infoHash: parseTorrent(torrentBuffer).infoHash,
}),
uploadDate: formatXatabDate($uploadDate.textContent),
};
worker.removeListener("message", onMessage);
};
worker.on("message", onMessage);
worker.postMessage($downloadButton.href);
})();
});
};
export const getNewRepacksFromXatab = async (
@@ -61,7 +66,7 @@ export const getNewRepacksFromXatab = async (
const { window } = new JSDOM(data);
const repacks: GameRepackInput[] = [];
const repacks = [];
for (const $a of Array.from(
window.document.querySelectorAll(".entry__title a")
@@ -84,7 +89,6 @@ export const getNewRepacksFromXatab = async (
const newRepacks = repacks.filter(
(repack) =>
repack.uploadDate &&
!existingRepacks.some(
(existingRepack) => existingRepack.title === repack.title
)

View File

@@ -2,8 +2,8 @@ import { BrowserWindow, Menu, Tray, app } from "electron";
import { is } from "@electron-toolkit/utils";
import { t } from "i18next";
import path from "node:path";
import icon from "../../../resources/icon.png?asset";
import trayIcon from "../../../resources/tray-icon.png?asset";
import icon from "@resources/icon.png?asset";
import trayIcon from "@resources/tray-icon.png?asset";
export class WindowManager {
public static mainWindow: Electron.BrowserWindow | null = null;