Skip to content

Commit

Permalink
fetch_zipped() only console.error, not raise if !response.ok
Browse files Browse the repository at this point in the history
fix StructureScene lighting
  • Loading branch information
janosh committed Oct 16, 2023
1 parent 2df8493 commit f46cee0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/lib/api.ts
Expand Up @@ -9,15 +9,16 @@ export async function decompress(blob: ReadableStream<Uint8Array> | null) {

export async function fetch_zipped<T>(
url: string,
{ unzip = true } = {},
): Promise<T> {
{ unzip = true, fetch = window.fetch } = {},
): Promise<T | null> {
const response = await fetch(url)
if (!response.ok) {
throw new Error(
console.error(
`${response.status} ${response.statusText} for ${response.url}`,
)
return null
}
if (!unzip) return await response.blob()
if (!unzip) return (await response.blob()) as T
return JSON.parse(await decompress(response.body))
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/structure/StructureScene.svelte
Expand Up @@ -94,8 +94,8 @@
/>
</T.PerspectiveCamera>

<T.DirectionalLight position={[3, 10, 10]} intensity={0.6} />
<T.AmbientLight intensity={0.3} />
<T.DirectionalLight position={[3, 10, 10]} intensity={1} />
<T.AmbientLight intensity={0.5} />

{#if show_atoms && structure?.sites}
<InstancedMesh>
Expand Down
8 changes: 4 additions & 4 deletions src/routes/mp-[slug]/+page.ts
Expand Up @@ -3,15 +3,15 @@ import type { RobocrystallogapherDoc, SimilarityDoc, SummaryDoc } from '$types'

export const prerender = false

export const load = async ({ params }) => {
export const load = async ({ params, fetch }) => {
const file = `mp-${params.slug}.json.gz`
const summary_url = `${mp_build_bucket}/summary/${file}`
const similarity_url = `${mp_build_bucket}/similarity/${file}`
const robocrys_url = `${mp_build_bucket}/robocrys/${file}`

return {
summary: fetch_zipped<SummaryDoc>(summary_url),
similarity: fetch_zipped<SimilarityDoc>(similarity_url),
robocrys: fetch_zipped<RobocrystallogapherDoc>(robocrys_url),
summary: fetch_zipped<SummaryDoc>(summary_url, { fetch }),
similarity: fetch_zipped<SimilarityDoc>(similarity_url, { fetch }),
robocrys: fetch_zipped<RobocrystallogapherDoc>(robocrys_url, { fetch }),
}
}

0 comments on commit f46cee0

Please sign in to comment.