404에러 패치
This commit is contained in:
@@ -6,6 +6,12 @@
|
||||
*/
|
||||
|
||||
import type { StrategyFlowLayoutStore } from './strategyEditorLayoutStorage';
|
||||
import {
|
||||
isStrategyMissingOnServer,
|
||||
markStrategyMissingFromPath,
|
||||
} from './strategyMissingCache';
|
||||
|
||||
export { isStrategyMissingOnServer } from './strategyMissingCache';
|
||||
|
||||
/** 백엔드 REST base (Docker 빌드: `/api`, 로컬 Vite: `.env` 또는 localhost:8080) */
|
||||
export const API_BASE = import.meta.env.VITE_API_BASE_URL ?? 'http://localhost:8080/api';
|
||||
@@ -90,18 +96,6 @@ async function requestOrThrow<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
return JSON.parse(text) as T;
|
||||
}
|
||||
|
||||
/** 서버에 없는 전략 ID — 삭제·만료 후 반복 404 방지 (태블릿·Safari 네트워크 로그 완화) */
|
||||
const strategyMissingIds = new Set<number>();
|
||||
|
||||
export function isStrategyMissingOnServer(strategyId: number): boolean {
|
||||
return strategyId > 0 && strategyMissingIds.has(strategyId);
|
||||
}
|
||||
|
||||
function markStrategyMissingFromPath(pathOnly: string): void {
|
||||
const m = pathOnly.match(/^\/strategies\/(\d+)(?:\/|$)/);
|
||||
if (m) strategyMissingIds.add(Number(m[1]));
|
||||
}
|
||||
|
||||
async function request<T>(path: string, init?: RequestInit): Promise<T | null> {
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}${path}`, {
|
||||
@@ -1073,15 +1067,22 @@ export interface StrategyDto {
|
||||
updatedAt?: string;
|
||||
}
|
||||
|
||||
/** 전략 목록 로드 */
|
||||
/** 전략 목록 로드 + localStorage·설정의 stale strategyId 정리 */
|
||||
export async function loadStrategies(): Promise<StrategyDto[]> {
|
||||
if (!hasRegisteredUser()) return [];
|
||||
return (await request<StrategyDto[]>('/strategies')) ?? [];
|
||||
const list = (await request<StrategyDto[]>('/strategies')) ?? [];
|
||||
try {
|
||||
const { applyStrategyReferenceSanitize } = await import('./strategyReferenceSanitize');
|
||||
await applyStrategyReferenceSanitize(list);
|
||||
} catch (e) {
|
||||
console.warn('[backendApi] strategy reference sanitize failed', e);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/** 단일 전략 로드 */
|
||||
export async function loadStrategy(id: number): Promise<StrategyDto | null> {
|
||||
if (!hasRegisteredUser() || id <= 0 || strategyMissingIds.has(id)) return null;
|
||||
if (!hasRegisteredUser() || id <= 0 || isStrategyMissingOnServer(id)) return null;
|
||||
return request<StrategyDto>(`/strategies/${id}`);
|
||||
}
|
||||
|
||||
@@ -1426,7 +1427,7 @@ const repairInflight = new Set<number>();
|
||||
|
||||
/** DB DSL TIMEFRAME 래핑 보정 — 전략 없으면 호출 안 함(404 방지) */
|
||||
export async function repairStrategyTimeframes(strategyId: number): Promise<boolean> {
|
||||
if (!hasRegisteredUser() || strategyId <= 0 || strategyMissingIds.has(strategyId)) return false;
|
||||
if (!hasRegisteredUser() || strategyId <= 0 || isStrategyMissingOnServer(strategyId)) return false;
|
||||
if (repairSkipIds.has(strategyId) || repairInflight.has(strategyId)) return false;
|
||||
|
||||
repairInflight.add(strategyId);
|
||||
|
||||
Reference in New Issue
Block a user