fix. utils 함수 리팩토링
This commit is contained in:
@@ -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}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user