mirror of
https://github.com/StepanovPlaton/torrent_frontend.git
synced 2026-04-03 20:30:48 +04:00
Add game cards and dev reverse proxy
This commit is contained in:
11
src/entities/game/game.ts
Normal file
11
src/entities/game/game.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { HTTPService } from "@/shared/http/httpService";
|
||||
import { gameCardsSchema, GameCardType } from "./schemas/gameCard";
|
||||
|
||||
export abstract class GameService {
|
||||
public static async getGameCards() {
|
||||
return await HTTPService.get<GameCardType[]>(
|
||||
"/games/cards",
|
||||
gameCardsSchema
|
||||
);
|
||||
}
|
||||
}
|
||||
5
src/entities/game/index.ts
Normal file
5
src/entities/game/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { GameCardType } from "./schemas/gameCard";
|
||||
import { GameType } from "./schemas/game";
|
||||
import { GameService } from "./game";
|
||||
|
||||
export { GameService, type GameType, type GameCardType };
|
||||
35
src/entities/game/schemas/game.ts
Normal file
35
src/entities/game/schemas/game.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { z } from "zod";
|
||||
import { gameCardSchema } from "./gameCard";
|
||||
|
||||
export const gameSchema = z.union([
|
||||
gameCardSchema,
|
||||
z.object({
|
||||
torrent_file: z.string().min(1),
|
||||
language: z.string().optional(),
|
||||
version: z.string().optional(),
|
||||
download_size: z.string().optional(),
|
||||
system: z.string().optional(),
|
||||
processor: z.string().optional(),
|
||||
memory: z.string().optional(),
|
||||
graphics: z.string().optional(),
|
||||
storage: z.string().optional(),
|
||||
upload_date: z
|
||||
.string()
|
||||
.min(1)
|
||||
.transform((d) => new Date(d)),
|
||||
}),
|
||||
]);
|
||||
export type GameType = z.infer<typeof gameSchema>;
|
||||
|
||||
export const isGame = (a: any): a is GameType => {
|
||||
return gameSchema.safeParse(a).success;
|
||||
};
|
||||
|
||||
export const gamesSchema = z.array(z.any()).transform((a) => {
|
||||
const games: GameType[] = [];
|
||||
a.forEach((e) => {
|
||||
if (isGame(e)) games.push(gameSchema.parse(e));
|
||||
else console.error("Game parse error - ", e);
|
||||
});
|
||||
return games;
|
||||
});
|
||||
31
src/entities/game/schemas/gameCard.ts
Normal file
31
src/entities/game/schemas/gameCard.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const gameCardSchema = z.object({
|
||||
id: z.number(),
|
||||
title: z.string().min(3),
|
||||
cover: z
|
||||
.string()
|
||||
.optional()
|
||||
.transform((u) => {
|
||||
if (!!u) return process.env.NEXT_PUBLIC_COVER_FULL_URL + "/" + u;
|
||||
}),
|
||||
description: z.string().optional(),
|
||||
release_date: z
|
||||
.string()
|
||||
.min(1)
|
||||
.transform((d) => new Date(d)),
|
||||
});
|
||||
export type GameCardType = z.infer<typeof gameCardSchema>;
|
||||
|
||||
export const isGameCard = (a: any): a is GameCardType => {
|
||||
return gameCardSchema.safeParse(a).success;
|
||||
};
|
||||
|
||||
export const gameCardsSchema = z.array(z.any()).transform((a) => {
|
||||
const cards: GameCardType[] = [];
|
||||
a.forEach((e) => {
|
||||
if (isGameCard(e)) cards.push(gameCardSchema.parse(e));
|
||||
else console.error("GameCard parse error - ", e);
|
||||
});
|
||||
return cards;
|
||||
});
|
||||
Reference in New Issue
Block a user