feat: add support for VikingFile and display if link is available

This commit is contained in:
Moyasee
2026-01-02 23:20:08 +02:00
parent 9769eecec6
commit 8fa33119d6
12 changed files with 226 additions and 35 deletions

View File

@@ -1,6 +1,7 @@
MAIN_VITE_API_URL= MAIN_VITE_API_URL=
MAIN_VITE_AUTH_URL= MAIN_VITE_AUTH_URL=
MAIN_VITE_WS_URL= MAIN_VITE_WS_URL=
MAIN_VITE_NIMBUS_API_URL=
RENDERER_VITE_REAL_DEBRID_REFERRAL_ID= RENDERER_VITE_REAL_DEBRID_REFERRAL_ID=
RENDERER_VITE_TORBOX_REFERRAL_CODE= RENDERER_VITE_TORBOX_REFERRAL_CODE=
MAIN_VITE_LAUNCHER_SUBDOMAIN= MAIN_VITE_LAUNCHER_SUBDOMAIN=

View File

@@ -11,12 +11,19 @@ class HttpDownloader:
) )
) )
def start_download(self, url: str, save_path: str, header: str, out: str = None): def start_download(self, url: str, save_path: str, header, out: str = None):
if self.download: if self.download:
self.aria2.resume([self.download]) self.aria2.resume([self.download])
else: else:
downloads = self.aria2.add(url, options={"header": header, "dir": save_path, "out": out}) options = {"dir": save_path}
if header:
if isinstance(header, list):
options["header"] = header
else:
options["header"] = header
if out:
options["out"] = out
downloads = self.aria2.add(url, options=options)
self.download = downloads[0] self.download = downloads[0]
def pause_download(self): def pause_download(self):

View File

@@ -8,6 +8,7 @@ import {
DatanodesApi, DatanodesApi,
MediafireApi, MediafireApi,
PixelDrainApi, PixelDrainApi,
VikingFileApi,
} from "../hosters"; } from "../hosters";
import { PythonRPC } from "../python-rpc"; import { PythonRPC } from "../python-rpc";
import { import {
@@ -499,6 +500,29 @@ export class DownloadManager {
allow_multiple_connections: true, allow_multiple_connections: true,
}; };
} }
case Downloader.VikingFile: {
logger.log(
`[DownloadManager] Processing VikingFile download for URI: ${download.uri}`
);
try {
const downloadUrl = await VikingFileApi.getDownloadUrl(download.uri);
logger.log(`[DownloadManager] VikingFile direct URL obtained`);
return {
action: "start",
game_id: downloadId,
url: downloadUrl,
save_path: download.downloadPath,
header:
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36",
};
} catch (error) {
logger.error(
`[DownloadManager] Error processing VikingFile download:`,
error
);
throw error;
}
}
} }
} }

View File

@@ -5,3 +5,4 @@ export * from "./mediafire";
export * from "./pixeldrain"; export * from "./pixeldrain";
export * from "./buzzheavier"; export * from "./buzzheavier";
export * from "./fuckingfast"; export * from "./fuckingfast";
export * from "./vikingfile";

View File

@@ -0,0 +1,51 @@
import axios from "axios";
interface UnlockResponse {
link: string;
hoster: string;
}
export class VikingFileApi {
private static readonly browserHeaders = {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36",
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
Referer: "https://vikingfile.com/",
};
public static async getDownloadUrl(uri: string): Promise<string> {
const unlockResponse = await axios.post<UnlockResponse>(
`${import.meta.env.MAIN_VITE_NIMBUS_API_URL}/hosters/unlock`,
{ url: uri }
);
if (!unlockResponse.data.link) {
throw new Error("Failed to unlock VikingFile URL");
}
const redirectUrl = unlockResponse.data.link;
// Follow the redirect to get the final Cloudflare storage URL
try {
const redirectResponse = await axios.head(redirectUrl, {
headers: this.browserHeaders,
maxRedirects: 0,
validateStatus: (status) =>
status === 301 || status === 302 || status === 200,
});
if (
redirectResponse.headers.location ||
redirectResponse.status === 301 ||
redirectResponse.status === 302
) {
return redirectResponse.headers.location || redirectUrl;
}
return redirectUrl;
} catch (error) {
// Fallback to the redirect URL if following redirect fails
return redirectUrl;
}
}
}

View File

