2024-09-23 14:35:38 -04:00
|
|
|
import { KCL_SAMPLES_MANIFEST_URLS } from './constants'
|
|
|
|
import { isDesktop } from './isDesktop'
|
|
|
|
|
|
|
|
export type KclSamplesManifestItem = {
|
|
|
|
file: string
|
2025-01-15 18:30:20 -05:00
|
|
|
pathFromProjectDirectoryToFirstFile: string
|
|
|
|
multipleFiles: boolean
|
2024-09-23 14:35:38 -04:00
|
|
|
title: string
|
|
|
|
description: string
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getKclSamplesManifest() {
|
|
|
|
let response = await fetch(KCL_SAMPLES_MANIFEST_URLS.remote)
|
|
|
|
if (!response.ok) {
|
|
|
|
console.warn(
|
|
|
|
'Failed to fetch latest remote KCL samples manifest, falling back to local:',
|
|
|
|
response.statusText
|
|
|
|
)
|
|
|
|
response = await fetch(
|
|
|
|
(isDesktop() ? '.' : '') + KCL_SAMPLES_MANIFEST_URLS.localFallback
|
|
|
|
)
|
|
|
|
if (!response.ok) {
|
|
|
|
console.error(
|
|
|
|
'Failed to fetch fallback KCL samples manifest:',
|
|
|
|
response.statusText
|
|
|
|
)
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return response.json().then((manifest) => {
|
|
|
|
return manifest as KclSamplesManifestItem[]
|
|
|
|
})
|
|
|
|
}
|