D34wY8wT.js 3.61 KB
import{a9 as l,aa as b}from"./BtEn9SvP.js";const a={name:"",email:"",username:"",avatar:void 0,bio:void 0},u={email:!0,desktop:!1,product_updates:!0,weekly_digest:!1,important_updates:!0};function i(e){return typeof e=="object"&&e!==null}function m(e,t){return i(e)?typeof e.message=="string"&&e.message.trim().length>0?e.message:typeof e.msg=="string"&&e.msg.trim().length>0?e.msg:typeof e.error=="string"&&e.error.trim().length>0?e.error:t:t}function v(e){return i(e)?typeof e.errorCode=="string"?e.errorCode:typeof e.code=="string"?e.code:typeof e.code=="number"?String(e.code):null:null}function f(e){return Array.isArray(e)?e:i(e)?"data"in e?e.data:"result"in e?e.result:"payload"in e?e.payload:e:null}function g(e,t){if(i(e)&&typeof e.success=="boolean")return{success:e.success,errorCode:v(e),message:m(e,t)};if(i(e)&&typeof e.code<"u"){const r=String(e.code),o=r==="0"||r==="200";return{success:o,errorCode:o?null:r,message:m(e,t)}}return{success:!0,errorCode:null,message:t}}function P(e){if(i(e)&&"data"in e){const t=g(e.data,"请求失败,请稍后重试。");if(!t.success)return t}return{success:!1,errorCode:"REQUEST_FAILED",message:"请求失败,请稍后重试。"}}function _(e){const t=f(e);return i(t)?{name:typeof t.name=="string"?t.name:a.name,email:typeof t.email=="string"?t.email:a.email,username:typeof t.username=="string"?t.username:a.username,avatar:typeof t.avatar=="string"?t.avatar:void 0,bio:typeof t.bio=="string"?t.bio:void 0}:{...a}}function A(e){const t=f(e);return i(t)?{email:typeof t.email=="boolean"?t.email:u.email,desktop:typeof t.desktop=="boolean"?t.desktop:u.desktop,product_updates:typeof t.product_updates=="boolean"?t.product_updates:u.product_updates,weekly_digest:typeof t.weekly_digest=="boolean"?t.weekly_digest:u.weekly_digest,important_updates:typeof t.important_updates=="boolean"?t.important_updates:u.important_updates}:{...u}}function E(e){return e==="member"||e==="admin"||e==="customer"?e:e==="owner"?"admin":"member"}function h(e){const t=f(e);return Array.isArray(t)?t.filter(i).map(r=>{const o=i(r.avatar)?r.avatar:{};return{name:typeof r.name=="string"?r.name:"",email:typeof r.email=="string"?r.email:void 0,username:typeof r.username=="string"?r.username:"",role:E(r.role),bio:typeof r.bio=="string"?r.bio:void 0,avatar:{src:typeof o.src=="string"?o.src:void 0,alt:typeof o.alt=="string"?o.alt:void 0}}}).filter(r=>r.name.length>0&&r.username.length>0):[]}const T=()=>{const e=b();async function t(n,s,p,d="操作成功。"){try{const c=await e.request(`/api/settings${n}`,{method:s,body:p,remotePath:`/settings${n}`});return g(c,d)}catch(c){return P(c)}}return{getProfile:()=>e.useApiFetch("/api/settings/profile",{remotePath:"/settings/profile",transform:_,default:()=>({...a})}),updateProfile:async n=>{const s=await t("/profile","PUT",n,"个人资料已保存。");return s.success?{...s,profile:n}:s},getNotifications:()=>e.useApiFetch("/api/settings/notifications",{remotePath:"/settings/notifications",transform:A,default:()=>({...u})}),updateNotifications:n=>t("/notifications","PUT",n,"通知设置已保存。"),updatePassword:n=>t("/security/password","POST",n,"密码已更新。"),deleteAccount:()=>t("/security/account","DELETE",void 0,"账号已删除。"),getMembers:()=>e.useApiFetch("/api/settings/members",{remotePath:"/settings/members",transform:h,default:()=>[]}),inviteMember:n=>t("/members","POST",n,"成员邀请已发送。"),updateMemberProfile:(n,s)=>t(`/members/${n}/profile`,"PUT",s,"成员资料已更新。"),updateMemberRole:(n,s)=>t(`/members/${n}`,"PATCH",{role:s},"成员角色已更新。"),removeMember:n=>t(`/members/${n}`,"DELETE",void 0,"成员已移除。")}},L=l(T);export{L as u};