@@ -7,6 +7,7 @@ interface ImportMetaEnv {
readonly MAIN_VITE_CHECKOUT_URL: string; readonly MAIN_VITE_CHECKOUT_URL: string;
readonly MAIN_VITE_EXTERNAL_RESOURCES_URL: string; readonly MAIN_VITE_EXTERNAL_RESOURCES_URL: string;
readonly MAIN_VITE_WS_URL: string; readonly MAIN_VITE_WS_URL: string;
readonly MAIN_VITE_NIMBUS_API_URL: string;
readonly MAIN_VITE_LAUNCHER_SUBDOMAIN: string; readonly MAIN_VITE_LAUNCHER_SUBDOMAIN: string;
readonly ELECTRON_RENDERER_URL: string; readonly ELECTRON_RENDERER_URL: string;
} }

View File

@@ -14,6 +14,7 @@ export const DOWNLOADER_NAME = {
[Downloader.FuckingFast]: "FuckingFast", [Downloader.FuckingFast]: "FuckingFast",
[Downloader.TorBox]: "TorBox", [Downloader.TorBox]: "TorBox",
[Downloader.Hydra]: "Nimbus", [Downloader.Hydra]: "Nimbus",
[Downloader.VikingFile]: "VikingFile",
}; };
export const MAX_MINUTES_TO_SHOW_IN_PLAYTIME = 120; export const MAX_MINUTES_TO_SHOW_IN_PLAYTIME = 120;

View File

