스킨 목록은 리플레이를 열 때마다 새로 받음 (그사이 뽑힌 스킨이 보이게) · 없는 스킨 요청을 100개씩 나눠 전부 · 맵 · 스킨 타이머를 OnCalendar 로 02:00~07:00 제외 (맵 타이머 Persistent · OnBootSec 뺌) · 테스트
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -391,10 +391,12 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
|
||||
const skinByPlayer = skinTracks(replay);
|
||||
let skinIdx: Awaited<ReturnType<typeof loadSkins>> = null;
|
||||
if (replay.skins?.length) {
|
||||
// 열 때마다 새 목록 (그사이 뽑힌 스킨이 보이게)
|
||||
void loadSkins().then((ix) => {
|
||||
if (!disposed) skinIdx = ix;
|
||||
if (disposed || !ix) return;
|
||||
skinIdx = ix;
|
||||
void requestMissing(ix, replay);
|
||||
});
|
||||
void requestMissing(replay);
|
||||
}
|
||||
const skinLookAt = (p: number, t: number) => {
|
||||
const s = equipAt(skinByPlayer[p], t);
|
||||
|
||||
@@ -26,14 +26,14 @@ export const isDefaultSkin = (s: SkinInfo) => /_Standard_PrimaryAsset$/.test(s.s
|
||||
|
||||
export const skinFileUrl = (file: string) => `/site/maps3d/skins/${encodeURIComponent(file)}`;
|
||||
|
||||
/** 스킨 목록. 부를 때마다 새로 받는다 (리플레이를 다시 열면 그사이 뽑힌 스킨이 보이게). 받는 중이면 그 요청을 같이 쓴다 */
|
||||
let indexP: Promise<SkinsIndex | null> | null = null;
|
||||
export function loadSkins(): Promise<SkinsIndex | null> {
|
||||
indexP ??= fetch('/site/maps3d/skins', { credentials: 'same-origin' })
|
||||
indexP ??= fetch('/site/maps3d/skins', { credentials: 'same-origin', cache: 'no-store' })
|
||||
.then((r) => (r.ok ? (r.json() as Promise<SkinsIndex>) : null))
|
||||
.catch(() => null)
|
||||
.then((d) => {
|
||||
if (!d) indexP = null;
|
||||
return d;
|
||||
.finally(() => {
|
||||
indexP = null;
|
||||
});
|
||||
return indexP;
|
||||
}
|
||||
@@ -56,17 +56,28 @@ export function missingSkins(idx: SkinsIndex, r: Pick<ReplayFile, 'skins'>): str
|
||||
return [...out];
|
||||
}
|
||||
|
||||
/** 없는 스킨을 뽑아 달라고 요청한다 (한 번에 100개까지, 실패해도 그냥 기본 스킨) */
|
||||
export async function requestMissing(r: Pick<ReplayFile, 'skins'>): Promise<number> {
|
||||
const idx = await loadSkins();
|
||||
if (!idx) return 0;
|
||||
const keys = missingSkins(idx, r).slice(0, 100);
|
||||
if (!keys.length) return 0;
|
||||
const res = await fetch('/site/maps3d/skins/want', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({ keys }),
|
||||
}).catch(() => null);
|
||||
return res?.ok ? (((await res.json()) as { queued?: number }).queued ?? 0) : 0;
|
||||
/** 요청 한 번에 보내는 열쇠 수 (서버 MAX_WANT_PER_REQUEST 와 같다) */
|
||||
export const WANT_CHUNK = 100;
|
||||
|
||||
/** 열쇠를 WANT_CHUNK 개씩 나눈다 */
|
||||
export function chunks<T>(list: T[], n = WANT_CHUNK): T[][] {
|
||||
const out: T[][] = [];
|
||||
for (let i = 0; i < list.length; i += n) out.push(list.slice(i, i + n));
|
||||
return out;
|
||||
}
|
||||
|
||||
/** 없는 스킨을 뽑아 달라고 요청한다 (100개씩 나눠 전부, 실패해도 그냥 기본 스킨). 넣은 개수 */
|
||||
export async function requestMissing(idx: SkinsIndex, r: Pick<ReplayFile, 'skins'>): Promise<number> {
|
||||
let queued = 0;
|
||||
for (const keys of chunks(missingSkins(idx, r))) {
|
||||
const res = await fetch('/site/maps3d/skins/want', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({ keys }),
|
||||
}).catch(() => null);
|
||||
if (!res?.ok) break;
|
||||
queued += ((await res.json()) as { queued?: number }).queued ?? 0;
|
||||
}
|
||||
return queued;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user