Advertisement
KoctrX

Untitled

May 1st, 2024
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fetch('/api/virtual-girlfriend', {
  2.     method: 'post',
  3.     headers: {
  4.         'Content-Type': 'application/json',
  5.         authorization: `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImlhdCI6MTcxMjIyMDIxMSwiZXhwIjoxNzE0ODEyMjExfQ.N_vtUcfC6LkfiMEGZd9xpSxFrGPN13yhCS2g1jfD0Iw`
  6.     },
  7.     body: JSON.stringify({
  8.         "ethnicity": "Asian",
  9.         "age": "20s",
  10.         "body_type": "Skinny",
  11.         "breasts_size": "Small",
  12.         "butt_size": "Skinny",
  13.         "hair_style": "Curly",
  14.         "hair_color": "Black",
  15.         "personality": "Jester",
  16.         "relationship": "School Mate",
  17.         "occupation": "Baker",
  18.         "hobbies": [
  19.             "Art",
  20.             "Diy Crafting",
  21.             "Writing"
  22.         ],
  23.         "clothing": "Skatepark",
  24.         "profile_image": null,
  25.         "name": "Tony Karch"
  26.     })
  27. }).then(async (response) => {
  28.         // response.body is a ReadableStream
  29.         const reader = response.body.getReader();
  30.         for await (const chunk of readChunks(reader)) {
  31.             const result = new TextDecoder().decode(chunk);
  32.             console.log('Result', result);
  33.         }
  34.     });
  35.  
  36. // readChunks() reads from the provided reader and yields the results into an async iterable
  37. function readChunks(reader) {
  38.     return {
  39.         async* [Symbol.asyncIterator]() {
  40.             let readResult = await reader.read();
  41.             while (!readResult.done) {
  42.                 yield readResult.value;
  43.                 readResult = await reader.read();
  44.             }
  45.         },
  46.     };
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement