feat(web): back artifact viewing with blob sas
This commit is contained in:
parent
e76174d43c
commit
be3b439621
@ -1,11 +1,31 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { getArtifactReadUrl } from "@/lib/blob-client";
|
||||||
import type { ArtifactSummary } from "@/lib/types";
|
import type { ArtifactSummary } from "@/lib/types";
|
||||||
|
|
||||||
export function ArtifactPanel({ artifacts }: { artifacts: ArtifactSummary[] }) {
|
export function ArtifactPanel({ artifacts }: { artifacts: ArtifactSummary[] }) {
|
||||||
|
const [openingId, setOpeningId] = useState<string | null>(null);
|
||||||
|
|
||||||
|
async function handleOpenArtifact(artifact: ArtifactSummary) {
|
||||||
|
if (!artifact.blobPath) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
setOpeningId(artifact.id);
|
||||||
|
const url = await getArtifactReadUrl(artifact.blobPath);
|
||||||
|
window.open(url, "_blank", "noopener,noreferrer");
|
||||||
|
} finally {
|
||||||
|
setOpeningId(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="surface-card" style={{ padding: "var(--ml-space-5)", display: "grid", gap: "var(--ml-space-3)" }}>
|
<section className="surface-card" style={{ padding: "var(--ml-space-5)", display: "grid", gap: "var(--ml-space-3)" }}>
|
||||||
<div style={{ display: "flex", justifyContent: "space-between", gap: "var(--ml-space-3)", alignItems: "center" }}>
|
<div style={{ display: "flex", justifyContent: "space-between", gap: "var(--ml-space-3)", alignItems: "center" }}>
|
||||||
<div style={{ fontWeight: 700 }}>Artifacts</div>
|
<div style={{ fontWeight: 700 }}>Artifacts</div>
|
||||||
<span className="badge">upload deferred</span>
|
<span className="badge">blob-backed view</span>
|
||||||
</div>
|
</div>
|
||||||
{artifacts.map((artifact) => (
|
{artifacts.map((artifact) => (
|
||||||
<div key={artifact.id} className="surface-muted" style={{ padding: "var(--ml-space-3)", display: "flex", justifyContent: "space-between", gap: "var(--ml-space-3)", alignItems: "center" }}>
|
<div key={artifact.id} className="surface-muted" style={{ padding: "var(--ml-space-3)", display: "flex", justifyContent: "space-between", gap: "var(--ml-space-3)", alignItems: "center" }}>
|
||||||
@ -13,7 +33,21 @@ export function ArtifactPanel({ artifacts }: { artifacts: ArtifactSummary[] }) {
|
|||||||
<strong>{artifact.name}</strong>
|
<strong>{artifact.name}</strong>
|
||||||
<span style={{ color: "var(--ml-text-secondary)" }}>{artifact.type}</span>
|
<span style={{ color: "var(--ml-text-secondary)" }}>{artifact.type}</span>
|
||||||
</div>
|
</div>
|
||||||
<span style={{ color: "var(--ml-text-secondary)" }}>{artifact.status}</span>
|
<div style={{ display: "flex", gap: "var(--ml-space-3)", alignItems: "center" }}>
|
||||||
|
<span style={{ color: "var(--ml-text-secondary)" }}>{artifact.status}</span>
|
||||||
|
{artifact.blobPath ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="badge"
|
||||||
|
onClick={() => {
|
||||||
|
void handleOpenArtifact(artifact);
|
||||||
|
}}
|
||||||
|
disabled={openingId === artifact.id}
|
||||||
|
>
|
||||||
|
{openingId === artifact.id ? "Opening…" : "Open"}
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
18
web/src/lib/blob-client.ts
Normal file
18
web/src/lib/blob-client.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { platformClient } from "@/lib/platform";
|
||||||
|
|
||||||
|
type BlobSasResponse = {
|
||||||
|
sasUrl: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function getArtifactReadUrl(blobPath: string): Promise<string> {
|
||||||
|
const response = await platformClient.post<BlobSasResponse>("/blob/sas", {
|
||||||
|
container: "attachments",
|
||||||
|
blobName: blobPath,
|
||||||
|
permissions: "r",
|
||||||
|
expiresInMinutes: 15,
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.sasUrl;
|
||||||
|
}
|
||||||
@ -47,6 +47,9 @@ type NoteArtifactDoc = {
|
|||||||
artifactType: "file" | "summary" | "extraction" | "citation" | "export";
|
artifactType: "file" | "summary" | "extraction" | "citation" | "export";
|
||||||
title: string;
|
title: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
|
blobPath?: string;
|
||||||
|
contentType?: string;
|
||||||
|
sizeBytes?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
type NoteAgentActionDoc = {
|
type NoteAgentActionDoc = {
|
||||||
@ -145,6 +148,9 @@ function toArtifactSummary(artifact: NoteArtifactDoc): ArtifactSummary {
|
|||||||
name: artifact.title,
|
name: artifact.title,
|
||||||
type: artifact.artifactType,
|
type: artifact.artifactType,
|
||||||
status: artifact.description ? "ready" : "processing",
|
status: artifact.description ? "ready" : "processing",
|
||||||
|
blobPath: artifact.blobPath,
|
||||||
|
contentType: artifact.contentType,
|
||||||
|
sizeBytes: artifact.sizeBytes,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -45,6 +45,9 @@ export interface ArtifactSummary {
|
|||||||
name: string;
|
name: string;
|
||||||
type: string;
|
type: string;
|
||||||
status: "ready" | "processing" | "deferred";
|
status: "ready" | "processing" | "deferred";
|
||||||
|
blobPath?: string;
|
||||||
|
contentType?: string;
|
||||||
|
sizeBytes?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NoteSummary {
|
export interface NoteSummary {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user