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
3.9 KiB

import{c as e,s as t}from"./index-D5exsJys.js";import{r as n,t as r}from"./downloadFeedback-HV11t-9m.js";function i(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},schema_list_fields:Array.isArray(t.schema_list_fields)?t.schema_list_fields:void 0,schema_filter_fields:Array.isArray(t.schema_filter_fields)?t.schema_filter_fields:void 0}}throw Error(`列表响应格式无效`)}async function a(e,n){let{data:r}=await t.get(`/competitions/${e}/applications`,{params:n});return i(r)}async function o(e,n){let{data:r}=await t.get(`/competitions/${e}/applications/${n}`);if(!r||typeof r!=`object`)throw Error(`报名详情无效`);return r}async function s(e,n,r){let{data:i}=await t.patch(`/competitions/${e}/applications/${n}/review-eligible`,{review_eligible:r});return i}async function c(n,r){try{let{data:e}=await t.post(`/competitions/${n}/applications/${r}/impersonate`);if(!e||typeof e!=`object`)throw Error(`代登响应无效`);let i=e;if(typeof i.token!=`string`||!i.token.trim())throw Error(`代登 Token 无效`);if(typeof i.competition_slug!=`string`||!i.competition_slug.trim())throw Error(`赛事标识无效`);return{token:i.token,competition_slug:i.competition_slug,expires_in:typeof i.expires_in==`number`?i.expires_in:1800,participant:i.participant&&typeof i.participant==`object`?i.participant:void 0}}catch(t){if(e.isAxiosError(t)){let e=t.response?.data;if(e&&typeof e==`object`){let t=e.message;if(typeof t==`string`&&t.trim())throw Error(t.trim())}}throw t instanceof Error?t:Error(`进入选手端失败`)}}async function l(e,i,a,o,s){let c=o?.trim()||`附件`,l=r(c,s?.size);if(l)try{let r=await t.get(`/competitions/${e}/applications/${i}/files/${a}/download`,{responseType:`blob`,timeout:0});l.setText(`正在保存「${c}」…`),u(r.data,c),n()}catch(e){throw await f(e,`下载附件失败`)}finally{l.close()}}function u(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}function d(e,t){if(!e)return t;let n=/filename\*=UTF-8''([^;]+)/i.exec(e);if(n?.[1])return decodeURIComponent(n[1]);let r=/filename="?([^";]+)"?/i.exec(e);return r?.[1]?r[1]:t}async function f(t,n){if(e.isAxiosError(t)){let e=t.response?.data;if(e instanceof Blob){let t=await e.text();try{let e=JSON.parse(t);return Error(e.errors?.export?.[0]||e.errors?.application_ids?.[0]||e.errors?.part?.[0]||e.errors?.file?.[0]||e.message||n)}catch{}}if(e&&typeof e==`object`){let t=e;return Error(t.errors?.export?.[0]||t.errors?.application_ids?.[0]||t.errors?.part?.[0]||t.errors?.file?.[0]||t.message||n)}}return t instanceof Error?t:Error(n)}async function p(e){return f(e,`导出失败`)}function m(e){return new Promise(t=>{window.setTimeout(t,e)})}function h(e){let{mode:t,application_ids:n,part:r,...i}=e,a={mode:t,...i};return n?.length&&(a.application_ids=n),r!=null&&(a.part=r),a}async function g(e,n){try{let{data:r}=await t.get(`/competitions/${e}/applications/export/meta`,{params:h(n)});if(!r||typeof r!=`object`)throw Error(`导出信息无效`);return r}catch(e){throw await p(e)}}async function _(e,n,r){let i;try{i=await t.get(`/competitions/${e}/applications/export`,{params:h({...n,part:r}),responseType:`blob`,timeout:0})}catch(e){throw await p(e)}let a=n.mode===`xlsx`?`报名信息.xlsx`:`报名信息导出_第${r}部分.zip`,o=d(i.headers[`content-disposition`],a);u(i.data,o)}async function v(e,t,n){let r=await g(e,t);if(t.mode===`xlsx`)return n?.(1,1),await _(e,t,1),r;for(let i=1;i<=r.part_count;i+=1)n?.(i,r.part_count),await _(e,t,i),i<r.part_count&&await m(500);return r}export{c as a,g as i,v as n,a as o,o as r,s,l as t};