chore: parse ansi
This commit is contained in:
@@ -12,6 +12,10 @@ interface RequestConfig {
|
||||
const useSetChunkFetch = () => {
|
||||
const axiosToken = useRef<any>(null);
|
||||
const requestConfig = useRef<any>({});
|
||||
const completeData = useRef<any>([]);
|
||||
const chunkDataRef = useRef<any>([]);
|
||||
const conentLengthRef = useRef<any>(0);
|
||||
const receivedLengthRef = useRef<any>(0);
|
||||
|
||||
const readTextEventStreamData = async (
|
||||
reader: any,
|
||||
@@ -19,16 +23,60 @@ const useSetChunkFetch = () => {
|
||||
callback: (data: any) => void
|
||||
) => {
|
||||
const { done, value } = await reader.read();
|
||||
|
||||
console.log('chunkDataRef.current===1', {
|
||||
data: chunkDataRef.current,
|
||||
done
|
||||
});
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
|
||||
let chunk = decoder.decode(value, { stream: true });
|
||||
const chunk = decoder.decode(value, { stream: true });
|
||||
|
||||
callback(chunk);
|
||||
// console.log('chunkDataRef.current===2', chunkDataRef.current);
|
||||
|
||||
await readTextEventStreamData(reader, decoder, callback);
|
||||
};
|
||||
|
||||
const combineUint8Arrays = (arrays: Uint8Array[]) => {
|
||||
// Calculate total length
|
||||
const totalLength = arrays.reduce((acc, arr) => acc + arr.length, 0);
|
||||
|
||||
// Create a new Uint8Array to hold the combined data
|
||||
const combined = new Uint8Array(totalLength);
|
||||
|
||||
// Copy each array into the combined array
|
||||
let offset = 0;
|
||||
for (const arr of arrays) {
|
||||
combined.set(arr, offset);
|
||||
offset += arr.length;
|
||||
}
|
||||
|
||||
return combined;
|
||||
};
|
||||
|
||||
const readUint8ArrayStreamData = async (
|
||||
reader: ReadableStreamDefaultReader<Uint8Array>,
|
||||
callback: (data: Uint8Array) => void
|
||||
) => {
|
||||
const { done, value } = await reader.read();
|
||||
while (true) {
|
||||
if (done) {
|
||||
callback(completeData.current);
|
||||
break;
|
||||
}
|
||||
const tempData = new Uint8Array(
|
||||
completeData.current.length + value.length
|
||||
);
|
||||
tempData.set(completeData.current);
|
||||
tempData.set(value, completeData.current.length);
|
||||
completeData.current = tempData;
|
||||
}
|
||||
|
||||
// await readUint8ArrayStreamData(reader, callback);
|
||||
};
|
||||
|
||||
const fetchChunkRequest = async ({
|
||||
url,
|
||||
handler,
|
||||
@@ -51,15 +99,21 @@ const useSetChunkFetch = () => {
|
||||
signal: axiosToken.current.signal
|
||||
}
|
||||
);
|
||||
console.log('response============', response);
|
||||
|
||||
if (!response.ok) {
|
||||
return;
|
||||
}
|
||||
|
||||
chunkDataRef.current = '';
|
||||
conentLengthRef.current = response.headers.get('Content-Length');
|
||||
receivedLengthRef.current = 0;
|
||||
console.log('conentLengthRef.current', conentLengthRef.current, response);
|
||||
const reader = response?.body?.getReader();
|
||||
const decoder = new TextDecoder('utf-8');
|
||||
await readTextEventStreamData(reader, decoder, handler);
|
||||
} catch (error) {
|
||||
// handle error
|
||||
console.log('error============', error);
|
||||
}
|
||||
|
||||
return axiosToken.current;
|
||||
|
||||
@@ -14,6 +14,7 @@ export const overlaySollerOptions: UseOverlayScrollbarsParams = {
|
||||
x: 'hidden'
|
||||
},
|
||||
scrollbars: {
|
||||
theme: 'os-theme-light',
|
||||
autoHide: 'scroll',
|
||||
autoHideDelay: 600,
|
||||
clickScroll: 'instant'
|
||||
@@ -22,11 +23,25 @@ export const overlaySollerOptions: UseOverlayScrollbarsParams = {
|
||||
defer: true
|
||||
};
|
||||
|
||||
export default function useOverlayScroller() {
|
||||
export default function useOverlayScroller(options?: any) {
|
||||
const scrollEventElement = React.useRef<any>(null);
|
||||
const instanceRef = React.useRef<any>(null);
|
||||
const [initialize, instance] = useOverlayScrollbars({
|
||||
...overlaySollerOptions
|
||||
options: {
|
||||
update: {
|
||||
debounce: 0
|
||||
},
|
||||
overflow: {
|
||||
x: 'hidden'
|
||||
},
|
||||
scrollbars: {
|
||||
theme: options?.theme || 'os-theme-dark',
|
||||
autoHide: 'scroll',
|
||||
autoHideDelay: 600,
|
||||
clickScroll: 'instant'
|
||||
}
|
||||
},
|
||||
defer: true
|
||||
});
|
||||
instanceRef.current = instance?.();
|
||||
scrollEventElement.current =
|
||||
|
||||
Reference in New Issue
Block a user