You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
2.9 KiB

import{g as e,r as t}from"./api-Dpfxb1ca.js";import{s as n}from"./index-D5exsJys.js";function r(e){if(!e||typeof e!=`object`)throw Error(`列表响应格式无效`);let t=e;if(Array.isArray(t.data)&&typeof t.current_page==`number`){let e=t.data;return{data:e,meta:{current_page:t.current_page,last_page:typeof t.last_page==`number`?t.last_page:1,per_page:typeof t.per_page==`number`?t.per_page:e.length||15,total:typeof t.total==`number`?t.total:e.length}}}let n=t.data??t,r=n.data,i=n.meta;if(Array.isArray(r)&&i&&typeof i==`object`)return{data:r,meta:i};if(Array.isArray(t.data)){let e=t.data;return{data:e,meta:{current_page:1,last_page:1,per_page:e.length,total:e.length}}}throw Error(`列表响应格式无效`)}async function i(e){let{data:t}=await n.get(`/competitions`,{params:e});return r(t)}async function a(e){let{data:t}=await n.get(`/competitions/${e}`),r=t?.data??t;if(!r||typeof r!=`object`)throw Error(`赛事详情无效`);return r}async function o(e){let{data:t}=await n.post(`/competitions`,e),r=t?.data??t;if(!r||typeof r!=`object`)throw Error(`创建响应无效`);return r}async function s(e,t){let{data:r}=await n.patch(`/competitions/${e}`,t),i=r?.data??r;if(!i||typeof i!=`object`)throw Error(`更新响应无效`);return i}async function c(e,t){let{data:r}=await n.patch(`/competitions/${e}`,t),i=r?.data??r;if(!i||typeof i!=`object`)throw Error(`更新响应无效`);return i}async function l(e){let{data:t}=await n.get(`/competitions/${e}/tracks`),r=t?.data??t;if(!Array.isArray(r))throw Error(`赛道列表无效`);return r}async function u(e,t){let{data:r}=await n.post(`/competitions/${e}/tracks`,t),i=r?.data??r;if(!i||typeof i!=`object`)throw Error(`创建赛道无效`);return i}async function d(e,t,r){let{data:i}=await n.put(`/competitions/${e}/tracks/${t}`,r),a=i?.data??i;if(!a||typeof a!=`object`)throw Error(`更新赛道无效`);return a}async function f(e,t){await n.delete(`/competitions/${e}/tracks/${t}`)}function p(e){if(!e||typeof e!=`object`)return``;let t=e,n=t.data!=null&&typeof t.data==`object`&&!Array.isArray(t.data)?t.data:t,r=n.url??n.logoUrl;return typeof r==`string`?r:``}function m(e,t){if(!e||typeof e!=`object`)return t;let n=e;if(typeof n.message==`string`&&n.message.trim())return n.message.trim();let r=n.errors;if(r&&typeof r==`object`&&!Array.isArray(r)){let e=Object.values(r)[0];if(Array.isArray(e)&&e.length)return String(e[0])}return t}async function h(n,r){let i=new FormData;i.append(`file`,r);let a=localStorage.getItem(t),o=await fetch(`${e()}/competitions/${n}/logo`,{method:`POST`,headers:{Accept:`application/json`,...a?{Authorization:`Bearer ${a}`}:{}},body:i}),s=await o.json().catch(()=>({}));if(!o.ok)throw Error(m(s,`Logo 上传失败`));let c=p(s);if(!c)throw Error(`Logo 上传响应无效`);return c}async function g(e){await n.delete(`/competitions/${e}/logo`)}export{a,c,h as d,f as i,s as l,u as n,i as o,g as r,l as s,o as t,d as u};