| @@ -61,14 +61,43 @@ export async function serverFetchBlob<T>(...args: FetchParams) { | |||||
| const response = await serverFetch(...args); | const response = await serverFetch(...args); | ||||
| if (response.ok) { | if (response.ok) { | ||||
| const body = response.body | |||||
| // console.log(body) | |||||
| // console.log(body?.tee()[0].getReader()) | |||||
| const reader = body?.getReader() | |||||
| let finalUInt8Array = new Uint8Array() | |||||
| let done = false | |||||
| // Read some more, and call this function again | |||||
| while (!done) { | |||||
| // Result objects contain two properties: | |||||
| // done - true if the stream has already given you all its data. | |||||
| // value - some data. Always undefined when done is true. | |||||
| const read = await reader?.read() | |||||
| if (read?.done) { | |||||
| done = true | |||||
| } else { | |||||
| // value for fetch streams is a Uint8Array | |||||
| finalUInt8Array = new Uint8Array(read?.value.length!!) | |||||
| finalUInt8Array.set(read?.value!!) | |||||
| } | |||||
| } | |||||
| // const bodyRead = await reader?.read() | |||||
| // const bodyValue = bodyRead?.value | |||||
| // const blob = await response.blob() | // const blob = await response.blob() | ||||
| // const blobText = await blob.text(); | // const blobText = await blob.text(); | ||||
| // const blobType = await blob.type; | // const blobType = await blob.type; | ||||
| const readBody = await response.body?.getReader().read() | |||||
| const bodyValue = readBody!!.value!! | |||||
| console.log(bodyValue) | |||||
| return {filename: response.headers.get("filename"), blobValue: bodyValue} as T; | |||||
| // console.log(bodyReader) | |||||
| // console.log(finalUInt8Array) | |||||
| // console.log(bodyValue) | |||||
| return { filename: response.headers.get("filename"), blobValue: finalUInt8Array } as T; | |||||
| } else { | } else { | ||||
| switch (response.status) { | switch (response.status) { | ||||
| case 401: | case 401: | ||||