UNPKG

3.01 kBJavaScriptView Raw
1const e={"Content-Type":"application/json"},n=(e,n="")=>{if("object"==typeof e&&e.errno)throw new TypeError(`${n} failed with ${e.errno}: ${e.errmsg}`);return e},t=({serverURL:e,lang:n,paths:t,type:o,signal:a})=>fetch(`${e}/article?path=${encodeURIComponent(t.join(","))}&type=${encodeURIComponent(o.join(","))}&lang=${n}`,{signal:a}).then((e=>e.json())),o=({serverURL:n,lang:t,path:o,type:a,action:r})=>fetch(`${n}/article?lang=${t}`,{method:"POST",headers:e,body:JSON.stringify({path:o,type:a,action:r})}).then((e=>e.json())),a=({serverURL:e,lang:t,path:o,page:a,pageSize:r,sortBy:s,signal:i,token:h})=>{const l={};return h&&(l.Authorization=`Bearer ${h}`),fetch(`${e}/comment?path=${encodeURIComponent(o)}&pageSize=${r}&page=${a}&lang=${t}&sortBy=${s}`,{signal:i,headers:l}).then((e=>e.json())).then((e=>n(e,"Get comment data")))},r=({serverURL:e,lang:n,token:t,comment:o})=>{const a={"Content-Type":"application/json"};return t&&(a.Authorization=`Bearer ${t}`),fetch(`${e}/comment?lang=${n}`,{method:"POST",headers:a,body:JSON.stringify(o)}).then((e=>e.json()))},s=({serverURL:e,lang:t,token:o,objectId:a})=>fetch(`${e}/comment/${a}?lang=${t}`,{method:"DELETE",headers:{Authorization:`Bearer ${o}`}}).then((e=>e.json())).then((e=>n(e,"Delete comment"))),i=({serverURL:t,lang:o,token:a,objectId:r,comment:s})=>fetch(`${t}/comment/${r}?lang=${o}`,{method:"PUT",headers:{...e,Authorization:`Bearer ${a}`},body:JSON.stringify(s)}).then((e=>e.json())).then((e=>n(e,"Update comment"))),h=({serverURL:e,lang:n,paths:t,signal:o})=>fetch(`${e}/comment?type=count&url=${encodeURIComponent(t.join(","))}&lang=${n}`,{signal:o}).then((e=>e.json())).then((e=>Array.isArray(e)?e:[e])),l=({lang:e,serverURL:n})=>{const t=(window.innerWidth-450)/2,o=(window.innerHeight-450)/2,a=window.open(`${n}/ui/login?lng=${encodeURIComponent(e)}`,"_blank",`width=450,height=450,left=${t},top=${o},scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no`);return a?.postMessage({type:"TOKEN",data:null},"*"),new Promise((e=>{const n=({data:t})=>{t&&"object"==typeof t&&"userInfo"===t.type&&t.data.token&&(a?.close(),window.removeEventListener("message",n),e(t.data))};window.addEventListener("message",n)}))},c=({serverURL:e,lang:n,paths:o,signal:a})=>t({serverURL:e,lang:n,paths:o,type:["time"],signal:a}).then((e=>Array.isArray(e)?e:[e])),g=e=>o({...e,type:"time",action:"inc"}),p=({serverURL:e,lang:n,count:t,signal:o,token:a})=>{const r={};return a&&(r.Authorization=`Bearer ${a}`),fetch(`${e}/comment?type=recent&count=${t}&lang=${n}`,{signal:o,headers:r}).then((e=>e.json()))},$=({serverURL:e,signal:t,pageSize:o,lang:a})=>fetch(`${e}/user?pageSize=${o}&lang=${a}`,{signal:t}).then((e=>e.json())).then((e=>n(e,"user list"))).then((e=>e.data));export{r as addComment,s as deleteComment,h as fetchCommentCount,t as getArticleCounter,a as getComment,c as getPageview,p as getRecentComment,$ as getUserList,l as login,o as updateArticleCounter,i as updateComment,g as updatePageview};
2//# sourceMappingURL=api.mjs.map