fix: fixing tsc errors

This commit is contained in:
Hydra
2024-05-12 13:29:12 +01:00
parent 13743cd7a5
commit c29f28dbdd
22 changed files with 79 additions and 100 deletions

View File

@@ -38,12 +38,9 @@ export class RealDebridDownloader extends Downloader {
const updatePayload: QueryDeepPartialEntity<Game> = {
status: GameStatus.Finished,
progress: 1,
};
await this.updateGameProgress(game.id, updatePayload, {
timeRemaining: 0,
});
await this.updateGameProgress(game.id, updatePayload, {});
}
static destroy() {
@@ -100,7 +97,7 @@ export class RealDebridDownloader extends Downloader {
this.download.on("end", async () => {
const updatePayload: QueryDeepPartialEntity<Game> = {
status: GameStatus.Decompressing,
progress: 0.99,
progress: 1,
};
await this.updateGameProgress(game.id, updatePayload, {

View File

@@ -1,3 +1,4 @@
import { Game } from "@main/entity";
import type {
RealDebridAddMagnet,
RealDebridTorrentInfo,

View File

@@ -33,9 +33,9 @@ const getTorrentDetails = async (path: string) => {
return {
magnet: $a?.href,
fileSize: $totalSize.querySelector("span").textContent ?? undefined,
fileSize: $totalSize.querySelector("span")!.textContent,
uploadDate: formatUploadDate(
$dateUploaded.querySelector("span").textContent!
$dateUploaded.querySelector("span")!.textContent!
),
};
};
@@ -65,8 +65,7 @@ export const getTorrentListLastPage = async (user: string) => {
export const extractTorrentsFromDocument = async (
page: number,
user: string,
document: Document,
existingRepacks: Repack[] = []
document: Document
) => {
const $trs = Array.from(document.querySelectorAll("tbody tr"));
@@ -78,24 +77,13 @@ export const extractTorrentsFromDocument = async (
const url = $name.href;
const title = $name.textContent ?? "";
if (existingRepacks.some((repack) => repack.title === title)) {
return {
title,
magnet: "",
fileSize: null,
uploadDate: null,
repacker: user,
page,
};
}
const details = await getTorrentDetails(url);
return {
title,
magnet: details.magnet,
fileSize: details.fileSize ?? null,
uploadDate: details.uploadDate ?? null,
fileSize: details.fileSize ?? "N/A",
uploadDate: details.uploadDate ?? new Date(),
repacker: user,
page,
};
@@ -114,13 +102,11 @@ export const getNewRepacksFromUser = async (
const repacks = await extractTorrentsFromDocument(
page,
user,
window.document,
existingRepacks
window.document
);
const newRepacks = repacks.filter(
(repack) =>
repack.uploadDate &&
!existingRepacks.some(
(existingRepack) => existingRepack.title === repack.title
)

View File

@@ -4,6 +4,7 @@ import { Repack } from "@main/entity";
import { requestWebPage, savePage } from "./helpers";
import { logger } from "../logger";
import type { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
export const getNewRepacksFromCPG = async (
existingRepacks: Repack[] = [],
@@ -13,11 +14,11 @@ export const getNewRepacksFromCPG = async (
const { window } = new JSDOM(data);
const repacks = [];
const repacks: QueryDeepPartialEntity<Repack>[] = [];
try {
Array.from(window.document.querySelectorAll(".post")).forEach(($post) => {
const $title = $post.querySelector(".entry-title");
const $title = $post.querySelector(".entry-title")!;
const uploadDate = $post.querySelector("time")?.getAttribute("datetime");
const $downloadInfo = Array.from(
@@ -31,26 +32,25 @@ export const getNewRepacksFromCPG = async (
$a.textContent?.startsWith("Magent")
);
const fileSize = $downloadInfo.textContent
const fileSize = ($downloadInfo?.textContent ?? "")
.split("Download link => ")
.at(1);
repacks.push({
title: $title.textContent,
title: $title.textContent!,
fileSize: fileSize ?? "N/A",
magnet: $magnet.href,
magnet: $magnet!.href,
repacker: "CPG",
page,
uploadDate: new Date(uploadDate),
uploadDate: uploadDate ? new Date(uploadDate) : new Date(),
});
});
} catch (err) {
logger.error(err.message, { method: "getNewRepacksFromCPG" });
} catch (err: unknown) {
logger.error((err as Error).message, { method: "getNewRepacksFromCPG" });
}
const newRepacks = repacks.filter(
(repack) =>
repack.uploadDate &&
!existingRepacks.some(
(existingRepack) => existingRepack.title === repack.title
)

View File

@@ -16,14 +16,14 @@ const getGOGGame = async (url: string) => {
const $em = window.document.querySelector(
"p:not(.lightweight-accordion *) em"
);
const fileSize = $em.textContent.split("Size: ").at(1);
)!;
const fileSize = $em.textContent!.split("Size: ").at(1);
const $downloadButton = window.document.querySelector(
".download-btn:not(.lightweight-accordion *)"
) as HTMLAnchorElement;
const { searchParams } = new URL($downloadButton.href);
const magnet = Buffer.from(searchParams.get("url"), "base64").toString(
const magnet = Buffer.from(searchParams.get("url")!, "base64").toString(
"utf-8"
);
@@ -50,10 +50,10 @@ export const getNewGOGGames = async (existingRepacks: Repack[] = []) => {
const $lis = Array.from($ul.querySelectorAll("li"));
for (const $li of $lis) {
const $a = $li.querySelector("a");
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

View File

@@ -13,6 +13,9 @@ import { ru } from "date-fns/locale";
import { onlinefixFormatter } from "@main/helpers";
import makeFetchCookie from "fetch-cookie";
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
import { formatBytes } from "@shared";
const ONLINE_FIX_URL = "https://online-fix.me/";
export const getNewRepacksFromOnlineFix = async (
existingRepacks: Repack[] = [],
@@ -27,14 +30,14 @@ export const getNewRepacksFromOnlineFix = async (
const http = makeFetchCookie(fetch, cookieJar);
if (page === 1) {
await http("https://online-fix.me/");
await http(ONLINE_FIX_URL);
const preLogin =
((await http("https://online-fix.me/engine/ajax/authtoken.php", {
method: "GET",
headers: {
"X-Requested-With": "XMLHttpRequest",
Referer: "https://online-fix.me/",
Referer: ONLINE_FIX_URL,
},
}).then((res) => res.json())) as {
field: string;
@@ -50,11 +53,11 @@ export const getNewRepacksFromOnlineFix = async (
[preLogin.field]: preLogin.value,
});
await http("https://online-fix.me/", {
await http(ONLINE_FIX_URL, {
method: "POST",
headers: {
Referer: "https://online-fix.me",
Origin: "https://online-fix.me",
Referer: ONLINE_FIX_URL,
Origin: ONLINE_FIX_URL,
"Content-Type": "application/x-www-form-urlencoded",
},
body: params.toString(),
@@ -149,13 +152,8 @@ export const getNewRepacksFromOnlineFix = async (
const torrentSizeInBytes = torrent.length;
if (!torrentSizeInBytes) return;
const fileSizeFormatted =
torrentSizeInBytes >= 1024 ** 3
? `${(torrentSizeInBytes / 1024 ** 3).toFixed(1)}GBs`
: `${(torrentSizeInBytes / 1024 ** 2).toFixed(1)}MBs`;
repacks.push({
fileSize: fileSizeFormatted,
fileSize: formatBytes(torrentSizeInBytes),
magnet: magnetLink,
page: 1,
repacker: "onlinefix",

View File

@@ -7,6 +7,8 @@ import { requestWebPage, savePage } from "./helpers";
import createWorker from "@main/workers/torrent-parser.worker?nodeWorker";
import { toMagnetURI } from "parse-torrent";
import type { Instance } from "parse-torrent";
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
import { formatBytes } from "@shared";
const worker = createWorker({});
@@ -23,10 +25,9 @@ const formatXatabDate = (str: string) => {
return date;
};
const formatXatabDownloadSize = (str: string) =>
str.replace(",", ".").replace(/Гб/g, "GB").replace(/Мб/g, "MB");
const getXatabRepack = (url: string) => {
const getXatabRepack = (
url: string
): Promise<{ fileSize: string; magnet: string; uploadDate: Date }> => {
return new Promise((resolve) => {
(async () => {
const data = await requestWebPage(url);
@@ -34,7 +35,6 @@ const getXatabRepack = (url: string) => {
const { document } = window;
const $uploadDate = document.querySelector(".entry__date");
const $size = document.querySelector(".entry__info-size");
const $downloadButton = document.querySelector(
".download-torrent"
@@ -42,17 +42,13 @@ const getXatabRepack = (url: string) => {
if (!$downloadButton) throw new Error("Download button not found");
const onMessage = (torrent: Instance) => {
worker.once("message", (torrent: Instance) => {
resolve({
fileSize: formatXatabDownloadSize($size.textContent).toUpperCase(),
fileSize: formatBytes(torrent.length ?? 0),
magnet: toMagnetURI(torrent),
uploadDate: formatXatabDate($uploadDate.textContent),
uploadDate: formatXatabDate($uploadDate!.textContent!),
});
worker.removeListener("message", onMessage);
};
worker.once("message", onMessage);
});
})();
});
};
@@ -65,7 +61,7 @@ export const getNewRepacksFromXatab = async (
const { window } = new JSDOM(data);
const repacks = [];
const repacks: QueryDeepPartialEntity<Repack>[] = [];
for (const $a of Array.from(
window.document.querySelectorAll(".entry__title a")
@@ -74,7 +70,7 @@ export const getNewRepacksFromXatab = async (
const repack = await getXatabRepack(($a as HTMLAnchorElement).href);
repacks.push({
title: $a.textContent,
title: $a.textContent!,
repacker: "Xatab",
...repack,
page,