import{Ct as e,E as t,Tt as n}from"./vue-vendor-DMUmTARL.js";import{Ct as r,I as i,ct as a,lt as o,y as s}from"./index-y6crcKNt.js";import{n as c}from"./file-data-Cd5HBt8u.js";import{t as l}from"./useFileLoading-DCCb1KUw.js";import{t as u}from"./useFilePwd-DcTv9OSJ.js";import{c as d,o as f,s as p,u as m}from"./share-DyiLPZ6d.js";var h,{routerRef:g,routeRef:_}=a(),v=(e,t=``)=>Array.isArray(e)?e.length>0?String(e[0]||t):t:e==null?t:String(e),y=e=>v(e,`/`)||`/`,b=e=>e.response?.data||{};function x(){if(h)return h;let a=t(()=>v(_.value?.params?.shareKey,``)),x=n(null),S=n(!0),C=n(!1),w=n(``),T=n(`/`),E=n(void 0),D=n(!1),O=n(``),k=e({orderBy:``,orderDirection:``}),A=c(),{getSharePathPwd:j,popPassword:M,putSharePathPwd:N}=u(),P=o(),{loading:F,firstLoading:I}=l(),L=e=>e?.storageKey||e?.shareLinkInfo?.storageKey||``,R=e=>{let t=L(e);return t?(P.updateShareRuntime({shareKey:String(a.value||``),storageKey:t}),console.info(`[share] 分享运行态 storageKey 已固化`,{shareKey:a.value,storageKey:t}),!0):(console.warn(`[share] 分享信息缺少 storageKey，清理分享运行态`,{shareKey:a.value}),P.clearShareRuntime(),!1)},z=()=>v(x.value?.sharePath||x.value?.shareLinkInfo?.sharePath,`/`),B=(e=`manual-clear`)=>{(P.shareRuntime.shareKey||P.shareRuntime.storageKey)&&console.info(`[share] 清理分享运行态 storageKey`,{reason:e,shareKey:P.shareRuntime.shareKey}),P.clearShareRuntime()},V=(e={})=>{let t=g.value,n=_.value;if(!t||!n)return;let r=`/share/${encodeURIComponent(a.value)}`,i={...n.query||{},...e};t.push({path:r,query:i})},H=e=>{let t=(e||`/`).split(`/`).filter(Boolean);t.pop();let n=`/`+t.join(`/`);return n===`//`?`/`:n||`/`},U=e=>{let t=E.value&&E.value!==e?E.value:H(e||`/`);y(_.value?.query?.path)!==t&&V({path:t})},W=async e=>!!(await m({shareKey:a.value,password:e})).data,G=(e,t)=>j(a.value,e,z(),t),K=async(e=`/`,t,n)=>{let o=s();F.value=!0;try{let r=e||`/`,o=z(),s=t||j(a.value,r,o,!0),c=await p({shareKey:a.value,path:r,password:w.value,folderPassword:s,orderBy:k.orderBy||P.globalConfig.defaultSortField||`name`,orderDirection:k.orderDirection||P.globalConfig.defaultSortOrder||`asc`});if(s){let e=c.data.passwordPattern||i(`/`,o,r,`/`);N(a.value,e,s,n)}let l=(c.data.fileItemList||[]).map(e=>{if(e.type===`FILE`){let t=e.path?e.path.endsWith(`/`)?e.path+e.name:e.path+`/`+e.name:e.name;return{...e,url:f(a.value,t,w.value)}}return e}),u=c.data.currentPath||e||`/`;if(T.value=u,E.value=u,u!==`/`){let e=c.data.parentPath||H(u);l=[{name:e===`/`?`根目录`:e.split(`/`).filter(Boolean).pop()||`根目录`,path:e,type:`BACK`},...l]}A.updateFileList(l),P.updateFolderConfig({...P.folderConfig,permission:c.data.permission||{}}),F.value=!1,I.value=!0,c.data.shareLinkInfo&&(x.value=c.data.shareLinkInfo,R(c.data.shareLinkInfo))}catch(t){F.value=!1;let n=b(t);if(n.code===r.responseCode.INVALID_PASSWORD||n.code===r.responseCode.REQUIRED_PASSWORD){let t=n.code===r.responseCode.INVALID_PASSWORD;M({title:t?`密码错误`:`提示`,message:t?`文件夹密码错误，请重新输入：`:`此文件夹已加密，请输入密码：`,defaultValue:j(a.value,e,z(),!0),initialInputErrorMessage:t?`密码错误，请重新输入`:``}).then(async({value:t,checkbox:n})=>{await K(e,t,!!n)}).catch(()=>{U(e)})}else console.error(`加载分享文件失败:`,t),o.error(n.msg||`加载文件列表失败`)}};return h={shareInitializing:S,shareVerified:C,sharePassword:w,shareInvalid:D,shareErrorMsg:O,initShare:async()=>{S.value=!0,x.value=null,C.value=!1,w.value=``,D.value=!1,O.value=``,T.value=`/`,E.value=void 0,B(`init-start`);try{try{let e=await d(a.value);x.value=e.data,R(e.data)}catch(e){D.value=!0,O.value=b(e).msg||`分享链接不存在或已失效`,B(`init-failed`);return}let e=v(_.value?.query?.pwd,``);e&&(w.value=e);let t=y(_.value?.query?.path);(!x.value?.needPassword||e)&&(e?await W(e)&&(C.value=!0,await K(t)):(C.value=!0,await K(t)))}finally{S.value=!1}},verifySharePassword:W,getShareFolderPassword:G,loadShareFiles:K,sortShareChangeMethod:({prop:e,order:t})=>{k.orderBy=e||``,k.orderDirection=t===`descending`?`desc`:`asc`,K(y(_.value?.query?.path))},clearShareRuntime:B},h}export{x as t};