gx
chenyc
2025-06-12 7b72ac13a83764a662159d4a49b7fffb90476ecb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
export function getModelUris(uri: string | undefined, defaultModelName: string) {
  const defaultManifestFilename = `${defaultModelName}-weights_manifest.json`;
 
  if (!uri) {
    return {
      modelBaseUri: '',
      manifestUri: defaultManifestFilename,
    };
  }
 
  if (uri === '/') {
    return {
      modelBaseUri: '/',
      manifestUri: `/${defaultManifestFilename}`,
    };
  }
  // eslint-disable-next-line no-nested-ternary
  const protocol = uri.startsWith('http://') ? 'http://' : uri.startsWith('https://') ? 'https://' : '';
  uri = uri.replace(protocol, '');
 
  const parts = uri.split('/').filter((s) => s);
 
  const manifestFile = uri.endsWith('.json')
    ? parts[parts.length - 1]
    : defaultManifestFilename;
 
  let modelBaseUri = protocol + (uri.endsWith('.json') ? parts.slice(0, parts.length - 1) : parts).join('/');
  modelBaseUri = uri.startsWith('/') ? `/${modelBaseUri}` : modelBaseUri;
 
  return {
    modelBaseUri,
    manifestUri: modelBaseUri === '/' ? `/${manifestFile}` : `${modelBaseUri}/${manifestFile}`,
  };
}