Remove unnecessary json parsing for presets and snippets

This commit is contained in:
Misode
2024-10-26 23:01:49 +02:00
parent e130cb59eb
commit 4d9e9fa40c
4 changed files with 12 additions and 12 deletions

View File

@@ -139,7 +139,7 @@ export async function fetchPreset(versionId: VersionId, registry: string, id: st
url = `${mcmeta(version, type)}/${type}/minecraft/${registry}/${id}.json`
}
const res = await fetch(url)
return await res.json()
return await res.text()
} catch (e) {
throw new Error(`Error occurred while fetching ${registry} preset ${id}: ${message(e)}`)
}

View File

@@ -1,5 +1,4 @@
import lz from 'lz-string'
import { safeJsonParse } from '../Utils.js'
import type { VersionId } from './Versions.js'
const API_PREFIX = 'https://snippets.misode.workers.dev'
@@ -30,7 +29,7 @@ export async function getSnippet(id: string) {
const snippet = await fetchApi(`/${id}`)
return {
...snippet,
data: safeJsonParse(lz.decompressFromBase64(snippet.data) ?? '{}') ?? {},
text: lz.decompressFromBase64(snippet.data) ?? '{}',
}
} catch (e) {
if (e instanceof Error) {