mirror of
https://github.com/coder/coder.git
synced 2026-10-24 01:26:25 +08:00
feature: Load workspace build logs from streaming (#1997)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import axios, { AxiosRequestHeaders } from "axios"
|
||||
import ndjsonStream from "can-ndjson-stream"
|
||||
import * as Types from "./types"
|
||||
import { WorkspaceBuildTransition } from "./types"
|
||||
import * as TypesGen from "./typesGenerated"
|
||||
@@ -271,6 +272,20 @@ export const getWorkspaceBuildLogs = async (buildname: string): Promise<TypesGen
|
||||
return response.data
|
||||
}
|
||||
|
||||
export const streamWorkspaceBuildLogs = async (
|
||||
buildname: string,
|
||||
): Promise<ReadableStreamDefaultReader<TypesGen.ProvisionerJobLog>> => {
|
||||
// Axios does not support HTTP stream in the browser
|
||||
// https://github.com/axios/axios/issues/1474
|
||||
// So we are going to use window.fetch and return a "stream" reader
|
||||
const reader = await window
|
||||
.fetch(`/api/v2/workspacebuilds/${buildname}/logs?follow=true`)
|
||||
.then((res) => ndjsonStream<TypesGen.ProvisionerJobLog>(res.body))
|
||||
.then((stream) => stream.getReader())
|
||||
|
||||
return reader
|
||||
}
|
||||
|
||||
export const putWorkspaceExtension = async (
|
||||
workspaceId: string,
|
||||
extendWorkspaceRequest: TypesGen.PutExtendWorkspaceRequest,
|
||||
|
||||
Reference in New Issue
Block a user