Files
sm-bm-plugin/public/assets/log-Xlt5jeld.js

2 lines
3.9 KiB
JavaScript

const O="urn:x-cast:com.jakubzych.bm.cast";const T=/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/;const _=/^[A-Za-z0-9_-]{8,64}$/;const m=new Set(["waiting","loading","ready","error"]),M=new Set(["connecting","connected","disconnected","off"]),b=new Set(["ticket","token","channel_token","authorization"]);function E(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function y(t){if(typeof t=="string"){if(t.length>6e4)return null;try{t=JSON.parse(t)}catch{return null}}return E(t)?t:null}function A(t){return typeof t=="number"&&Number.isInteger(t)&&t>=0&&t<=9999}function w(t){return typeof t=="string"&&t.length<=512&&T.test(t)}function L(t){const e=y(t);if(!e)return null;switch(e.type){case"hello":return!w(e.ticket)||typeof e.tab!="string"||!_.test(e.tab)?null:{type:"hello",ticket:e.ticket,tab:e.tab};case"where":return{type:"where"};case"log":return{type:"log"};default:return null}}function R(t){const e=y(t);if(!e)return null;switch(e.type){case"status":return typeof e.phase!="string"||!m.has(e.phase)||typeof e.ws!="string"||!M.has(e.ws)||!A(e.number)||typeof e.special!="boolean"||typeof e.title!="string"||e.title.length>1e3?null:{type:"status",phase:e.phase,ws:e.ws,number:e.number,special:e.special,title:e.title};case"position":return!A(e.number)||typeof e.special!="boolean"?null:{type:"position",number:e.number,special:e.special};case"need-ticket":return{type:"need-ticket"};case"log":{const{part:n,of:o,data:r}=e;return typeof n!="number"||typeof o!="number"||!Number.isInteger(n)||!Number.isInteger(o)||n<0||n>=o||o>1e3||typeof r!="string"?null:{type:"log",part:n,of:o,data:r}}default:return null}}const C=new TextEncoder;function k(t){let e;try{e=JSON.stringify(t)}catch{return!1}return typeof e!="string"?!1:e.length*3<=6e4?!0:e.length>6e4?!1:C.encode(e).length<=6e4}function I(t,e=4e4){const n=Math.max(1,Math.floor(e)),o=[];let r=0;for(;r<t.length||o.length===0;){let i=Math.min(n,t.length-r),s=t.slice(r,r+i);for(;i>1&&!k({type:"log",part:999,of:1e3,data:s});)i=Math.max(1,Math.floor(i*.75)),s=t.slice(r,r+i);const f=s.charCodeAt(s.length-1);if(s.length>1&&f>=55296&&f<=56319&&(s=s.slice(0,-1)),o.push(s),r+=s.length,t.length===0)break}const l=o.length;return o.map((i,s)=>({type:"log",part:s,of:l,data:i}))}function j(t){if(t.length===0)return null;const e=t[0].of,n=new Map;for(const r of t){if(r.of!==e)return null;n.set(r.part,r.data)}if(n.size!==e)return null;let o="";for(let r=0;r<e;r++){const l=n.get(r);if(l===void 0)return null;o+=l}return o}function g(t,e=new WeakSet){if(t===null||typeof t!="object")return t;if(e.has(t))return"[circular]";e.add(t);try{if(Array.isArray(t))return t.map(o=>g(o,e));if(t instanceof Error)return{name:t.name,message:t.message};const n={};for(const[o,r]of Object.entries(t))n[o]=b.has(o.toLowerCase())?"[redacted]":g(r,e);return n}finally{e.delete(t)}}const S=4e3,N=1500;function X(){try{return globalThis.localStorage??null}catch{return null}}function P(t,e=X()){const n=[],o=new Set;let r=[];try{const c=JSON.parse(e?.getItem(t)??"[]");r=Array.isArray(c)?c:[]}catch{r=[]}function l(c,u,p){const a=Date.now(),h={t:a,iso:new Date(a).toISOString(),cat:c,msg:u};p!==void 0&&(h.data=g(p)),n.push(h),n.length>S&&n.splice(0,n.length-S);for(const d of[...o])try{d(h)}catch{}return h}function i(){try{e?.setItem(t,JSON.stringify(n.slice(-N)))}catch{}}function s(){const c={};for(const a of n)c[a.cat]=(c[a.cat]??0)+1;const u=n[0]?.t??Date.now(),p=n[n.length-1]?.t??u;return{events:n.length,counts:c,started:new Date(u).toISOString(),durationMin:+((p-u)/6e4).toFixed(1),errors:c.error??0}}function f(c){return o.add(c),()=>{o.delete(c)}}return{events:n,previous:r,note:l,persist:i,summary:s,on:f}}function G(t,e){const n=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),o=URL.createObjectURL(n),r=document.createElement("a");r.href=o,r.download=t,r.click(),setTimeout(()=>URL.revokeObjectURL(o),1e3)}export{O as C,L as a,P as b,I as c,G as d,k as f,w as i,j,R as p,g as r};