-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: image subsystem properly sets src for images
- Loading branch information
1 parent
492b835
commit b50f121
Showing
6 changed files
with
149 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { | ||
Accessor, | ||
createEffect, | ||
createSignal, | ||
For, | ||
Setter, | ||
Show, | ||
} from "solid-js"; | ||
import { FullScreenModal } from "./Atoms/FullScreenModal"; | ||
import { useStore } from "@nanostores/solid"; | ||
import { currentDataset } from "../stores/datasetStore"; | ||
|
||
export interface ImageModalProps { | ||
showImageModal: Accessor<boolean>; | ||
setShowImageModal: Setter<boolean>; | ||
imgInformation: Accessor<{ | ||
imgRangeStart: number; | ||
imgRangeEnd: number; | ||
imgRangePrefix: string; | ||
} | null>; | ||
} | ||
|
||
export const ImageModal = (props: ImageModalProps) => { | ||
const apiHost = import.meta.env.VITE_API_HOST as string; | ||
const $currentDataset = useStore(currentDataset); | ||
|
||
const [signedImageUrlsHashmap, setSignedImageUrlsHashmap] = createSignal< | ||
Record<string, string> | ||
>({}); | ||
|
||
createEffect(() => { | ||
const rangeArray = Array.from({ | ||
length: | ||
(props.imgInformation()?.imgRangeEnd ?? 0) - | ||
(props.imgInformation()?.imgRangeStart ?? 0) + | ||
1, | ||
}); | ||
|
||
rangeArray.forEach((_, i) => { | ||
const fileName = `${props.imgInformation()?.imgRangePrefix ?? ""}${ | ||
(props.imgInformation()?.imgRangeStart ?? 0) + i | ||
}`; | ||
|
||
void fetch(`${apiHost}/get_signed_url/${fileName}`, { | ||
headers: { | ||
"TR-Dataset": $currentDataset()?.dataset.id ?? "", | ||
}, | ||
credentials: "include", | ||
}).then((response) => { | ||
const location = response.headers.get("Location"); | ||
if (location) { | ||
setSignedImageUrlsHashmap((prev) => ({ | ||
...prev, | ||
[fileName]: location, | ||
})); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
return ( | ||
<Show when={props.showImageModal()}> | ||
<FullScreenModal | ||
isOpen={props.showImageModal} | ||
setIsOpen={props.setShowImageModal} | ||
> | ||
<div class="flex max-h-[75vh] max-w-[75vw] flex-col space-y-2 overflow-auto"> | ||
<For | ||
each={Array.from({ | ||
length: | ||
(props.imgInformation()?.imgRangeEnd ?? 0) - | ||
(props.imgInformation()?.imgRangeStart ?? 0) + | ||
1, | ||
})} | ||
> | ||
{(_, i) => { | ||
const fileName = `${ | ||
props.imgInformation()?.imgRangePrefix ?? "" | ||
}${ | ||
// eslint-disable-next-line solid/reactivity | ||
(props.imgInformation()?.imgRangeStart ?? 0) + i() | ||
}`; | ||
const signedUrl = signedImageUrlsHashmap()[fileName] ?? ""; | ||
|
||
return <img class="mx-auto my-auto" src={signedUrl} />; | ||
}} | ||
</For> | ||
</div> | ||
</FullScreenModal> | ||
</Show> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const res = await fetch("https://api.trieve.ai/api/chunk/search", { | ||
headers: { | ||
"content-type": "application/json", | ||
"tr-dataset": "982df67b-a95f-46f6-adfd-25ee7648c79c", | ||
Authorization: "tr-wPFc6qBAM9T6XEXDXLPFl2RhNZ8iUSZD", | ||
}, | ||
body: '{"query":"test","page":1,"filters":{"must":[]},"search_type":"hybrid","get_collisions":true}', | ||
method: "POST", | ||
}); | ||
|
||
const data = await res.json(); | ||
|
||
const score_chunks = data.score_chunks; | ||
|
||
for (let i = 0; i < score_chunks.length; i++) { | ||
const chunk_data = score_chunks[i].metadata[0]; | ||
|
||
const queued_chunk = await fetch("http://127.0.0.1:8090/api/chunk", { | ||
headers: { | ||
"content-type": "application/json", | ||
Authorization: "tr-jmTgOG67D3TlNwjmqXytxOgCT82n5Eay", | ||
"tr-dataset": "5495a77b-cd85-428e-960e-7f4c856885d4", | ||
}, | ||
body: JSON.stringify({ | ||
chunk_html: chunk_data.chunk_html, | ||
metadata: chunk_data.metadata, | ||
}), | ||
method: "POST", | ||
}); | ||
|
||
if (queued_chunk.ok) { | ||
console.log("Chunk queued successfully"); | ||
} else { | ||
console.error( | ||
"Chunk failed to queue", | ||
queued_chunk.status, | ||
await queued_chunk.text() | ||
); | ||
} | ||
} |