1 line
1.5 KiB
JavaScript
1 line
1.5 KiB
JavaScript
import{r as e}from"./client-vZFx54yb.js";import{r as t,t as n}from"./index-Ci0r-yTA.js";function r(){let e=n();return i(e.refreshTokenAction,e.getToken)}function i(n,r){async function i(i,a){return t(async()=>{let t=new Headers(a.headers),n=r();n&&t.set(`Authorization`,`Bearer ${n}`);let o=await fetch(`${e()}/${i}`,{...a,headers:t});if(o.status===401)throw Error(`unauthorized`);return o},n,r)}async function s(e,t){let n=await i(e,{method:`GET`});if(!n.ok)throw Error(await o(n));return{blob:await n.blob(),filename:a(n.headers.get(`Content-Disposition`))||t}}function c(e){return s(`api/scenarios/${e}/archive`,`scenario-${e}.zip`)}function l(e){return s(`api/games/${e}/teams/qr.pdf`,`game-${e}.pdf`)}async function u(e){let t=await i(`api/scenarios/archive`,{method:`POST`,headers:{"Content-Type":e.type||`application/zip`},body:e}),n=await t.json().catch(()=>null);if(!t.ok)throw Error(n?.message||`Ошибка сервера (${t.status})`);return{ID:typeof n?.ID==`number`?n.ID:null}}return{downloadScenarioArchive:c,downloadTeamQR:l,uploadScenarioArchive:u}}function a(e){if(!e)return``;let t=e.match(/filename\*=UTF-8''([^;]+)/i);if(t)try{return decodeURIComponent(t[1].trim()).replace(/[\\/:*?"<>|]/g,`_`)}catch{}let n=e.match(/filename="?([^";]+)"?/i);return(n?n[1]:``).replace(/[\\/:*?"<>|]/g,`_`)}async function o(e){let t=await e.json().catch(()=>null);return t&&typeof t.message==`string`&&t.message!==``?t.message:`Ошибка сервера (${e.status})`}export{r as t}; |