mirror of
				https://github.com/Yidadaa/ChatGPT-Next-Web.git
				synced 2025-11-04 16:57:27 +08:00 
			
		
		
		
	update
This commit is contained in:
		@@ -28,7 +28,8 @@ export function fetch(url: string, options?: RequestInit): Promise<any> {
 | 
				
			|||||||
      body = [],
 | 
					      body = [],
 | 
				
			||||||
    } = options || {};
 | 
					    } = options || {};
 | 
				
			||||||
    let unlisten: Function | undefined;
 | 
					    let unlisten: Function | undefined;
 | 
				
			||||||
    let request_id = 0;
 | 
					    let setRequestId: Function | undefined;
 | 
				
			||||||
 | 
					    const requestIdPromise = new Promise((resolve) => (setRequestId = resolve));
 | 
				
			||||||
    const ts = new TransformStream();
 | 
					    const ts = new TransformStream();
 | 
				
			||||||
    const writer = ts.writable.getWriter();
 | 
					    const writer = ts.writable.getWriter();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -47,7 +48,8 @@ export function fetch(url: string, options?: RequestInit): Promise<any> {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    // @ts-ignore 2. listen response multi times, and write to Response.body
 | 
					    // @ts-ignore 2. listen response multi times, and write to Response.body
 | 
				
			||||||
    window.__TAURI__.event
 | 
					    window.__TAURI__.event
 | 
				
			||||||
      .listen("stream-response", (e: ResponseEvent) => {
 | 
					      .listen("stream-response", (e: ResponseEvent) =>
 | 
				
			||||||
 | 
					        requestIdPromise.then((request_id) => {
 | 
				
			||||||
          const { request_id: rid, chunk, status } = e?.payload || {};
 | 
					          const { request_id: rid, chunk, status } = e?.payload || {};
 | 
				
			||||||
          if (request_id != rid) {
 | 
					          if (request_id != rid) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
@@ -60,7 +62,8 @@ export function fetch(url: string, options?: RequestInit): Promise<any> {
 | 
				
			|||||||
            // end of body
 | 
					            // end of body
 | 
				
			||||||
            close();
 | 
					            close();
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
      })
 | 
					        }),
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
      .then((u: Function) => (unlisten = u));
 | 
					      .then((u: Function) => (unlisten = u));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const headers: Record<string, string> = {
 | 
					    const headers: Record<string, string> = {
 | 
				
			||||||
@@ -83,8 +86,8 @@ export function fetch(url: string, options?: RequestInit): Promise<any> {
 | 
				
			|||||||
            : [],
 | 
					            : [],
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
      .then((res: StreamResponse) => {
 | 
					      .then((res: StreamResponse) => {
 | 
				
			||||||
        request_id = res.request_id;
 | 
					        const { request_id, status, status_text: statusText, headers } = res;
 | 
				
			||||||
        const { status, status_text: statusText, headers } = res;
 | 
					        setRequestId?.(request_id);
 | 
				
			||||||
        const response = new Response(ts.readable, {
 | 
					        const response = new Response(ts.readable, {
 | 
				
			||||||
          status,
 | 
					          status,
 | 
				
			||||||
          statusText,
 | 
					          statusText,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user