UNPKG

@tycoonsystems/tycoon-modules

Version:
1 lines 2.82 kB
import{fetchPost}from"@tycoonsystems/tycoon-modules/utility/fetch";const loadArticle=async(e,t,s,r,a,u,c,n,i,l,o,d,h)=>{try{var y,p,g,f;if(!e.fetchBusy)if(e.setFetchBusy(!0),setTimeout(()=>{e.setFetchBusy(!1)},1e4),t)return y={domainKey:e.domainKey,hash:e._loggedIn.hash,identifier:e._loggedIn.identifier,id:t},(p=await fetchPost(e.apiUrl+"/a/getarticle",null,null,y))?p.hasOwnProperty("status")?(e.setFetchBusy(!1),"disauthenticated"==p.status?(logout(),"disauthenticated"):"failed"!=p.status&&("success"==p.status?(p?.data&&((g=p.data).contents&&JSON.parse(g.contents)&&(f=s.current.clipboard.convert(JSON.parse(g.contents)),s.current.setContents(f,"silent")),g.title&&(r.current.value=g.title),g.groups&&(a.current.value=g.groups.join(" "),c(g.groups)),g.tags&&(u.current.value=g.tags.join(" "),n(g.tags)),Object.prototype.hasOwnProperty.call(g,"approved")&&(l(g.approved),o?.current)&&(o.current.checked=g.approved),g.meta&&d(g.meta),g.images&&h(g.images),i(p.data)),p):void 0)):void 0:(e.setFetchBusy(!1),!1)}catch(t){console.log(t),e.setFetchBusy(!1)}},publishArticle=async(e,t,s,r,a,u,c,n,i,l,o,d,h,y,p,g,f,v,m)=>{try{if(!e.fetchBusy){e.setFetchBusy(!0),setTimeout(()=>{e.setFetchBusy(!1)},1e4);var B,F,_=l.current.root.innerHTML;if(_)return B={domainKey:e.domainKey,hash:e._loggedIn.hash,identifier:e._loggedIn.identifier,published:t,title:s.current.value,contents:_,groups:r,tags:a,images:m,meta:o,approved:g},(F=await fetchPost(e.apiUrl+"/a/publisharticle",null,null,B))?F.hasOwnProperty("status")?(e.setFetchBusy(!1),"disauthenticated"==F.status?(logout(),"disauthenticated"):"failed"!=F.status&&("success"==F.status?(console.log(F),F?.published&&(u(null),c(null),n?.current&&(n.current.value=""),i?.current&&(i.current.value=""),l?.current&&l.current.setContents([{insert:p}]),s?.current&&(s.current.value=""),localStorage.setItem("cached_post_admin",null),v?.current&&(v.current.checked=!0),f&&f(!0),d(!0),h(F.published),y()),F):void 0)):void 0:(e.setFetchBusy(!1),!1)}}catch(t){console.log(t),e.setFetchBusy(!1)}},deleteArticle=async(e,t,s,r,a,u,c,n,i,l,o)=>{try{var d,h;if(!e.fetchBusy)if(e.setFetchBusy(!0),setTimeout(()=>{e.setFetchBusy(!1)},1e4),t?.id)return d={domainKey:e.domainKey,hash:e._loggedIn.hash,identifier:e._loggedIn.identifier,id:t.id},(h=await fetchPost(e.apiUrl+"/a/deletearticle",null,null,d))?h.hasOwnProperty("status")?(e.setFetchBusy(!1),"disauthenticated"==h.status?(logout(),"disauthenticated"):"failed"!=h.status&&("success"==h.status?(r(null),a(null),u?.current&&(u.current.value=""),c?.current&&(c.current.value=""),n?.current&&n.current.setContents([{insert:o}]),s?.current&&(s.current.value=""),localStorage.setItem("cached_post_admin",null),i(!1),l(),h):void 0)):void 0:(e.setFetchBusy(!1),!1)}catch(t){e.setFetchBusy(!1)}};export{loadArticle,publishArticle,deleteArticle};