mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-02 16:23:48 +03:00
Merge pull request #1261 from hydralauncher/fix/correct-subscription-date-validation
fix: subscription date validation
This commit is contained in:
commit
57e0fb493f
@ -1,5 +1,4 @@
|
|||||||
import { registerEvent } from "../register-event";
|
import { registerEvent } from "../register-event";
|
||||||
import parseTorrent from "parse-torrent";
|
|
||||||
import type { StartGameDownloadPayload } from "@types";
|
import type { StartGameDownloadPayload } from "@types";
|
||||||
import { DownloadManager, HydraApi, logger } from "@main/services";
|
import { DownloadManager, HydraApi, logger } from "@main/services";
|
||||||
|
|
||||||
@ -9,7 +8,6 @@ import { createGame } from "@main/services/library-sync";
|
|||||||
import { steamUrlBuilder } from "@shared";
|
import { steamUrlBuilder } from "@shared";
|
||||||
import { dataSource } from "@main/data-source";
|
import { dataSource } from "@main/data-source";
|
||||||
import { DownloadQueue, Game } from "@main/entity";
|
import { DownloadQueue, Game } from "@main/entity";
|
||||||
import { HydraAnalytics } from "@main/services/hydra-analytics";
|
|
||||||
|
|
||||||
const startGameDownload = async (
|
const startGameDownload = async (
|
||||||
_event: Electron.IpcMainInvokeEvent,
|
_event: Electron.IpcMainInvokeEvent,
|
||||||
@ -91,17 +89,6 @@ const startGameDownload = async (
|
|||||||
logger.error("Failed to create game download", err);
|
logger.error("Failed to create game download", err);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (uri.startsWith("magnet:")) {
|
|
||||||
try {
|
|
||||||
const { infoHash } = await parseTorrent(payload.uri);
|
|
||||||
if (infoHash) {
|
|
||||||
HydraAnalytics.postDownload(infoHash).catch(() => {});
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
logger.error("Failed to parse torrent", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await DownloadManager.cancelDownload(updatedGame!.id);
|
await DownloadManager.cancelDownload(updatedGame!.id);
|
||||||
await DownloadManager.startDownload(updatedGame!);
|
await DownloadManager.startDownload(updatedGame!);
|
||||||
|
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
import { userSubscriptionRepository } from "@main/repository";
|
|
||||||
import axios from "axios";
|
|
||||||
import { appVersion } from "@main/constants";
|
|
||||||
|
|
||||||
export class HydraAnalytics {
|
|
||||||
private static instance = axios.create({
|
|
||||||
baseURL: import.meta.env.MAIN_VITE_ANALYTICS_API_URL,
|
|
||||||
headers: { "User-Agent": `Hydra Launcher v${appVersion}` },
|
|
||||||
});
|
|
||||||
|
|
||||||
private static async hasActiveSubscription() {
|
|
||||||
const userSubscription = await userSubscriptionRepository.findOne({
|
|
||||||
where: { id: 1 },
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
userSubscription?.expiresAt && userSubscription.expiresAt > new Date()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static async postDownload(hash: string) {
|
|
||||||
const hasSubscription = await this.hasActiveSubscription();
|
|
||||||
|
|
||||||
return this.instance
|
|
||||||
.post("/track", {
|
|
||||||
event: "download",
|
|
||||||
attributes: {
|
|
||||||
hash,
|
|
||||||
hasSubscription,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.then((response) => response.data);
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,6 +12,7 @@ import { UserNotLoggedInError, SubscriptionRequiredError } from "@shared";
|
|||||||
import { omit } from "lodash-es";
|
import { omit } from "lodash-es";
|
||||||
import { appVersion } from "@main/constants";
|
import { appVersion } from "@main/constants";
|
||||||
import { getUserData } from "./user/get-user-data";
|
import { getUserData } from "./user/get-user-data";
|
||||||
|
import { isFuture, isToday } from "date-fns";
|
||||||
|
|
||||||
interface HydraApiOptions {
|
interface HydraApiOptions {
|
||||||
needsAuth?: boolean;
|
needsAuth?: boolean;
|
||||||
@ -45,10 +46,8 @@ export class HydraApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static hasActiveSubscription() {
|
private static hasActiveSubscription() {
|
||||||
return (
|
const expiresAt = this.userAuth.subscription?.expiresAt;
|
||||||
this.userAuth.subscription?.expiresAt &&
|
return expiresAt && (isFuture(expiresAt) || isToday(expiresAt));
|
||||||
this.userAuth.subscription.expiresAt > new Date()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async handleExternalAuth(uri: string) {
|
static async handleExternalAuth(uri: string) {
|
||||||
|
@ -14,6 +14,7 @@ import type {
|
|||||||
UserDetails,
|
UserDetails,
|
||||||
} from "@types";
|
} from "@types";
|
||||||
import { UserFriendModalTab } from "@renderer/pages/shared-modals/user-friend-modal";
|
import { UserFriendModalTab } from "@renderer/pages/shared-modals/user-friend-modal";
|
||||||
|
import { isFuture, isToday } from "date-fns";
|
||||||
|
|
||||||
export function useUserDetails() {
|
export function useUserDetails() {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
@ -128,10 +129,8 @@ export function useUserDetails() {
|
|||||||
const unblockUser = (userId: string) => window.electron.unblockUser(userId);
|
const unblockUser = (userId: string) => window.electron.unblockUser(userId);
|
||||||
|
|
||||||
const hasActiveSubscription = useMemo(() => {
|
const hasActiveSubscription = useMemo(() => {
|
||||||
return (
|
const expiresAt = userDetails?.subscription?.expiresAt;
|
||||||
userDetails?.subscription?.expiresAt &&
|
return expiresAt && (isFuture(expiresAt) || isToday(expiresAt));
|
||||||
new Date(userDetails.subscription.expiresAt) > new Date()
|
|
||||||
);
|
|
||||||
}, [userDetails]);
|
}, [userDetails]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -75,7 +75,7 @@ export function CloudSyncFilesModal({
|
|||||||
showSuccessToast(t("custom_backup_location_set"));
|
showSuccessToast(t("custom_backup_location_set"));
|
||||||
getGameBackupPreview();
|
getGameBackupPreview();
|
||||||
}
|
}
|
||||||
}, [objectId, setValue, shop, showSuccessToast, getGameBackupPreview]);
|
}, [objectId, setValue, shop, showSuccessToast, getGameBackupPreview, t]);
|
||||||
|
|
||||||
const handleFileMappingMethodClick = useCallback(
|
const handleFileMappingMethodClick = useCallback(
|
||||||
(mappingOption: FileMappingMethod) => {
|
(mappingOption: FileMappingMethod) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user