refactor: deduplicate splitFilePath and getResourceURL

Extract shared file path and resource URL utilities to
src/utils/resourceUrl.ts, eliminating exact duplicates
between load3d and audio widget code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Alexander Brown
2026-03-05 16:05:09 -08:00
parent dad9b4e71e
commit 2205ead595
4 changed files with 3 additions and 30 deletions

View File

@@ -3,7 +3,7 @@ import { t } from '@/i18n'
import { useToastStore } from '@/platform/updates/common/toastStore'
import { api } from '@/scripts/api'
import { getResourceURL, splitFilePath } from './load3dFileUtils'
import { getResourceURL, splitFilePath } from '@/utils/resourceUrl'
class Load3dUtils {
static async generateThumbnailIfNeeded(

View File

@@ -1,7 +1,7 @@
import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
import { getResourceURL, splitFilePath } from './load3dFileUtils'
import { getResourceURL, splitFilePath } from '@/utils/resourceUrl'
import {
type BackgroundRenderModeType,
type EventManagerInterface,

View File

@@ -1,5 +1,4 @@
import type { ResultItemType } from '@/schemas/apiSchema'
import { app } from '@/scripts/app'
export { getResourceURL, splitFilePath } from '@/utils/resourceUrl'
/**
* Format time in MM:SS format
@@ -11,29 +10,3 @@ export function formatTime(seconds: number): string {
const secs = Math.floor(seconds % 60)
return `${mins}:${secs.toString().padStart(2, '0')}`
}
export function getResourceURL(
subfolder: string,
filename: string,
type: ResultItemType = 'input'
): string {
const params = [
'filename=' + encodeURIComponent(filename),
'type=' + type,
'subfolder=' + subfolder,
app.getRandParam().substring(1)
].join('&')
return `/view?${params}`
}
export function splitFilePath(path: string): [string, string] {
const folder_separator = path.lastIndexOf('/')
if (folder_separator === -1) {
return ['', path]
}
return [
path.substring(0, folder_separator),
path.substring(folder_separator + 1)
]
}