이름: solution/front → solution/frontend

`backend` 옆에 `front` 가 있을 이유가 없었다. negosium 의 negodata/front 를 그대로
베꼈고 그게 왜 front 인지는 따져보지 않았다 — 근거 없이 들여온 이름이라 바로잡는다.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019uYhHQdssRubirPirrdJJC
This commit is contained in:
minaChoiandClaude Opus 5 committed 2026-08-31 15:27:16 +09:00
1 parent 06f6438d9b
commit c85c577349
480 files changed
+22 -22

No files matched your search

@@ -0,0 +1,128 @@
/**
* 수집에 딸린 잡 실행과 캐시 정리 — React 를 모르는 부분.
*
* ★ 훅 상태를 건드리지 않는 일만 모았다. 하는 일은 "잡을 넣고 → 폴링하고 → 캐시를
* 무효화하고 → 결과를 알린다" 뿐이라 컴포넌트 마운트와 아무 상관이 없다. 훅 안에 두면
* 수집 흐름(단계 전이)과 잡 실행이 한 덩어리로 보여 어느 쪽을 고치는지 흐려진다.
*/
import type {JobData} from '@/api';
import {
getGetPlaceQueryKey,
getListFactsQueryKey,
getListFaqsQueryKey,
getListLinksQueryKey,
getListMediaQueryKey,
pollJob,
startCopy,
startVision,
} from '@/api';
import {notify, notifyApiError} from '@/lib/notify';
import {queryClient} from '@/lib/query-client';
import {notifyCopy, notifyVision} from './collectNotify';
import type {RecollectTask} from './useCollectFlow';
/** 재수집 작업의 화면 표시명. */
export const RECOLLECT_LABEL: Record<RecollectTask, string> = {
facts: '정보',
photos: '사진',
copy: '소개문',
};
/**
* 사진 분석 · 소개문 생성 잡 1회분.
*
* 수집(runCollect)과 달리 훅 상태를 건드리지 않아 모듈 함수로 둔다 —
* 하는 일은 "잡을 넣고 → 폴링하고 → 캐시를 무효화하고 → 결과를 알린다" 뿐이다.
*/
export async function runSideJob(task: 'photos' | 'copy', placeId: string, signal: AbortSignal) {
const label = RECOLLECT_LABEL[task];
let jobId: string;
try {
const started =
task === 'photos'
? // ★ force:true — 이미 alt 가 붙은 사진도 다시 분석한다. 사장님이 일부러 누른 버튼이라
// "분석할 사진이 없습니다"로 끝나면 재분석이라는 이름값을 못 한다.
await startVision(placeId, {force: true}, undefined, signal)
: await startCopy(placeId, {}, undefined, signal);
// 거절도 HTTP 200 이다 — 사진 0장(MEDIA_NOT_FOUND)·근거 부족(FAQ_UNGROUNDED)·
// 키 미설정(GENERATOR_NOT_CONFIGURED)이 전부 이 자리로 온다.
if (started.result?.success === false || !started.job_id) {
notifyApiError({data: started}, `${label}을 시작하지 못했습니다.`);
return;
}
jobId = started.job_id;
} catch (error) {
if (signal.aborted) return;
notifyApiError(error, `${label}을 시작하지 못했습니다.`);
return;
}
const outcome = await pollJob(jobId, {signal});
switch (outcome.kind) {
case 'aborted':
return;
case 'dead':
notify.error(`${label}을 끝내지 못했습니다.`, outcome.job.last_error ?? undefined);
return;
case 'unreachable':
notifyApiError(outcome.error, `${label} 상태를 확인하지 못했습니다.`);
return;
case 'timeout':
notify.warn(
`${label}이 예상보다 오래 걸립니다.`,
'서버에서는 계속 진행됩니다. 잠시 후 다시 확인해 주세요.',
);
return;
case 'done':
if (task === 'photos') {
// 사진은 media 가 진실이다 — 라벨·alt 가 바뀌었으니 다시 읽게 한다.
await invalidate(getListMediaQueryKey(placeId));
notifyVision(outcome.job);
} else {
// 소개문은 fact(intro·meta_description)로, FAQ 는 faq 로 들어간다 — 둘 다 무효화한다.
await invalidate(getListFactsQueryKey(placeId), getListFaqsQueryKey(placeId));
notifyCopy(outcome.job);
}
}
}
/**
* 수집이 큐에 넣은 사진 분석 잡을 기다린다.
*
* 잡 id 는 수집 결과(`result.vision_job_id`)에 실려 온다 — 사진이 한 장도 없으면 없다.
* 실패·타임아웃은 조용히 넘어간다: 사진이 늦게 붙을 뿐 수집 자체는 성공이고,
* 여기서 화면을 막으면 사장님이 다음으로 못 간다.
*/
export async function waitForVision(placeId: string, job: JobData, signal: AbortSignal) {
const visionJobId = (job.result as {vision_job_id?: string} | undefined)?.vision_job_id;
if (!visionJobId) return;
const outcome = await pollJob(visionJobId, {signal});
if (outcome.kind === 'done') await refreshPlaceCaches(placeId);
}
/**
* 수집이 끝난 뒤 서버가 진실인 것들 — place(주소·갱신시각) · 링크 · fact · **사진**.
*
* ★ media 를 빠뜨리면 사진이 서버에 10장 들어와도 화면은 빈 목록을 계속 본다.
* 실제로 그랬다 — "이미지 왜 못 가져오냐"의 원인이 수집이 아니라 여기였다.
* 목록에 뭘 더할 때는 화면이 그 값을 어디서 읽는지 같이 확인해야 한다.
*/
export async function refreshPlaceCaches(placeId: string) {
await Promise.all([
queryClient.invalidateQueries({queryKey: getGetPlaceQueryKey(placeId)}),
queryClient.invalidateQueries({queryKey: getListLinksQueryKey(placeId)}),
queryClient.invalidateQueries({queryKey: getListFactsQueryKey(placeId)}),
queryClient.invalidateQueries({queryKey: getListMediaQueryKey(placeId)}),
]).catch(() => undefined);
}
/**
* 캐시 무효화 묶음. 실패해도 삼킨다 — 화면이 한 박자 늦게 갱신될 뿐이고, 잡은 이미 끝났다.
*
* 생성물 쿼리 키는 `as const` 라 안쪽도 readonly 다 — 그 모양 그대로 받는다.
*/
export async function invalidate(...queryKeys: readonly (readonly unknown[])[]) {
await Promise.all(
queryKeys.map((queryKey) => queryClient.invalidateQueries({queryKey})),
).catch(() => undefined);
}