import{r as e}from"./rolldown-runtime-DCMCV6zW.js";import{E as t,Et as n,c as r,ft as i}from"./vendor-vue-core-D3IvUUeM.js";import{D as a}from"./vendor-other-CrvBxfcV.js";import{n as o}from"./envUtil-DPL4J8Ws.js";import{t as s}from"./types-0oh-UGWL.js";import{V as c}from"./vendor-vueuse-ChSVzIZz.js";import{t as l}from"./vendor-axios-BKU8NR6A.js";import{J as u}from"./api-3C7_IVZO.js";import{Dr as d,r as f}from"./dialogService-BC0EXJA5.js";import{T as p,t as m}from"./systemStatsStore-gvlzOl4W.js";var h=l.create({baseURL:d(),headers:{"Content-Type":`application/json`}});const useReleaseService=()=>{let e=n(!1),t=n(null);i(()=>d(),e=>{h.defaults.baseURL=e});let handleApiError=(e,t,n)=>{if(!l.isAxiosError(e))return e instanceof Error?`${t}: ${e.message}`:`${t}: Unknown error occurred`;let r=e;if(r.response){let{status:e,data:i}=r.response;if(n&&n[e])return n[e];switch(e){case 400:return`Bad request: ${i?.message||`Invalid input`}`;case 401:return`Unauthorized: Authentication required`;case 403:return`Forbidden: ${i?.message||`Access denied`}`;case 404:return`Not found: ${i?.message||`Resource not found`}`;case 500:return`Server error: ${i?.message||`Internal server error`}`;default:return`${t}: ${i?.message||r.message}`}}return`${t}: ${r.message}`},executeApiRequest=async(n,r,i)=>{e.value=!0,t.value=null;try{return(await n()).data}catch(e){return u(e)||(t.value=handleApiError(e,r,i)),null}finally{e.value=!1}},getReleases=async(e,t)=>await executeApiRequest(()=>h.get(`/releases`,{params:e,signal:t}),`Failed to get releases`,{400:`Invalid project or version parameter`});return{isLoading:e,error:t,getReleases}};var g=a();const _=r(`release`,()=>{let e=n([]),r=n(!1),i=n(null),a=useReleaseService(),l=m(),u=f(),d=t(()=>s?l?.systemStats?.system?.cloud_version??``:l?.systemStats?.system?.comfyui_version??``),h=t(()=>u.get(`Comfy.Locale`)),_=t(()=>u.get(`Comfy.Release.Version`)),v=t(()=>u.get(`Comfy.Release.Status`)),y=t(()=>u.get(`Comfy.Release.Timestamp`)),b=t(()=>u.get(`Comfy.Notification.ShowVersionUpdates`)),x=t(()=>e.value[0]??null),S=t(()=>e.value.slice(0,3)),compareVersions=(e,t)=>(0,g.valid)(e)&&(0,g.valid)(t)?(0,g.compare)(e,t):e===t?0:1,C=t(()=>!!x.value&&compareVersions(x.value.version,d.value||`0.0.0`)>0),w=t(()=>!!x.value&&compareVersions(x.value.version,d.value||`0.0.0`)===0),T=t(()=>{let e=x.value?.attention;return e===`medium`||e===`high`}),E=t(()=>!(!o()||s||!b.value||!C.value||!T.value||_.value===x.value?.version&&[`skipped`,`changelog seen`].includes(v.value))),D=t(()=>{if(!o()||s||!b.value||!C.value)return!1;let{version:e}=x.value;return _.value===e&&v.value===`changelog seen`?!1:T.value?!0:!(_.value===e&&v.value===`skipped`&&y.value&&Date.now()-y.value>=2592e5)}),O=t(()=>!(!o()&&!s||!b.value||!x.value||(0,g.valid)(d.value)&&!w.value||_.value===x.value.version&&v.value===`what's new seen`));async function handleSkipRelease(e){e!==x.value?.version||v.value===`changelog seen`||(await u.set(`Comfy.Release.Version`,e),await u.set(`Comfy.Release.Status`,`skipped`),await u.set(`Comfy.Release.Timestamp`,Date.now()))}async function handleShowChangelog(e){e===x.value?.version&&(await u.set(`Comfy.Release.Version`,e),await u.set(`Comfy.Release.Status`,`changelog seen`),await u.set(`Comfy.Release.Timestamp`,Date.now()))}async function handleWhatsNewSeen(e){e===x.value?.version&&(await u.set(`Comfy.Release.Version`,e),await u.set(`Comfy.Release.Status`,`what's new seen`),await u.set(`Comfy.Release.Timestamp`,Date.now()))}async function fetchReleases(){if(!r.value&&!(!s&&!b.value)&&!l.systemStats?.system?.argv?.includes(`--disable-api-nodes`)){r.value=!0,i.value=null;try{l.systemStats||await c(l.isInitialized);let t=await a.getReleases({project:s?`cloud`:`comfyui`,current_version:d.value,form_factor:l.getFormFactor(),locale:p(h.value)});t===null?a.error.value&&(i.value=a.error.value):e.value=t}catch(e){i.value=e instanceof Error?e.message:`Unknown error occurred`}finally{r.value=!1}}}async function initialize(){await fetchReleases()}return{releases:e,isLoading:r,error:i,recentRelease:x,recentReleases:S,shouldShowToast:E,shouldShowRedDot:D,shouldShowPopup:O,shouldShowUpdateButton:C,handleSkipRelease,handleShowChangelog,handleWhatsNewSeen,fetchReleases,initialize}});export{_ as t};
//# sourceMappingURL=releaseStore-DH0BznNd.js.map