동결된 파일 전송
사용자가 저장된 버전에서 생성된 파일을 다운로드하려고 합니다. Blob store는
공개 URL이 아닙니다. snapshots.readArtifact는 하나의 체크포인트에서 복사된
바이트를 읽습니다. 그런 다음 경로가 HTTP 응답을 반환합니다.
이 메서드는 체크포인트가 제공된 스레드에 속하는지 확인합니다. 그래도 경로에서
먼저 해당 스레드를 인증해야 합니다. 메서드는 메타데이터와 Uint8Array 바이트를
반환합니다. HTTP 응답을 생성하지는 않습니다.
이 경로는 서버에 유지합니다. 세션이 스레드에 액세스할 수 없으면 404를
반환합니다. 그런 다음 snapshots.readArtifact를 호출합니다.
import { requireSession } from './auth'
import { snapshots } from './sandbox-server'
export async function GET(request: Request) {
const session = await requireSession(request)
const url = new URL(request.url)
const threadId = url.searchParams.get('threadId')
const checkpointId = url.searchParams.get('checkpointId')
const artifactId = url.searchParams.get('artifactId')
if (!threadId || !checkpointId || !artifactId) {
return new Response('Not found', { status: 404 })
}
if (!(await session.canAccessThread(threadId))) {
return new Response('Not found', { status: 404 })
}
const { artifact, bytes } = await snapshots.readArtifact({
threadId,
checkpointId,
artifactId,
})
return new Response(bytes.slice(), {
headers: {
'content-type': artifact.mimeType,
'content-length': String(artifact.size),
},
})
}
클라이언트는 인증된 경로를 아티팩트 URL로 사용합니다. 브라우저에서 Blob store를
읽거나 snapshots.readArtifact를 호출해서는 안 됩니다.
export function snapshotArtifactUrl(
threadId: string,
checkpointId: string,
artifactId: string,
) {
const query = new URLSearchParams({ threadId, checkpointId, artifactId })
return `/api/snapshots/artifact?${query}`
}
이름을 지정한 저장은 스레드 아티팩트를 체크포인트에 복사합니다. 자동 복원은 복사된 바이트를 변경하지 않습니다. 이름이 지정된 버전 저장과 스냅샷에 저장되는 항목을 참조하세요.