PageSourceSearch

https://kwain.net/resources/PiHole-BbJ_ZIaP.js

js kwain.net collected 2026-10-04 11:06:35 UTC 3,485 bytes, 1 lines download raw bytes

1import{a as e,c as t,d as n,g as r,l as i,m as a,n as o,o as s,p as c,r as l,s as u,u as d,v as f}from"./index-C32yDzkE.js";var p={name:`PiHole`,mixins:[o],props:{item:{type:Object,required:!0}},data:()=>({status:``,percent_blocked:0,sessionId:null,sessionExpiry:null,retryCount:0,maxRetries:3,retryDelay:5e3}),computed:{percentage:function(){return this.percent_blocked>=0?this.percent_blocked.toFixed(1):``},isAuthenticated(){return this.sessionId&&this.sessionExpiry&&Date.now()<this.sessionExpiry}},created(){parseInt(this.item.apiVersion,10)===6?(this.loadCachedSession(),this.autoUpdateMethod=this.fetchStatus):this.autoUpdateMethod=this.fetchStatus_v5(),this.autoUpdateMethod()},methods:{handleError:function(e,t){console.error(e),this.subtitle=e,this.status=t},loadCachedSession:function(){try{let e=localStorage.getItem(`pihole_session_${this.item.url}`);if(e){let t=JSON.parse(e);t.expiry>Date.now()?(this.sessionId=t.sid,this.sessionExpiry=t.expiry):this.removeCacheSession()}}catch(e){this.handleError(`Failed to load cached session: ${e}`,`error`),this.removeCacheSession()}},removeCacheSession:function(){localStorage.removeItem(`pihole_session_${this.item.url}`),this.sessionId=null,this.sessionExpiry=null},authenticate:async function(){try{let e=await this.fetch(`/api/auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({password:this.item.apikey})});if(e?.session?.sid)return this.sessionId=e.session.sid,this.sessionExpiry=Date.now()+e.session.validity*1e3,localStorage.setItem(`pihole_session_${this.item.url}`,JSON.stringify({sid:this.sessionId,expiry:this.sessionExpiry})),this.retryCount=0,!0;throw Error(`Invalid authentication response`)}catch(e){return this.handleError(`Authentication failed: ${e}`,`disabled`),!1}},retryWithDelay:async function(){return console.log(`Retrying authentication...`),this.retryCount<this.maxRetries&&(this.retryCount++,await new Promise(e=>setTimeout(e,this.retryDelay)),this.fetchStatus())},fetchStatus:async function(){try{if(!this.isAuthenticated&&this.item.apikey&&!await this.authenticate())return;let[e,t]=await Promise.all([this.fetch(`api/stats/summary?sid=${encodeURIComponent(this.sessionId)}`),this.fetch(`api/dns/blocking?sid=${encodeURIComponent(this.sessionId)}`)]);if(e?.queries?.percent_blocked===void 0||t?.blocking===void 0)throw Error(`Invalid response format`);this.status=t.blocking,this.percent_blocked=e.queries.percent_blocked,this.retryCount=0}catch(e){if((e.message.includes(`401 error`)||e.message.includes(`403 error`))&&this.item.apikey)return this.removeCacheSession(),this.retryWithDelay();this.handleError(`Failed to fetch status: ${e.message||e}`,`error`),this.removeCacheSession()}},async fetchStatus_v5(){let e=this.item.apikey?`?summaryRaw&auth=${this.item.apikey}`:``,t=await this.fetch(`/api.php${e}`).catch(e=>this.handleError(`Failed to fetch status: ${e}`,`error`));this.status=t.status,this.percent_blocked=t.ads_percentage_today}}},m={class:`title is-4`},h={class:`subtitle is-6`};function g(o,l,p,g,_,v){let y=c(`Generic`);return n(),u(y,{item:p.item},{content:a(()=>[s(`p`,m,f(p.item.name),1),s(`p`,h,[p.item.subtitle?(n(),i(e,{key:0},[d(f(p.item.subtitle),1)],64)):v.percentage?(n(),i(e,{key:1},[d(f(v.percentage)+`% blocked `,1)],64)):t(``,!0)])]),indicator:a(()=>[o.status?(n(),i(`div`,{key:0,class:r([`status`,o.status])},f(o.status),3)):t(``,!0)]),_:1},8,[`item`])}var _=l(p,[[`render`,g],[`__scopeId`,`data-v-d1e43677`]]);export{_ as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.