mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 07:10:41 +00:00
Revert "Use Spyglass API to get vanilla-mcdoc symbols"
This reverts commit 63f9eed07c.
This commit is contained in:
@@ -12,6 +12,7 @@ declare var __LATEST_VERSION__: string
|
||||
export const latestVersion = __LATEST_VERSION__ ?? ''
|
||||
const mcmetaUrl = 'https://raw.githubusercontent.com/misode/mcmeta'
|
||||
const mcmetaTarballUrl = 'https://github.com/misode/mcmeta/tarball'
|
||||
const vanillaMcdocUrl = 'https://raw.githubusercontent.com/SpyglassMC/vanilla-mcdoc'
|
||||
const changesUrl = 'https://raw.githubusercontent.com/misode/technical-changes'
|
||||
const fixesUrl = 'https://raw.githubusercontent.com/misode/mcfixes'
|
||||
const versionDiffUrl = 'https://mcmeta-diff.misode.workers.dev'
|
||||
@@ -47,6 +48,19 @@ export function getVersionChecksum(versionId: VersionId) {
|
||||
return version.ref
|
||||
}
|
||||
|
||||
export interface VanillaMcdocSymbols {
|
||||
ref: string,
|
||||
mcdoc: Record<string, unknown>,
|
||||
'mcdoc/dispatcher': Record<string, Record<string, unknown>>,
|
||||
}
|
||||
export async function fetchVanillaMcdoc(): Promise<VanillaMcdocSymbols> {
|
||||
try {
|
||||
return cachedFetch<VanillaMcdocSymbols>(`${vanillaMcdocUrl}/generated/symbols.json`, { refresh: true })
|
||||
} catch (e) {
|
||||
throw new Error(`Error occured while fetching vanilla-mcdoc: ${message(e)}`)
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchDependencyMcdoc(dependency: string) {
|
||||
try {
|
||||
return cachedFetch(`/mcdoc/${dependency}.mcdoc`, { decode: res => res.text(), refresh: true })
|
||||
@@ -490,41 +504,3 @@ async function applyPatches() {
|
||||
localStorage.setItem(CACHE_PATCH, i.toFixed())
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchWithCache(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
|
||||
const cache = await caches.open(CACHE_NAME)
|
||||
const request = new Request(input, init)
|
||||
const cachedResponse = await cache.match(request)
|
||||
const cachedEtag = cachedResponse?.headers.get('ETag')
|
||||
if (cachedEtag) {
|
||||
request.headers.set('If-None-Match', cachedEtag)
|
||||
}
|
||||
try {
|
||||
const response = await fetch(request)
|
||||
if (response.status === 304 && cachedResponse) {
|
||||
console.log(`[fetchWithCache] reusing cache for ${request.url}`)
|
||||
return cachedResponse
|
||||
} else if (!response.ok) {
|
||||
let message = response.statusText
|
||||
try {
|
||||
message = (await response.json()).message
|
||||
} catch (e) {}
|
||||
throw new TypeError(`${response.status} ${message}`)
|
||||
} else {
|
||||
try {
|
||||
await cache.put(request, response.clone())
|
||||
console.log(`[fetchWithCache] updated cache for ${request.url}`)
|
||||
} catch (e) {
|
||||
console.warn('[fetchWithCache] put cache', e)
|
||||
}
|
||||
return response
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[fetchWithCache] fetch', e)
|
||||
if (cachedResponse) {
|
||||
console.log(`[fetchWithCache] falling back to cache for ${request.url}`)
|
||||
return cachedResponse
|
||||
}
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,13 +12,11 @@ import { TextDocument } from 'vscode-languageserver-textdocument'
|
||||
import type { ConfigGenerator } from '../Config.js'
|
||||
import siteConfig from '../Config.js'
|
||||
import { computeIfAbsent, genPath } from '../Utils.js'
|
||||
import type { VersionMeta } from './DataFetcher.js'
|
||||
import { fetchBlockStates, fetchRegistries, fetchVersions, fetchWithCache, getVersionChecksum } from './DataFetcher.js'
|
||||
import type { VanillaMcdocSymbols, VersionMeta } from './DataFetcher.js'
|
||||
import { fetchBlockStates, fetchRegistries, fetchVanillaMcdoc, fetchVersions, getVersionChecksum } from './DataFetcher.js'
|
||||
import { IndexedDbFileSystem } from './FileSystem.js'
|
||||
import type { VersionId } from './Versions.js'
|
||||
|
||||
const SPYGLASS_API = 'https://api.spyglassmc.com'
|
||||
|
||||
export const CACHE_URI = 'file:///cache/'
|
||||
export const ROOT_URI = 'file:///root/'
|
||||
export const DEPENDENCY_URI = `${ROOT_URI}dependency/`
|
||||
@@ -369,10 +367,10 @@ async function compressBall(files: [string, string][]): Promise<Uint8Array> {
|
||||
const initialize: core.ProjectInitializer = async (ctx) => {
|
||||
const { config, logger, meta, externals, cacheRoot } = ctx
|
||||
|
||||
const vanillaMcdocRes = await fetchWithCache(`${SPYGLASS_API}/vanilla-mcdoc/symbols`)
|
||||
const vanillaMcdoc = await fetchVanillaMcdoc()
|
||||
meta.registerSymbolRegistrar('vanilla-mcdoc', {
|
||||
checksum: vanillaMcdocRes.headers.get('ETag') ?? '',
|
||||
registrar: vanillaMcdocRegistrar(await vanillaMcdocRes.json()),
|
||||
checksum: vanillaMcdoc.ref,
|
||||
registrar: vanillaMcdocRegistrar(vanillaMcdoc),
|
||||
})
|
||||
|
||||
meta.registerDependencyProvider('@misode-mcdoc', async () => {
|
||||
@@ -481,10 +479,6 @@ function registerAttributes(meta: core.MetaRegistry, release: ReleaseVersion, ve
|
||||
|
||||
const VanillaMcdocUri = 'mcdoc://vanilla-mcdoc/symbols.json'
|
||||
|
||||
interface VanillaMcdocSymbols {
|
||||
mcdoc: Record<string, unknown>,
|
||||
'mcdoc/dispatcher': Record<string, Record<string, unknown>>,
|
||||
}
|
||||
function vanillaMcdocRegistrar(vanillaMcdoc: VanillaMcdocSymbols): core.SymbolRegistrar {
|
||||
return (symbols) => {
|
||||
const start = performance.now()
|
||||
|
||||
Reference in New Issue
Block a user