Files
PIbd-23_Sheymuhov_A.I._Inte…/dist/assets/client-HTyyrb_U.js

2 lines
1.8 KiB
JavaScript

(function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const e of document.querySelectorAll('link[rel="modulepreload"]'))n(e);new MutationObserver(e=>{for(const t of e)if(t.type==="childList")for(const c of t.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&n(c)}).observe(document,{childList:!0,subtree:!0});function s(e){const t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin==="use-credentials"?t.credentials="include":e.crossOrigin==="anonymous"?t.credentials="omit":t.credentials="same-origin",t}function n(e){if(e.ep)return;e.ep=!0;const t=s(e);fetch(e.href,t)}})();const i="http://localhost:3000/",u=async(o,r,s,n="GET",e=null)=>{try{const t=r?`?${r}`:"",c=s?`/${s}`:"",l={method:n};(n==="POST"||n==="PUT")&&e&&(l.headers={"Content-Type":"application/json;charset=utf-8"},l.body=JSON.stringify(e)),console.log(`${i}${o}${c}${t}`);const a=await fetch(`${i}${o}${c}${t}`,l);if(!a.ok)throw new Error(`Response status: ${a==null?void 0:a.status}`);const f=await a.json();return console.debug(o,f),f}catch(t){throw t instanceof SyntaxError?new Error("There was a SyntaxError",t):new Error("There was an error",t)}};async function p(o,r=""){const s=`${i}${o}?${r}`;try{const n=await fetch(s,{headers:{Accept:"application/json"}});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return await n.json()}catch(n){throw console.error(`Failed to fetch ${s}:`,n),n}}const h=(o,r)=>u(o,null,r),y=async(o,r)=>{const s=await fetch(`${i}${o}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);return await s.json()},w=(o,r,s)=>u(o,null,r,"PUT",s),$=(o,r)=>u(o,null,r,"DELETE");export{h as a,y as c,$ as d,p as g,w as u};