import type { ReqGameMaintenance, ResGameMaintenance, } from '#layers/types/GameMaintenanceType' /** * 게임 점검 */ const useGetGameMaintenance = () => { const inspectionStore = useInspectionStore() const logPrefix = { exception: '[Exception] /composables/useGetGameMaintenance', failure: '[Failure] /composables/useGetGameMaintenance', } const isGameMaintenance = ref(false) // 게임 서버 점검 여부 // [Setter] 게임 서버 점검 여부 세팅 const setIsGameMaintenance = (status: boolean) => { isGameMaintenance.value = status } // 게임 점검이 아닌 경우 일괄 세팅 const setGameMaintenanceFalse = () => { setIsGameMaintenance(false) inspectionStore.setGameMaintenanceStatus(false) inspectionStore.setGameMaintenanceData({ ts_start_date: 0, ts_end_date: 0, detail_link: '', }) } /** * 게임 서버 점검 여부 * * @param {ReqGameMaintenance} req * @description https://wiki.smilegate.net/pages/viewpage.action?pageId=362619887 */ const checkGameMaintenance = async (req: ReqGameMaintenance) => { let res: ResGameMaintenance = {} as ResGameMaintenance try { const baseApiUrl = req.baseApiUrl || '' // Path Variables const category = req.category || 'GAME' const serviceId1 = req.service_id1 || '' const lang = req.lang || 'ko' const url = `${baseApiUrl}/v2.0/maintenances/${category}/${serviceId1}/${lang}` res = (await commonFetch('GET', url, {})) as ResGameMaintenance if (res != null && res.code === 0) { // FIXME: 테스트용 데이터 --------------------------------------------------- /* const runtimeConfig = useRuntimeConfig() if (['local', 'local-gate8', 'dev'].includes(`${runtimeConfig.public.runType}`)) { res.value = { total_count: 1, list: [ { start_at: new Date().getTime(), end_at: new Date().getTime(), languages: [{ link: 'https://www.onstove.com', lang: 'ko', title: '', content: '' }], maintenance_no: 0, category: '', service_id1: '', service_id2: [], type: '', description: '' } ] } } */ // ------------------------------------------------------------------------ if ( Number(res.value?.total_count) > 0 && res.value?.list != null && res.value?.list.length > 0 ) { setIsGameMaintenance(true) // 서버 1개 이상 점검일 경우 점검 중으로 간주 inspectionStore.setGameMaintenanceData({ ts_start_date: res.value?.list[0].start_at || 0, ts_end_date: res.value?.list[0].end_at || 0, detail_link: res.value?.list[0].languages[0].link || '', }) inspectionStore.setGameMaintenanceStatus(true) } else { setGameMaintenanceFalse() } } else { // [500] 내부 서버 에러 // [70001] 부적절한 엑세스 토큰 // [70051] 부적절한 파라미터 요청 - {param_key} // [70052] 데이터를 찾을 수 않음 setGameMaintenanceFalse() } } catch (e) { console.error(`${logPrefix.exception}.checkGameMaintenance: `, e) res = { code: -99999, message: `${e}` } setGameMaintenanceFalse() } return res } return { isGameMaintenance, checkGameMaintenance } } export { useGetGameMaintenance }