const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BTWPkaRa.js","assets/preload-helper-DxX6f4wy.js","assets/Fade-Bj1YUcWe.js","assets/notistack.esm-Bl-G2Rx2.js","assets/Box-BoFhqo9n.js","assets/useThemeProps-Cb3a7a2t.js","assets/getThemeProps-Ct9I61Jz.js","assets/ButtonBase-dVPwHUcG.js","assets/useMediaQuery-D3QrrE_7.js","assets/Menu-DT9JOTRT.js","assets/InputBase-Twl1xf9g.js","assets/useFormControl-DzT-9k0o.js","assets/useSlot-dcyUConq.js","assets/Button-uK26k-ET.js","assets/CircularProgress-zVZJTwOj.js","assets/Stack-sZ5R3ZLo.js","assets/useControlled-CnpoXLSq.js","assets/IconButton-R7hSIaQ0.js","assets/Avatar-DACPN1Gd.js","assets/DialogContent-1cFv81I0.js","assets/DialogTitle-C0Sfw4o6.js","assets/DialogContentText-C5CkgX0W.js","assets/MenuItem-CfYCN_Ah.js","assets/renderers-B7haMoN0.js","assets/Article-DU6u_Kpl.js","assets/LocalOffer-Dwgcpx6D.js","assets/Refresh-DwfNXqjw.js","assets/chunk-KS7C4IRE-C-Go0Sd1.js","assets/react-CRXH2-jv.js","assets/middleware-Pd0e8Igk.js","assets/siteStore-BLhBstND.js","assets/themeConfigStore-BeYPl93w.js","assets/uiStore-CMCILUt0.js","assets/Loading-BIwVunRy.js"])))=>i.map(i=>d[i]);
import{t as e}from"./preload-helper-DxX6f4wy.js";function t(){if(typeof window>`u`)return``;try{let e=localStorage.getItem(`auth-state`);return e&&JSON.parse(e)?.state?.token||``}catch{return``}}var n=new Map,r={"/api/v1/site":10800*1e3,"/api/v1/tags":3600*1e3,"/api/v1/posts":1800*1e3,"/api/v1/user/settings":1800*1e3,"/api/v1/settings/interaction":0,"/api/v1/admin/posts":600*1e3,"/api/v1/admin/tags":600*1e3,"/api/v1/admin/media":300*1e3,"/api/v1/admin/dashboard":300*1e3},i=300*1e3;function a(e,t){return`${e}:${t}`}function o(e){let t=e.split(`?`)[0];if(t.includes(`/comments`)||t.includes(`/likes`))return 0;for(let e of Object.keys(r))if(t===e||t.startsWith(`${e}/`))return r[e];return i}function s(e,t){let r=n.get(e);return!r||r.promise||Date.now()-r.ts>t?null:r.data}function c(e){return e.split(`?`)[0]}function l(e){let t=c(e),r=`/`+t.split(`/`).filter(Boolean).slice(0,4).join(`/`),i=[r];if(r.startsWith(`/api/v1/admin/posts`))i.push(`/api/v1/posts`);else if(r.startsWith(`/api/v1/admin/tags`))i.push(`/api/v1/tags`);else if(t===`/api/v1/admin/settings/interaction`)i.push(`/api/v1/settings/interaction`);else if(t.startsWith(`/api/v1/admin/settings/`)){let e=t.replace(`/api/v1/admin/settings/`,``);i.push(`/api/v1/settings/${e}`)}else r.startsWith(`/api/v1/admin/friends`)?i.push(`/api/v1/friends`):r.startsWith(`/api/v1/admin/media`)?i.push(`/api/v1/media`):r.startsWith(`/api/v1/admin/themes`)&&i.push(`/api/v1/site`);for(let e of n.keys())for(let t of i)if(e.includes(t)){n.delete(e);break}}async function u(){if(typeof window>`u`)return!1;try{let t=localStorage.getItem(`auth-state`);if(!t)return!1;let n=JSON.parse(t)?.state?.refreshToken;if(!n)return!1;let r=await(await fetch(`/api/v1/auth/refresh`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({refreshToken:n})})).json();if(r.code!==0||!r.data){let{useAuthStore:t}=await e(async()=>{let{useAuthStore:e}=await import(`./index-BTWPkaRa.js`).then(e=>e.i);return{useAuthStore:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33]));return t.getState().logout(),!1}let{accessToken:i,refreshToken:a,user:o}=r.data,s={state:{isAuthenticated:!0,user:o,token:i,refreshToken:a},version:0};localStorage.setItem(`auth-state`,JSON.stringify(s)),localStorage.setItem(`auth-state-sync`,JSON.stringify({isAuthenticated:!0,user:o,token:i,refreshToken:a}));let{useAuthStore:c}=await e(async()=>{let{useAuthStore:e}=await import(`./index-BTWPkaRa.js`).then(e=>e.i);return{useAuthStore:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33]));return c.getState().setAuth(i,a,o),!0}catch{return!1}}async function d(e,n){let r=t(),i={"Content-Type":`application/json`,...r?{Authorization:`Bearer ${r}`}:{}};if(n.headers){let e=n.headers;Object.assign(i,e)}try{let t=await fetch(`${e}`,{...n,headers:i}),r;try{r=await t.json()}catch{r={code:t.status||500,data:null,msg:`请求失败，HTTP ${t.status}`}}return!t.ok&&r.code===0&&(r.code=t.status),r}catch(e){return{code:500,data:null,msg:e instanceof Error?e.message:`网络请求异常`}}}function f(e){let t=s(a(`GET`,e),o(e));return t&&t.code===0?{data:t.data,hit:!0}:{data:null,hit:!1}}async function p(e,t={}){let r=t.method||`GET`,i=t._retry===!0,c=a(r,e),f=o(e);if(r!==`GET`){let n=await d(e,t);return n.code===401&&!i&&await u()?p(e,{...t,_retry:!0}):(n.code===0&&l(e),n)}let m=s(c,f);if(m)return m;let h=n.get(c);if(h?.promise)return h.promise;let g=d(e,t);n.set(c,{data:{code:0,data:null,msg:``},ts:Date.now(),promise:g});let _=await g;return _.code===401&&!i&&(n.delete(c),await u())?p(e,{...t,_retry:!0}):(_.code===0?n.set(c,{data:_,ts:Date.now()}):n.delete(c),_)}async function m(e){return p(e,{method:`GET`})}async function h(e,t,n={}){return p(e,{...n,method:`POST`,body:JSON.stringify(t)})}async function g(e,t){return p(e,{method:`PATCH`,body:JSON.stringify(t)})}async function _(e){return p(e,{method:`DELETE`})}export{f as a,h as i,m as n,g as r,_ as t};