add new content end game
All checks were successful
Gitea Auto Deploy / Deploy-Container (push) Successful in 2m2s
All checks were successful
Gitea Auto Deploy / Deploy-Container (push) Successful in 2m2s
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
|
||||
import { AffixDetail, ASDetail, CharacterDetail, ConfigMaze, FreeSRJson, LightConeDetail, MocDetail, PFDetail, PSResponse, RelicDetail } from "@/types";
|
||||
import { AffixDetail, ASDetail, CharacterDetail, ConfigMaze, FreeSRJson, LightConeDetail, MocDetail, PeakDetail, PFDetail, PSResponse, RelicDetail } from "@/types";
|
||||
import axios from 'axios';
|
||||
import { pSResponseSchema } from "@/zod";
|
||||
|
||||
@@ -176,7 +176,6 @@ export async function fetchPFByIdNative(ids: string, locale: string): Promise<PF
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function fetchMOCByIdsNative(ids: string[], locale: string): Promise<Record<string, MocDetail[]> | null> {
|
||||
try {
|
||||
const res = await axios.post<Record<string, MocDetail[]>>(`/api/${locale}/moc`, { mocIds: ids });
|
||||
@@ -197,6 +196,27 @@ export async function fetchMOCByIdNative(ids: string, locale: string): Promise<M
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function fetchPeakByIdsNative(ids: string[], locale: string): Promise<Record<string, PeakDetail> | null> {
|
||||
try {
|
||||
const res = await axios.post<Record<string, PeakDetail>>(`/api/${locale}/peak`, { peakIds: ids });
|
||||
return res.data;
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch peak:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchPeakByIdNative(ids: string, locale: string): Promise<PeakDetail | null> {
|
||||
try {
|
||||
const res = await axios.get<PeakDetail>(`/api/${locale}/peak/${ids}`);
|
||||
return res.data;
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch peak:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function SendDataToServer(username: string, password: string, serverUrl: string, data: FreeSRJson | null): Promise<PSResponse | string> {
|
||||
try {
|
||||
const response = await axios.post(`${serverUrl}`, { username, password, data })
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { convertAvatar, convertEvent, convertLightcone, convertMonster, convertRelicSet } from "@/helper";
|
||||
import { ASDetail, CharacterBasic, CharacterBasicRaw, CharacterDetail, EventBasic, EventBasicRaw, LightConeBasic, LightConeBasicRaw, LightConeDetail, MocDetail, MonsterBasic, MonsterBasicRaw, MonsterDetail, PFDetail, RelicBasic, RelicBasicRaw, RelicDetail } from "@/types";
|
||||
import { ASDetail, CharacterBasic, CharacterBasicRaw, CharacterDetail, EventBasic, EventBasicRaw, LightConeBasic, LightConeBasicRaw, LightConeDetail, MocDetail, MonsterBasic, MonsterBasicRaw, MonsterDetail, PeakDetail, PFDetail, RelicBasic, RelicBasicRaw, RelicDetail } from "@/types";
|
||||
import axios from "axios";
|
||||
|
||||
export async function getLightconeInfoApi(lightconeId: number, locale: string): Promise<LightConeDetail | null> {
|
||||
@@ -134,6 +134,28 @@ export async function getPFEventInfoApi(eventId: number, locale: string): Promis
|
||||
}
|
||||
}
|
||||
|
||||
export async function getPeakEventInfoApi(eventId: number, locale: string): Promise<PeakDetail | null> {
|
||||
try {
|
||||
const res = await axios.get<PeakDetail>(
|
||||
`https://api.hakush.in/hsr/data/${locale}/peak/${eventId}.json`,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return res.data as PeakDetail;
|
||||
} catch (error: unknown) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
console.log(`Error: ${error.response?.status} - ${error.message}`);
|
||||
} else {
|
||||
console.log(`Unexpected error: ${String(error)}`);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getCharacterListApi(): Promise<CharacterBasic[]> {
|
||||
try {
|
||||
const res = await axios.get<Record<string, CharacterBasicRaw>>(
|
||||
@@ -278,6 +300,30 @@ export async function getPFEventListApi(): Promise<EventBasic[]> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getPEAKEventListApi(): Promise<EventBasic[]> {
|
||||
try {
|
||||
const res = await axios.get<Record<string, EventBasicRaw>>(
|
||||
'https://api.hakush.in/hsr/data/maze_peak.json',
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const data = new Map(Object.entries(res.data));
|
||||
|
||||
return Array.from(data.entries()).map(([id, it]) => convertEvent(id, it));
|
||||
} catch (error: unknown) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
console.log(`Error: ${error.response?.status} - ${error.message}`);
|
||||
} else {
|
||||
console.log(`Unexpected error: ${String(error)}`);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function getMonsterListApi(): Promise<{list: MonsterBasic[], map: Record<string, MonsterBasic>}> {
|
||||
try {
|
||||
const res = await axios.get<Record<string, MonsterBasicRaw>>(
|
||||
|
||||
@@ -6,3 +6,5 @@ export * from "./relicLoader";
|
||||
export * from "./asLoader";
|
||||
export * from "./pfLoader";
|
||||
export * from "./mocLoader";
|
||||
export * from "./peakLoader";
|
||||
|
||||
|
||||
51
src/lib/loader/peakLoader.ts
Normal file
51
src/lib/loader/peakLoader.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { PeakDetail } from '@/types';
|
||||
import { getPeakEventInfoApi } from '../api';
|
||||
|
||||
const DATA_DIR = path.join(process.cwd(), 'data');
|
||||
const peakFileCache: Record<string, Record<string, PeakDetail>> = {};
|
||||
export let peakMap: Record<string, PeakDetail> = {};
|
||||
|
||||
function getJsonFilePath(locale: string): string {
|
||||
return path.join(DATA_DIR, `peak.${locale}.json`);
|
||||
}
|
||||
|
||||
function loadFromFileIfExists(locale: string): Record<string, PeakDetail> | null {
|
||||
if (peakFileCache[locale]) return peakFileCache[locale];
|
||||
|
||||
const filePath = getJsonFilePath(locale);
|
||||
if (fs.existsSync(filePath)) {
|
||||
const data = JSON.parse(fs.readFileSync(filePath, 'utf-8')) as Record<string, PeakDetail>;
|
||||
peakFileCache[locale] = data;
|
||||
return data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function loadPeak(charIds: string[], locale: string): Promise<Record<string, PeakDetail>> {
|
||||
const fileData = loadFromFileIfExists(locale);
|
||||
const fileIds = fileData ? Object.keys(fileData) : [];
|
||||
|
||||
if (fileData && charIds.every(id => fileIds.includes(id))) {
|
||||
peakMap = fileData;
|
||||
return peakMap;
|
||||
}
|
||||
|
||||
const result: Record<string, PeakDetail> = {};
|
||||
|
||||
await Promise.all(
|
||||
charIds.map(async id => {
|
||||
const info = await getPeakEventInfoApi(Number(id), locale);
|
||||
if (info) result[id] = info;
|
||||
})
|
||||
);
|
||||
|
||||
fs.mkdirSync(DATA_DIR, { recursive: true });
|
||||
const filePath = getJsonFilePath(locale);
|
||||
fs.writeFileSync(filePath, JSON.stringify(result, null, 2), 'utf-8');
|
||||
|
||||
peakFileCache[locale] = result;
|
||||
peakMap = result;
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user