@@ -19,23 +19,67 @@
color: globals.$body-color; color: globals.$body-color;
} }
&__downloaders { &__downloaders-list {
display: grid; display: flex;
gap: globals.$spacing-unit; flex-direction: column;
grid-template-columns: repeat(2, 1fr); gap: calc(globals.$spacing-unit / 2);
max-height: 200px;
overflow-y: auto;
border: 1px solid globals.$border-color;
border-radius: 4px;
padding: calc(globals.$spacing-unit / 2);
background-color: globals.$dark-background-color;
} }
&__downloader-option { &__downloader-item {
position: relative; display: flex;
align-items: center;
gap: calc(globals.$spacing-unit * 1.5);
padding: calc(globals.$spacing-unit * 1.5) calc(globals.$spacing-unit * 2);
border: 1px solid transparent;
border-radius: 4px;
background-color: transparent;
cursor: pointer;
transition:
background-color 0.15s ease,
border-color 0.15s ease;
color: globals.$body-color;
font-size: 14px;
text-align: left;
&:only-child { &:hover:not(&--disabled) {
grid-column: 1 / -1; background-color: rgba(255, 255, 255, 0.05);
}
&--selected {
background-color: rgba(255, 255, 255, 0.08);
}
&--disabled {
opacity: 0.5;
cursor: not-allowed;
} }
} }
&__downloader-icon { &__downloader-name {
position: absolute; flex: 1;
left: calc(globals.$spacing-unit * 2); }
&__availability-indicator {
width: 10px;
height: 10px;
border-radius: 50%;
flex-shrink: 0;
&--available {
background-color: #22c55e;
box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}
&--unavailable {
background-color: #ef4444;
box-shadow: 0 0 6px rgba(239, 68, 68, 0.5);
}
} }
&__path-error { &__path-error {

View File

@@ -7,8 +7,13 @@ import {
Modal, Modal,
TextField, TextField,
} from "@renderer/components"; } from "@renderer/components";
import { CheckCircleFillIcon, DownloadIcon } from "@primer/octicons-react"; import { DownloadIcon } from "@primer/octicons-react";
import { Downloader, formatBytes, getDownloadersForUris } from "@shared"; import {
Downloader,
formatBytes,
getDownloadersForUri,
getDownloadersForUris,
} from "@shared";
import type { GameRepack } from "@types"; import type { GameRepack } from "@types";
import { DOWNLOADER_NAME } from "@renderer/constants"; import { DOWNLOADER_NAME } from "@renderer/constants";
import { useAppSelector, useFeature, useToast } from "@renderer/hooks"; import { useAppSelector, useFeature, useToast } from "@renderer/hooks";
@@ -82,6 +87,41 @@ export function DownloadSettingsModal({
return getDownloadersForUris(repack?.uris ?? []); return getDownloadersForUris(repack?.uris ?? []);
}, [repack?.uris]); }, [repack?.uris]);
const downloadOptions = useMemo(() => {
if (!repack) return [];
const unavailableUrisSet = new Set(repack.unavailableUris ?? []);
const downloaderMap = new Map<
Downloader,
{ hasAvailable: boolean; hasUnavailable: boolean }
>();
for (const uri of repack.uris) {
const uriDownloaders = getDownloadersForUri(uri);
if (uriDownloaders.length > 0) {
const downloader = uriDownloaders[0];
const isAvailable = !unavailableUrisSet.has(uri);
const existing = downloaderMap.get(downloader);
if (existing) {
existing.hasAvailable = existing.hasAvailable || isAvailable;
existing.hasUnavailable = existing.hasUnavailable || !isAvailable;
} else {
downloaderMap.set(downloader, {
hasAvailable: isAvailable,
hasUnavailable: !isAvailable,
});
}
}
}
return Array.from(downloaderMap.entries()).map(([downloader, status]) => ({
downloader,
isAvailable: status.hasAvailable,
}));
}, [repack]);
const getDefaultDownloader = useCallback( const getDefaultDownloader = useCallback(
(availableDownloaders: Downloader[]) => { (availableDownloaders: Downloader[]) => {
if (availableDownloaders.length === 0) return null; if (availableDownloaders.length === 0) return null;
@@ -186,31 +226,47 @@ export function DownloadSettingsModal({
<div className="download-settings-modal__downloads-path-field"> <div className="download-settings-modal__downloads-path-field">
<span>{t("downloader")}</span> <span>{t("downloader")}</span>
<div className="download-settings-modal__downloaders"> <div className="download-settings-modal__downloaders-list">
{downloaders.map((downloader) => { {downloadOptions.map((option) => {
const shouldDisableButton = const isUnavailable = !option.isAvailable;
(downloader === Downloader.RealDebrid && const shouldDisableOption =
isUnavailable ||
(option.downloader === Downloader.RealDebrid &&
!userPreferences?.realDebridApiToken) || !userPreferences?.realDebridApiToken) ||
(downloader === Downloader.TorBox && (option.downloader === Downloader.TorBox &&
!userPreferences?.torBoxApiToken) || !userPreferences?.torBoxApiToken) ||
(downloader === Downloader.Hydra && (option.downloader === Downloader.Hydra &&
!isFeatureEnabled(Feature.Nimbus)); !isFeatureEnabled(Feature.Nimbus));
const isSelected = selectedDownloader === option.downloader;
return ( return (
<Button <button
key={downloader} type="button"
className="download-settings-modal__downloader-option" key={option.downloader}
theme={ className={`download-settings-modal__downloader-item ${
selectedDownloader === downloader ? "primary" : "outline" isSelected
} ? "download-settings-modal__downloader-item--selected"
disabled={shouldDisableButton} : ""
onClick={() => setSelectedDownloader(downloader)} } ${
shouldDisableOption
? "download-settings-modal__downloader-item--disabled"
: ""
}`}
disabled={shouldDisableOption}
onClick={() => setSelectedDownloader(option.downloader)}
> >
{selectedDownloader === downloader && ( <span className="download-settings-modal__downloader-name">
<CheckCircleFillIcon className="download-settings-modal__downloader-icon" /> {DOWNLOADER_NAME[option.downloader]}
)} </span>
{DOWNLOADER_NAME[downloader]} <span
</Button> className={`download-settings-modal__availability-indicator ${
option.isAvailable
? "download-settings-modal__availability-indicator--available"
: "download-settings-modal__availability-indicator--unavailable"
}`}
/>
</button>
); );
})} })}
</div> </div>

View File

@@ -10,6 +10,7 @@ export enum Downloader {
Hydra, Hydra,
Buzzheavier, Buzzheavier,
FuckingFast, FuckingFast,
VikingFile,
} }
export enum DownloadSourceStatus { export enum DownloadSourceStatus {

View File

@@ -124,6 +124,9 @@ export const getDownloadersForUri = (uri: string) => {
if (uri.startsWith("https://fuckingfast.co")) { if (uri.startsWith("https://fuckingfast.co")) {
return [Downloader.FuckingFast]; return [Downloader.FuckingFast];
} }
if (uri.startsWith("https://vikingfile.com")) {
return [Downloader.VikingFile];
}
if (realDebridHosts.some((host) => uri.startsWith(host))) if (realDebridHosts.some((host) => uri.startsWith(host)))
return [Downloader.RealDebrid]; return [Downloader.RealDebrid];

View File

@@ -20,6 +20,7 @@ export interface GameRepack {
title: string; title: string;
fileSize: string | null; fileSize: string | null;
uris: string[]; uris: string[];
unavailableUris: string[];
uploadDate: string | null; uploadDate: string | null;
downloadSourceId: string; downloadSourceId: string;
downloadSourceName: string; downloadSourceName: string;