2024-05-05 18:18:48 +00:00
|
|
|
export enum Downloader {
|
2024-05-06 08:53:18 +00:00
|
|
|
RealDebrid,
|
2024-05-05 18:18:48 +00:00
|
|
|
Torrent,
|
2024-07-09 18:24:02 +00:00
|
|
|
Gofile,
|
|
|
|
PixelDrain,
|
2024-08-18 15:19:06 +00:00
|
|
|
Qiwi,
|
2024-05-05 18:18:48 +00:00
|
|
|
}
|
|
|
|
|
2024-06-03 20:39:37 +00:00
|
|
|
export enum DownloadSourceStatus {
|
|
|
|
UpToDate,
|
|
|
|
Errored,
|
|
|
|
}
|
|
|
|
|
2024-07-03 02:31:07 +00:00
|
|
|
export class UserNotLoggedInError extends Error {
|
|
|
|
constructor() {
|
|
|
|
super("user not logged in");
|
|
|
|
this.name = "UserNotLoggedInError";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-12 12:29:12 +00:00
|
|
|
const FORMAT = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
|
|
|
|
|
|
export const formatBytes = (bytes: number): string => {
|
|
|
|
if (!Number.isFinite(bytes) || isNaN(bytes) || bytes <= 0) {
|
|
|
|
return `0 ${FORMAT[0]}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const byteKBase = 1024;
|
|
|
|
|
|
|
|
const base = Math.floor(Math.log(bytes) / Math.log(byteKBase));
|
|
|
|
|
|
|
|
const formatedByte = bytes / byteKBase ** base;
|
|
|
|
|
|
|
|
return `${Math.trunc(formatedByte * 10) / 10} ${FORMAT[base]}`;
|
|
|
|
};
|
2024-06-03 01:12:05 +00:00
|
|
|
|
|
|
|
export const pipe =
|
|
|
|
<T>(...fns: ((arg: T) => any)[]) =>
|
|
|
|
(arg: T) =>
|
|
|
|
fns.reduce((prev, fn) => fn(prev), arg);
|
|
|
|
|
|
|
|
export const removeReleaseYearFromName = (name: string) =>
|
|
|
|
name.replace(/\([0-9]{4}\)/g, "");
|
|
|
|
|
|
|
|
export const removeSymbolsFromName = (name: string) =>
|
|
|
|
name.replace(/[^A-Za-z 0-9]/g, "");
|
|
|
|
|
|
|
|
export const removeSpecialEditionFromName = (name: string) =>
|
|
|
|
name.replace(
|
|
|
|
/(The |Digital )?(GOTY|Deluxe|Standard|Ultimate|Definitive|Enhanced|Collector's|Premium|Digital|Limited|Game of the Year|Reloaded|[0-9]{4}) Edition/g,
|
|
|
|
""
|
|
|
|
);
|
|
|
|
|
|
|
|
export const removeDuplicateSpaces = (name: string) =>
|
|
|
|
name.replace(/\s{2,}/g, " ");
|
|
|
|
|
2024-08-15 19:46:21 +00:00
|
|
|
export const replaceDotsWithSpace = (name: string) => name.replace(/\./g, " ");
|
|
|
|
|
2024-07-05 14:53:32 +00:00
|
|
|
export const replaceUnderscoreWithSpace = (name: string) =>
|
|
|
|
name.replace(/_/g, " ");
|
|
|
|
|
2024-06-03 01:12:05 +00:00
|
|
|
export const formatName = pipe<string>(
|
|
|
|
removeReleaseYearFromName,
|
|
|
|
removeSpecialEditionFromName,
|
2024-07-05 14:53:32 +00:00
|
|
|
replaceUnderscoreWithSpace,
|
2024-08-15 19:46:21 +00:00
|
|
|
replaceDotsWithSpace,
|
2024-07-04 22:11:21 +00:00
|
|
|
(str) => str.replace(/DIRECTOR'S CUT/g, ""),
|
|
|
|
removeSymbolsFromName,
|
2024-06-03 01:12:05 +00:00
|
|
|
removeDuplicateSpaces,
|
|
|
|
(str) => str.trim()
|
|
|
|
);
|
2024-07-09 18:24:02 +00:00
|
|
|
|
|
|
|
const realDebridHosts = ["https://1fichier.com", "https://mediafire.com"];
|
|
|
|
|
|
|
|
export const getDownloadersForUri = (uri: string) => {
|
|
|
|
if (uri.startsWith("https://gofile.io")) return [Downloader.Gofile];
|
2024-08-18 00:39:50 +00:00
|
|
|
|
2024-07-09 18:24:02 +00:00
|
|
|
if (uri.startsWith("https://pixeldrain.com")) return [Downloader.PixelDrain];
|
2024-08-18 15:19:06 +00:00
|
|
|
if (uri.startsWith("https://qiwi.gg")) return [Downloader.Qiwi];
|
2024-07-09 18:24:02 +00:00
|
|
|
|
|
|
|
if (realDebridHosts.some((host) => uri.startsWith(host)))
|
|
|
|
return [Downloader.RealDebrid];
|
|
|
|
|
2024-08-18 00:39:50 +00:00
|
|
|
if (uri.startsWith("magnet:")) {
|
2024-07-09 18:24:02 +00:00
|
|
|
return [Downloader.Torrent, Downloader.RealDebrid];
|
2024-08-18 00:39:50 +00:00
|
|
|
}
|
2024-07-09 18:24:02 +00:00
|
|
|
|
|
|
|
return [];
|
|
|
|
};
|
2024-08-18 00:39:50 +00:00
|
|
|
|
|
|
|
export const getDownloadersForUris = (uris: string[]) => {
|
|
|
|
const downloadersSet = uris.reduce<Set<Downloader>>((prev, next) => {
|
|
|
|
const downloaders = getDownloadersForUri(next);
|
|
|
|
downloaders.forEach((downloader) => prev.add(downloader));
|
|
|
|
|
|
|
|
return prev;
|
|
|
|
}, new Set());
|
|
|
|
|
|
|
|
return Array.from(downloadersSet);
|
|
|
|
};
|
2024-09-11 23:53:16 +00:00
|
|
|
|
|
|
|
export const steamUrlBuilder = {
|
|
|
|
library: (objectID: string) =>
|
|
|
|
`https://steamcdn-a.akamaihd.net/steam/apps/${objectID}/header.jpg`,
|
|
|
|
libraryHero: (objectID: string) =>
|
|
|
|
`https://steamcdn-a.akamaihd.net/steam/apps/${objectID}/library_hero.jpg`,
|
|
|
|
logo: (objectID: string) =>
|
|
|
|
`https://cdn.cloudflare.steamstatic.com/steam/apps/${objectID}/logo.png`,
|
|
|
|
cover: (objectID: string) =>
|
|
|
|
`https://cdn.cloudflare.steamstatic.com/steam/apps/${objectID}/library_600x900.jpg`,
|
|
|
|
icon: (objectID: string, clientIcon: string) =>
|
|
|
|
`https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/${objectID}/${clientIcon}.ico`,
|
|
|
|
};
|