120 lines
4.2 KiB
TypeScript
120 lines
4.2 KiB
TypeScript
import type {
|
|
ReqGetGdsClientPolicyTotal,
|
|
ResGetGdsClientPolicyTotal,
|
|
} from '#layers/types/GdsType'
|
|
import { DEFAULT_LOCALE_CODE } from '@/i18n.config'
|
|
|
|
/**
|
|
* GDS
|
|
*
|
|
* @description https://wiki.smilegate.net/display/SDKAPIDOCU/51-09.+gds
|
|
*/
|
|
const useGds = () => {
|
|
const logPrefix = {
|
|
exception: '[Exception] /composables/useGds',
|
|
failure: '[Failure] /composables/useGds',
|
|
}
|
|
|
|
const countryCode = ref('') // 국가 코드
|
|
const isKorea = ref(false) // 대한민국 여부
|
|
const isTaiwanHongKongMacau = ref(false) // 대홍마 여부
|
|
const isNorthAmerica = ref(false) // 북미 여부
|
|
|
|
// [Setter] 사전등록 - 국가 코드 세팅
|
|
const setCountryCode = (newCountryCode: string) => {
|
|
countryCode.value = newCountryCode
|
|
}
|
|
// [Setter] 사전등록 - 대한민국 여부 세팅
|
|
const setIsKorea = (newIsKorea: boolean) => {
|
|
isKorea.value = newIsKorea
|
|
}
|
|
// [Setter] 사전등록 - 대홍마 여부 세팅
|
|
const setIsTaiwanHongKongMacau = (newIsTaiwanHongKongMacau: boolean) => {
|
|
isTaiwanHongKongMacau.value = newIsTaiwanHongKongMacau
|
|
}
|
|
// [Setter] 사전등록 - 북미 여부 세팅
|
|
const setIsNorthAmerica = (newIsNorthAmerica: boolean) => {
|
|
isNorthAmerica.value = newIsNorthAmerica
|
|
}
|
|
|
|
// 사전 등록 - 특정 국가 여부 조회 (IP 기반)
|
|
const checkCountryByIp = async (req: ReqGetGdsClientPolicyTotal) => {
|
|
let res: ResGetGdsClientPolicyTotal
|
|
const arrKorea = ['KR'] // cf. UM: 미국령 군소 제도의 기 미국령 군소 제도, VI: 미국령 버진아일랜드의 기 미국령 버진아일랜드
|
|
const arrNorthAmerica = ['US', 'CA'] // cf. UM: 미국령 군소 제도의 기 미국령 군소 제도, VI: 미국령 버진아일랜드의 기 미국령 버진아일랜드
|
|
const arrTaiwanHongKongMacau = ['TW', 'HK', 'MO'] // 대만, 홍콩, 마카오 국가 코드
|
|
try {
|
|
if (`${req.runType}` !== 'live' && req.qc != null && req.qc !== '') {
|
|
// Live가 아닌 환경에서 qc가 있으면 국가 코드로 설정하여 판별
|
|
setCountryCode(req.qc || '')
|
|
setIsKorea(arrKorea.includes(req.qc))
|
|
setIsTaiwanHongKongMacau(arrTaiwanHongKongMacau.includes(req.qc))
|
|
setIsNorthAmerica(arrNorthAmerica.includes(req.qc))
|
|
|
|
res = {
|
|
code: 0,
|
|
message: '',
|
|
res_code: 0,
|
|
res_data: {
|
|
is_default: true,
|
|
nation: req.qc,
|
|
regulation: '',
|
|
timezone: '',
|
|
utc_offset: 0,
|
|
lang: req.client_lang || DEFAULT_LOCALE_CODE,
|
|
coverages: [],
|
|
},
|
|
} as ResGetGdsClientPolicyTotal
|
|
} else {
|
|
const config = useRuntimeConfig()
|
|
const stoveApiBaseUrl = config.public.stoveApiUrl
|
|
|
|
const url = `${stoveApiBaseUrl}/gds/v2/client/policy/total`
|
|
const query = {
|
|
policy_grp: req.policy_grp || 'onstove',
|
|
device_nation: req.device_nation || 'KR',
|
|
client_lang: req.client_lang || DEFAULT_LOCALE_CODE,
|
|
include_coverages: req.include_coverages || false,
|
|
}
|
|
res = (await commonFetch('GET', url, {
|
|
query,
|
|
})) as ResGetGdsClientPolicyTotal
|
|
|
|
if (res != null && res.res_code === 0) {
|
|
// is_default = false : 국가코드를 정상 처리했으나 타임존을 처리하지 못한 경우
|
|
// is_default = true : device_nation 또는 policy_grp 별 디폴트 값으로 처리된 경우
|
|
if (res.res_data != null && res.res_data.nation != null) {
|
|
setCountryCode(res.res_data.nation || '')
|
|
setIsKorea(arrKorea.includes(res.res_data.nation))
|
|
setIsTaiwanHongKongMacau(
|
|
arrTaiwanHongKongMacau.includes(res.res_data.nation)
|
|
)
|
|
setIsNorthAmerica(arrNorthAmerica.includes(res.res_data.nation))
|
|
}
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.error(`${logPrefix.exception}.checkCountryByIp: `, e)
|
|
res = {
|
|
code: -99999,
|
|
message: `${e}`,
|
|
}
|
|
setCountryCode('')
|
|
setIsKorea(false)
|
|
setIsTaiwanHongKongMacau(false)
|
|
setIsNorthAmerica(false)
|
|
}
|
|
return res
|
|
}
|
|
|
|
return {
|
|
isKorea,
|
|
isTaiwanHongKongMacau,
|
|
isNorthAmerica,
|
|
countryCode,
|
|
checkCountryByIp,
|
|
}
|
|
}
|
|
|
|
export { useGds }
|