sending video

hi so I have a large db of mixed img and vid, and Im currently trying to send the randomly seleced media to the user, when I got an img the server sent everything fine, but when I got vid the servers tries to fetch the domain again which gave a random media (img/vid), is there any way to prevent this?
export default {
  async fetch(request, env) {
      const url = "db";
      const response = await fetch(url);
      const { contentType, result } = await gatherResponse(response);
      const data = result;

      // gatherResponse returns both content-type & response body as a string
      async function gatherResponse(response) {
        const { headers } = response;
        const contentType = headers.get("content-type") || "";
          return { contentType, result: await response.json() };
      }

      let ur2l = data[Math.floor(Math.random() * data.length)]

      const aa = await fetch(ur2l.split("|")[2])
      const resp = new Response((await aa.arrayBuffer()), {headers: { "content-type": aa.headers.get("content-type") || "no"}})
      
      resp.headers.append("X-fetchedurl", ur2l.split("|")[2])
      resp.headers.append("X-fetchedurlid", ur2l.split("|")[1])
      resp.headers.append("X-fetchedurlname", ur2l.split("|")[0])
      return resp;
  }
}
Was this page helpful?