mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 13:05:14 +03:00
fix(app): load images and audio in the review panel (#55015)
This commit is contained in:
committed by
GitHub
Unverified
parent
ba82b370c1
commit
738f77e470
@@ -498,7 +498,7 @@ test("rereads a file each time an artifact link opens it", async ({ page }) => {
|
||||
/** What the image case's frame probe records on the window. */
|
||||
type ImageProbe = { problems: string[]; frames: number; running: boolean }
|
||||
|
||||
test("image files keep the review panel painted while loading", async ({ page }) => {
|
||||
test("image files load into the review panel and keep it painted while loading", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 960, height: 900 })
|
||||
const directory = "C:/OpenCode/ReviewImage"
|
||||
const image = "assets/preview.png"
|
||||
@@ -512,7 +512,13 @@ test("image files keep the review panel painted while loading", async ({ page })
|
||||
read.resolve()
|
||||
await release.promise
|
||||
|
||||
return { type: "binary", content: "iVBORw0KGgo=", encoding: "base64", mimeType: "image/png" }
|
||||
// A 1x1 PNG.
|
||||
return {
|
||||
type: "binary",
|
||||
content: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",
|
||||
encoding: "base64",
|
||||
mimeType: "image/png",
|
||||
}
|
||||
},
|
||||
fileList: (path) => {
|
||||
if (!path) return [fileNode(directory, "assets", "directory"), fileNode(directory, "src", "directory")]
|
||||
@@ -568,6 +574,10 @@ test("image files keep the review panel painted while loading", async ({ page })
|
||||
release.resolve()
|
||||
await response
|
||||
await expect(page.locator('[data-slot="session-review-v2-file-name"]')).toHaveText("preview.png")
|
||||
await expect(page.locator("#review-panel").getByRole("img", { name: image, exact: true })).toHaveJSProperty(
|
||||
"naturalWidth",
|
||||
1,
|
||||
)
|
||||
const loaded = await frames()
|
||||
await expect.poll(frames).toBeGreaterThan(loaded)
|
||||
expect(
|
||||
|
||||
@@ -758,9 +758,15 @@ function mockHandlers(
|
||||
Effect.gen(function* () {
|
||||
const path = decodeURIComponent(new URL(ctx.request.url, "http://localhost").pathname.slice(13))
|
||||
const value = yield* Effect.promise(() => Promise.resolve(config.fileContent?.(path)))
|
||||
const content = Predicate.isString(value) ? value : (value?.content ?? "")
|
||||
|
||||
return HttpServerResponse.uint8Array(new TextEncoder().encode(content))
|
||||
if (Predicate.isString(value)) return HttpServerResponse.uint8Array(new TextEncoder().encode(value))
|
||||
|
||||
// Like the server, stream base64 content as the bytes it encodes.
|
||||
return HttpServerResponse.uint8Array(
|
||||
value?.encoding === "base64"
|
||||
? Buffer.from(value.content, "base64")
|
||||
: new TextEncoder().encode(value?.content ?? ""),
|
||||
)
|
||||
}),
|
||||
)
|
||||
// Raw, so a hook's answer can replace the status and body.
|
||||
|
||||
@@ -44,17 +44,6 @@ function SessionReviewTab(props: {
|
||||
const review = props.review
|
||||
const state: ScrollState = { userInteracted: false }
|
||||
|
||||
const readFile = async (path: string) => {
|
||||
return props.session.server.client.file
|
||||
.read({ path, location: { directory: props.review.screen.file.root } })
|
||||
.then((data) => ({ type: "text" as const, content: new TextDecoder().decode(data) }))
|
||||
.catch((error) => {
|
||||
console.debug("[session-review] failed to read file", { path, error })
|
||||
|
||||
return undefined
|
||||
})
|
||||
}
|
||||
|
||||
const handleInteraction = () => {
|
||||
state.userInteracted = true
|
||||
|
||||
@@ -165,7 +154,7 @@ function SessionReviewTab(props: {
|
||||
disableLineNumbers={false}
|
||||
onViewFile={props.onViewFile}
|
||||
focusedFile={review.activeFile()}
|
||||
readFile={readFile}
|
||||
readFile={review.readFile}
|
||||
onLineComment={review.comments.add}
|
||||
onLineCommentUpdate={review.comments.update}
|
||||
onLineCommentDelete={review.comments.remove}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { FileDiffInfo } from "@opencode/client/promise"
|
||||
import type { SessionReviewLineComment } from "@opencode/session-ui/session-review"
|
||||
import { previewSelectedLines } from "@opencode/session-ui/pierre/selection-bridge"
|
||||
import { artifactMime } from "@opencode/util/artifact"
|
||||
import { bytesToBase64 } from "@opencode/util/base64"
|
||||
import { checksum } from "@opencode/util/encode"
|
||||
import { showToast } from "@opencode/ui/toast"
|
||||
import { createQuery, useQueryClient } from "@tanstack/solid-query"
|
||||
@@ -388,6 +390,22 @@ export function createReviewModel(input: {
|
||||
})
|
||||
}
|
||||
|
||||
// Previews read files only to show images and audio, which need the raw bytes and their MIME type.
|
||||
const readFile = (path: string) =>
|
||||
view()
|
||||
.server.client.file.read({ path, location: { directory: directory() } })
|
||||
.then((bytes) => ({
|
||||
type: "binary" as const,
|
||||
content: bytesToBase64(bytes),
|
||||
encoding: "base64" as const,
|
||||
mimeType: artifactMime(path),
|
||||
}))
|
||||
.catch((error) => {
|
||||
console.debug("[session-review] failed to read file", { path, error })
|
||||
|
||||
return undefined
|
||||
})
|
||||
|
||||
const selectionPreview = (path: string, selection: FileSelection): string | undefined => {
|
||||
const content = screen.file.get(path)?.content?.content
|
||||
|
||||
@@ -585,6 +603,7 @@ export function createReviewModel(input: {
|
||||
initializeGit,
|
||||
initializingGit: () => !!state.initializingGit[view().key],
|
||||
loadDiff,
|
||||
readFile,
|
||||
mode,
|
||||
noGit: createMemo(() => {
|
||||
const project = view().project
|
||||
|
||||
@@ -53,6 +53,7 @@ type ReviewPanelProps = {
|
||||
diffsReady: boolean
|
||||
diffVersion?: number
|
||||
loadDiff?: (path: string, version?: number) => Promise<RenderDiff | undefined>
|
||||
readFile: ReviewModel["readFile"]
|
||||
activeFile?: string
|
||||
onSelectFile: (path: string) => void
|
||||
diffStyle: SessionReviewDiffStyle
|
||||
@@ -89,6 +90,7 @@ export default function ReviewPanelContent(props: {
|
||||
diffsReady={props.review.ready()}
|
||||
diffVersion={props.review.diffVersion()}
|
||||
loadDiff={props.review.loadDiff}
|
||||
readFile={props.review.readFile}
|
||||
activeFile={props.review.activeFile()}
|
||||
onSelectFile={props.review.focusFile}
|
||||
diffStyle={props.diffStyle}
|
||||
@@ -120,16 +122,6 @@ function ReviewPanel(props: ReviewPanelProps) {
|
||||
return live.status === "active" ? live.value : undefined
|
||||
}
|
||||
|
||||
const readFile = async (path: string) =>
|
||||
props.session.server.client.file
|
||||
.read({ path, location: { directory: props.screen.file.root } })
|
||||
.then((data) => ({ type: "text" as const, content: new TextDecoder().decode(data) }))
|
||||
.catch((error) => {
|
||||
console.debug("[session-review-v2] failed to read file", { path, error })
|
||||
|
||||
return undefined
|
||||
})
|
||||
|
||||
const diffs = () => props.diffs
|
||||
|
||||
const filteredFiles = createMemo(() =>
|
||||
@@ -242,7 +234,7 @@ function ReviewPanel(props: ReviewPanelProps) {
|
||||
diff={diff()}
|
||||
diffStyle={props.diffStyle}
|
||||
expandMode={props.state.expandMode()}
|
||||
readFile={readFile}
|
||||
readFile={props.readFile}
|
||||
onLineComment={props.onLineComment}
|
||||
onLineCommentUpdate={props.onLineCommentUpdate}
|
||||
onLineCommentDelete={props.onLineCommentDelete}
|
||||
|
||||
Reference in New Issue
Block a user