import{d as g,l as u}from"./index-00dd720f.js";const _=g({id:"common",state:()=>({eventSource:null,log_cache:[],sse_connected:!1,log_cache_max_len:1e3,startTime:-1,tutorial_map:{qq_official_webhook:"https://astrbot.app/deploy/platform/qqofficial/webhook.html",qq_official:"https://astrbot.app/deploy/platform/qqofficial/websockets.html",aiocqhttp:"https://astrbot.app/deploy/platform/aiocqhttp/napcat.html",wecom:"https://astrbot.app/deploy/platform/wecom.html",gewechat:"https://astrbot.app/deploy/platform/wechat/gewechat.html",lark:"https://astrbot.app/deploy/platform/lark.html",telegram:"https://astrbot.app/deploy/platform/telegram.html",dingtalk:"https://astrbot.app/deploy/platform/dingtalk.html",wechatpadpro:"https://astrbot.app/deploy/platform/wechat/wechatpadpro.html",weixin_official_account:"https://astrbot.app/deploy/platform/weixin-official-account.html"},pluginMarketData:[]}),actions:{createEventSource(){if(this.eventSource)return;const e=new AbortController,{signal:t}=e,r={"Content-Type":"multipart/form-data",Authorization:"Bearer "+localStorage.getItem("token")};fetch("/api/live-log",{method:"GET",headers:r,signal:t,cache:"no-cache"}).then(o=>{if(!o.ok)throw new Error(`SSE connection failed: ${o.status}`);console.log("SSE stream opened"),this.sse_connected=!0;const l=o.body.getReader(),n=new TextDecoder,i=({done:s,value:c})=>{if(s){console.log("SSE stream closed"),setTimeout(()=>{this.eventSource=null,this.createEventSource()},2e3);return}return n.decode(c).split(`

`).forEach(m=>{if(m.startsWith("data:")){const p=m.substring(5).trim();let d={};try{d=JSON.parse(p)}catch{console.error("Invalid JSON:",p),d={type:"log",data:p,level:"INFO",time:new Date().toISOString()}}d.type==="log"&&(this.log_cache.push(d),this.log_cache.length>this.log_cache_max_len&&this.log_cache.shift())}}),l.read().then(i)};l.read().then(i)}).catch(o=>{console.error("SSE error:",o),this.log_cache.push("SSE Connection failed, retrying in 5 seconds..."),setTimeout(()=>{this.eventSource=null,this.createEventSource()},1e3)}),this.eventSource=e},closeEventSourcet(){this.eventSource&&(this.eventSource.abort(),this.eventSource=null)},getLogCache(){return this.log_cache},getStartTime(){if(this.startTime!==-1)return this.startTime;u.get("/api/stat/start-time").then(e=>{this.startTime=e.data.data.start_time})},getTutorialLink(e){return this.tutorial_map[e]},async getPluginCollections(e=!1){return!e&&this.pluginMarketData.length>0?Promise.resolve(this.pluginMarketData):u.get("/api/plugin/market_list").then(t=>{var o,l,n,i,s,c,h;let r=[];for(let a in t.data.data)r.push({name:a,desc:t.data.data[a].desc,author:t.data.data[a].author,repo:t.data.data[a].repo,installed:!1,version:(o=t.data.data[a])!=null&&o.version?t.data.data[a].version:"未知",social_link:(l=t.data.data[a])==null?void 0:l.social_link,tags:(n=t.data.data[a])!=null&&n.tags?t.data.data[a].tags:[],logo:(i=t.data.data[a])!=null&&i.logo?t.data.data[a].logo:"",pinned:(s=t.data.data[a])!=null&&s.pinned?t.data.data[a].pinned:!1,stars:(c=t.data.data[a])!=null&&c.stars?t.data.data[a].stars:0,updated_at:(h=t.data.data[a])!=null&&h.updated_at?t.data.data[a].updated_at:""});return this.pluginMarketData=r,r}).catch(t=>(this.toast("获取插件市场数据失败: "+t,"error"),Promise.reject(t)))}}});export{_ as u};
