fix. utils 함수 리팩토링

This commit is contained in:
clkim
2025-12-01 14:23:35 +09:00
parent 10ce30e149
commit 9b3b7b4ee3
20 changed files with 120 additions and 162 deletions

View File

@@ -53,3 +53,34 @@ export const formatPathWithoutLocale = (path: string): string => {
export const isInternalUrl = (url?: string): boolean => {
return !!url && !url.startsWith('http')
}
/**
* 리소스 경로를 완전한 호스트 URL로 변환합니다.
* @param path 리소스 경로
* @returns 완전한 리소스 URL
*/
export const formatPathHost = (
path: string,
options: { imageType?: 'common' | 'game'; isSkipHost?: boolean } = {}
): string => {
if (!path) return ''
if (/^(https?:\/\/|www\.)/.test(path)) return path
const runtimeConfig = useRuntimeConfig()
const { staticUrl, assetsUrl } = runtimeConfig.public
const { imageType = 'game', isSkipHost = false } = options
const isDevelopment = import.meta.dev
const isTypeGame = imageType === 'game'
if (isSkipHost) return path
// 개발 환경일 때는 루트 경로 생략
if (!isTypeGame && isDevelopment) return path
// 게임/공통 여부에 따른 경로 결정
const basePath = isTypeGame ? staticUrl : assetsUrl
return `${basePath}${path}`
}