MCPcopy Create free account
hub / github.com/esengine/esengine / AssetPathResolver

Class AssetPathResolver

packages/asset-system/src/core/AssetPathResolver.ts:34–235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32 * 资产路径解析器
33 */
34export class AssetPathResolver {
35 private config: IAssetPathConfig;
36
37 constructor(config: IAssetPathConfig = {}) {
38 this.config = {
39 baseUrl: '',
40 assetDir: 'assets',
41 platform: AssetPlatform.H5,
42 ...config
43 };
44 }
45
46 /**
47 * Update configuration
48 * 更新配置
49 */
50 updateConfig(config: Partial<IAssetPathConfig>): void {
51 this.config = { ...this.config, ...config };
52 }
53
54 /**
55 * Resolve asset path to full URL
56 * 解析资产路径为完整URL
57 */
58 resolve(path: string): string {
59 // Validate input path
60 const validation = PathValidator.validate(path);
61 if (!validation.valid) {
62 console.warn(`Invalid asset path: ${path} - ${validation.reason}`);
63 // Sanitize the path instead of throwing
64 path = PathValidator.sanitize(path);
65 if (!path) {
66 throw new Error(`Cannot resolve invalid path: ${validation.reason}`);
67 }
68 }
69
70 // Already a full URL
71 // 已经是完整URL
72 if (this.isAbsoluteUrl(path)) {
73 return path;
74 }
75
76 // Data URL
77 // 数据URL
78 if (path.startsWith('data:')) {
79 return path;
80 }
81
82 // Normalize the path
83 path = PathValidator.normalize(path);
84
85 // Apply custom transformer if provided
86 // 应用自定义转换器(如果提供)
87 if (this.config.pathTransformer) {
88 path = this.config.pathTransformer(path);
89 // Transformer output is trusted (may be absolute path or asset:// URL)
90 // 转换器输出是可信的(可能是绝对路径或 asset:// URL)
91 return path;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected