Files
clash-for-linux/dashboard/public/_nuxt/RfkGMhKY.js
wnlen ac5a8931a6 ui
2026-01-15 21:23:41 +08:00

1 line
5.9 KiB
JavaScript

import{E as e,M as t,W as n,yt as r}from"./DB3QyUG1.js";import{a as i}from"./_v7-ePgP.js";import{t as a}from"./Ds3PMqWb.js";var o=typeof global==`object`&&global&&global.Object===Object&&global,s=typeof self==`object`&&self&&self.Object===Object&&self,c=o||s||Function(`return this`)(),l=c.Symbol,u=Object.prototype,d=u.hasOwnProperty,f=u.toString,p=l?l.toStringTag:void 0;function m(e){var t=d.call(e,p),n=e[p];try{e[p]=void 0;var r=!0}catch{}var i=f.call(e);return r&&(t?e[p]=n:delete e[p]),i}var h=m,g=Object.prototype.toString;function _(e){return g.call(e)}var v=_,y=`[object Null]`,b=`[object Undefined]`,x=l?l.toStringTag:void 0;function S(e){return e==null?e===void 0?b:y:x&&x in Object(e)?h(e):v(e)}var C=S;function w(e){return typeof e==`object`&&!!e}var T=w,E=`[object Number]`;function D(e){return typeof e==`number`||T(e)&&C(e)==E}var O=D;const k=t(`connections`,()=>{let t=a(),i=r([]),o=r([]),s=r([]),c=r(null),l=r(!1),u=e(`dataUsageMap`,{}),d=e(`dataUsageBaseline`,{upload:0,download:0}),f=0,p=0,m=new Map,h=!1,g=(e,t)=>{let n=new Map;return t.forEach(e=>n.set(e.id,e)),e.map(e=>{let t=n.get(e.id);if(!t||!O(t.download)||!O(t.upload)){let t=e;return{...e,downloadSpeed:t.downloadSpeed??0,uploadSpeed:t.uploadSpeed??0}}return{...e,downloadSpeed:e.download-t.download,uploadSpeed:e.upload-t.upload}})},_=e=>{let t=new Set,n=[];for(let e of i.value)t.has(e.id)||(t.add(e.id),n.push(e));for(let r of e)t.has(r.id)||(t.add(r.id),n.push(r));let r=e.length+200;i.value=r>0&&n.length>r?n.slice(-r):n},v=(e,t)=>{let n=new Set(e.map(e=>e.id));return t.filter(e=>!n.has(e.id))},y=()=>{m.clear(),d.value={upload:0,download:0},h=!1,console.log(`[Data Usage] Connection tracking reset due to service restart`)},b=()=>{u.value={},m.clear()},x=e=>{let t={...u.value};delete t[e],u.value=t},S=e=>{let t=e?new Set(e.map(e=>e.id)):new Set(i.value.map(e=>e.id));m.forEach((e,n)=>{t.has(n)||m.delete(n)})},C=e=>{c.value=e;let n=e?.connections,r=e?.uploadTotal||0,a=e?.downloadTotal||0;if((r<f||a<p)&&(y(),b(),t.clearChartHistory()),f=r,p=a,!n||n.length===0)return;let u=g(n,o.value);if(w(u),S(u),_(u),!l.value){let e=v(u,i.value);o.value=u,s.value=e.slice(-200)}},w=e=>{let t=c.value;t?.uploadTotal,t?.downloadTotal,h||=!0;let n={...u.value},r=Date.now(),i=new Map;e.forEach(e=>{let t=e.metadata.sourceIP;if(!t)return;let n=e.upload||0,r=e.download||0;i.has(t)||i.set(t,{upload:0,download:0,connectionIds:new Set});let a=i.get(t);a.connectionIds.add(e.id);let o=m.get(e.id);if(o){let e=Math.max(0,n-o.upload),t=Math.max(0,r-o.download);a.upload+=e,a.download+=t}else a.upload+=n,a.download+=r;m.set(e.id,{upload:n,download:r})}),i.forEach((e,t)=>{let i=n[t];i?e.upload>0||e.download>0?n[t]={...i,upload:i.upload+e.upload,download:i.download+e.download,total:i.upload+e.upload+(i.download+e.download),firstSeen:i.firstSeen||r,lastSeen:r}:n[t]={...i,lastSeen:r}:(e.upload>0||e.download>0)&&(n[t]={sourceIP:t,macAddress:``,upload:e.upload,download:e.download,total:e.upload+e.download,firstSeen:r,lastSeen:r})}),u.value=n};return{allConnections:i,activeConnections:o,closedConnections:s,latestConnectionMsg:c,paused:l,dataUsageMap:u,speedGroupByName:n(()=>{let e={};return o.value.forEach(t=>{t.chains.forEach(n=>{e[n]||(e[n]=0),e[n]+=t.downloadSpeed})}),e}),updateFromWsMsg:C,clearDataUsage:b,removeDataUsageEntry:x,restructRawMsgToConnection:g}});var A={},j=new WeakMap,M={metric:[{from:0,to:1e3,unit:`B`,long:`bytes`},{from:1e3,to:1e6,unit:`kB`,long:`kilobytes`},{from:1e6,to:1e9,unit:`MB`,long:`megabytes`},{from:1e9,to:0xe8d4a51000,unit:`GB`,long:`gigabytes`},{from:0xe8d4a51000,to:0x38d7ea4c68000,unit:`TB`,long:`terabytes`},{from:0x38d7ea4c68000,to:0xde0b6b3a7640000,unit:`PB`,long:`petabytes`},{from:0xde0b6b3a7640000,to:1e21,unit:`EB`,long:`exabytes`},{from:1e21,to:1e24,unit:`ZB`,long:`zettabytes`},{from:1e24,to:1e27,unit:`YB`,long:`yottabytes`}],metric_octet:[{from:0,to:1e3,unit:`o`,long:`octets`},{from:1e3,to:1e6,unit:`ko`,long:`kilooctets`},{from:1e6,to:1e9,unit:`Mo`,long:`megaoctets`},{from:1e9,to:0xe8d4a51000,unit:`Go`,long:`gigaoctets`},{from:0xe8d4a51000,to:0x38d7ea4c68000,unit:`To`,long:`teraoctets`},{from:0x38d7ea4c68000,to:0xde0b6b3a7640000,unit:`Po`,long:`petaoctets`},{from:0xde0b6b3a7640000,to:1e21,unit:`Eo`,long:`exaoctets`},{from:1e21,to:1e24,unit:`Zo`,long:`zettaoctets`},{from:1e24,to:1e27,unit:`Yo`,long:`yottaoctets`}],iec:[{from:0,to:1024**1,unit:`B`,long:`bytes`},{from:1024**1,to:1024**2,unit:`KiB`,long:`kibibytes`},{from:1024**2,to:1024**3,unit:`MiB`,long:`mebibytes`},{from:1024**3,to:1024**4,unit:`GiB`,long:`gibibytes`},{from:1024**4,to:1024**5,unit:`TiB`,long:`tebibytes`},{from:1024**5,to:1024**6,unit:`PiB`,long:`pebibytes`},{from:1024**6,to:1024**7,unit:`EiB`,long:`exbibytes`},{from:1024**7,to:1024**8,unit:`ZiB`,long:`zebibytes`},{from:1024**8,to:1024**9,unit:`YiB`,long:`yobibytes`}],iec_octet:[{from:0,to:1024**1,unit:`o`,long:`octets`},{from:1024**1,to:1024**2,unit:`Kio`,long:`kibioctets`},{from:1024**2,to:1024**3,unit:`Mio`,long:`mebioctets`},{from:1024**3,to:1024**4,unit:`Gio`,long:`gibioctets`},{from:1024**4,to:1024**5,unit:`Tio`,long:`tebioctets`},{from:1024**5,to:1024**6,unit:`Pio`,long:`pebioctets`},{from:1024**6,to:1024**7,unit:`Eio`,long:`exbioctets`},{from:1024**7,to:1024**8,unit:`Zio`,long:`zebioctets`},{from:1024**8,to:1024**9,unit:`Yio`,long:`yobioctets`}]},N=class{constructor(e,t){t=Object.assign({units:`metric`,precision:1,locale:void 0},A,t),j.set(this,t),Object.assign(M,t.customUnits);let n=e<0?`-`:``;e=Math.abs(e);let r=M[t.units];if(r){let i=r.find(t=>e>=t.from&&e<t.to);if(i){let r=new Intl.NumberFormat(t.locale,{style:`decimal`,maximumFractionDigits:t.precision});this.value=i.from===0?n+r.format(e):n+r.format(e/i.from),this.unit=i.unit,this.long=i.long}else this.value=n+e,this.unit=``,this.long=``}else throw Error(`Invalid units specified: ${t.units}`)}toString(){let e=j.get(this);return e.toStringFn?e.toStringFn.bind(this)():`${this.value} ${this.unit}`}};function P(e,t){return new N(e,t)}P.defaultOptions=function(e){A=e};var F=P;export{c as i,k as n,C as r,F as t};