const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/hostPermissions-DjA5Msvp.js","assets/chunk-B3pr0VN8.js"])))=>i.map(i=>d[i]);
import{t as e}from"./preload-helper-Dd-HcVz_.js";import{r as t}from"./authSession-CrP9lMPq.js";import{r as n}from"./norm-CeclA1Tu.js";var r=()=>(n(`https://api2.bysjob.com`)||`https://api2.bysjob.com`).replace(/\/+$/g,``),i=e=>{let t=String(e||``).trim();return t?/message port closed before a response was received/i.test(t)?`扩展消息通道暂时中断，请重试`:/failed to load edge function/i.test(t)||/requested function was not found/i.test(t)||/\bNOT_FOUND\b/i.test(t)?`收藏云同步服务暂不可用，请稍后重试`:t:`收藏同步失败`},a=async()=>{let e=n((await t())?.token);if(!e)throw Error(`请先登录`);return e},o=async(e,t,r,a=2e4)=>{let o=new AbortController,s=window.setTimeout(()=>o.abort(),Math.max(1e3,Math.floor(a||2e4)));try{let a=await fetch(e,{method:`POST`,headers:t,body:JSON.stringify(r),signal:o.signal}),s=await a.text().catch(()=>``),c=null;try{c=s?JSON.parse(s):null}catch{}if(!a.ok)throw Error(i(n(c?.message||c?.error||s||`请求失败（${a.status}）`)));return c}catch(e){let t=String(e?.name||``),n=String(e?.message||e||``).trim();throw t===`AbortError`||/aborted/i.test(n)?Error(`请求超时：请稍后重试`):/failed to fetch/i.test(n)?Error(`网络请求失败：请检查网络连接后重试`):Error(i(n))}finally{window.clearTimeout(s)}},s=async(t,n)=>{let r=await a(),{ensureHostPermissionForUrl:i}=await e(async()=>{let{ensureHostPermissionForUrl:e}=await import(`./hostPermissions-DjA5Msvp.js`).then(e=>e.n);return{ensureHostPermissionForUrl:e}},__vite__mapDeps([0,1]));if(!await i(t))throw Error(`未授予访问该地址的权限`);return await o(t,{"Content-Type":`application/json`,"x-auth-token":r,Authorization:`Bearer ${r}`},n,2e4)},c=async()=>`${r()}/api/favorites/sync`,l=async(e,t=500)=>{let r=await s(await c(),{op:`pull`,since:n(e),limit:Math.max(1,Math.min(1e3,Math.floor(t||500)))});return{items:Array.isArray(r?.items)?r.items:[],cursor:n(r?.cursor)}},u=async e=>await s(await c(),{op:`upsert`,items:e}),d=async e=>await s(await c(),{op:`delete`,jobId:n(e)}),f=async e=>{let t=Array.from(new Set((e||[]).map(e=>n(e)).filter(Boolean))).slice(0,400);return t.length?await s(await c(),{op:`delete_many`,ids:t}):{ok:!0,deleted:0}};export{d as cloudFavoritesDelete,f as cloudFavoritesDeleteMany,l as cloudFavoritesPull,u as cloudFavoritesUpsert};