dns-worker 1.2.4-alpha.b867a80 → 1.2.4-canary.1eaaf16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/serverfull.mjs +1 -1
- package/dist/serverfull.mjs.map +2 -2
- package/package.json +3 -3
- package/static/assets/{AccountView-CwKpGOrC.js → AccountView-D1hAuUai.js} +4 -4
- package/static/assets/{AnalyticsView-6R5LCMgP.js → AnalyticsView-Cyx4no09.js} +2 -2
- package/static/assets/{DestinationMap-Bhj4ukLH.js → DestinationMap-CKWSeA7K.js} +1 -1
- package/static/assets/FilteringView-CaJnDt4S.js +1 -0
- package/static/assets/{LogsView-CrQTmZSx.js → LogsView-DQyTzxZF.js} +3 -3
- package/static/assets/{RulesView-C5CetUI9.js → RulesView-B_FIP9E1.js} +1 -1
- package/static/assets/{SettingsView-DWc3w47x.js → SettingsView-Cj8yQqiG.js} +1 -1
- package/static/assets/{SetupView-QFt-oSBh.js → SetupView-BAgDJo3Y.js} +1 -1
- package/static/assets/{SwipeableDrawer-syZCSIcg.js → SwipeableDrawer-BwkmSnIu.js} +1 -1
- package/static/assets/{SystemView-VU0N3T-m.js → SystemView-CZJecf7h.js} +1 -1
- package/static/assets/{TrendChart-DhmcRJ7S.js → TrendChart-DejSnNoz.js} +1 -1
- package/static/assets/allPaths-a_Gma8ca.js +1 -0
- package/static/assets/allPathsLoader-sY5nfYNE.js +1 -0
- package/static/assets/browser-C2GXluhp.js +1 -0
- package/static/assets/date-C6sADc_i.js +1 -0
- package/static/assets/{index-Da3fe_pZ.js → index-BBQgxHBc.js} +6 -6
- package/static/assets/index-BJvh2Wqo.css +2 -0
- package/static/assets/{services-bcBVkRCc.js → services-CE4B8gLU.js} +1 -1
- package/static/assets/splitPathsBySizeLoader-CagJEoij.js +1 -0
- package/static/assets/{useLogsE2ee-DMqYjbbz.js → useLogsE2ee-VUD7c_eS.js} +1 -1
- package/static/assets/vendor-i18next-J2aoF7F1.js +1 -0
- package/static/assets/{vendor-icons-other-BTYC6Wvz.js → vendor-icons-other-kRhgWBno.js} +2 -2
- package/static/assets/vendor-react-DjiBOEpO.js +11 -0
- package/static/assets/vendor-ui-core-DILHJ_S5.js +1 -0
- package/static/assets/{vendor-utils-DRN35ZiK.js → vendor-utils-b59hZvGS.js} +1 -1
- package/static/index.html +7 -7
- package/static/assets/FilteringView-2lyMSl3P.js +0 -1
- package/static/assets/allPaths-ZKIw3HqD.js +0 -1
- package/static/assets/allPathsLoader-CvGx1ejI.js +0 -1
- package/static/assets/browser-DZAcNVpE.js +0 -1
- package/static/assets/date-BRDEOO7h.js +0 -1
- package/static/assets/index-DPsgoopl.css +0 -2
- package/static/assets/splitPathsBySizeLoader-htHoS0DT.js +0 -1
- package/static/assets/vendor-i18next-DlmslyBB.js +0 -1
- package/static/assets/vendor-react-BNI8IqI8.js +0 -11
- package/static/assets/vendor-ui-core-CBIcrXnW.js +0 -1
package/dist/serverfull.mjs
CHANGED
|
@@ -2194,7 +2194,7 @@ ${u}`)}return`
|
|
|
2194
2194
|
ON pulo.user_list_id = ul.id AND pulo.profile_id = p.id
|
|
2195
2195
|
WHERE ul.url = ?
|
|
2196
2196
|
AND COALESCE(pulo.enabled, ul.enabled) = 1`).bind(t).all(),o=new Set;for(let i of n||[])o.add(i.profile_id);for(let i of r||[])o.add(i.profile_id);return Array.from(o)}};var me=class{constructor(e){this.db=e;this.user=new mi(e),this.profile=new fi(e),this.system=new gi(e,this.user),this.metadata=new yi(e)}db;profile;user;system;metadata;static normalizeUrl(e){return Te(e)}async getLists(e){return this.profile.getLists(e)}async addList(e,t,n=!1){return this.profile.addList(e,t,n)}async getListByUrl(e,t){return this.profile.getListByUrl(e,t)}async addListsBulk(e,t){return this.profile.addListsBulk(e,t)}async setEnabled(e,t,n){return this.profile.setEnabled(e,t,n)}async toggleProfileList(e,t,n){return this.profile.toggleProfileList(e,t,n)}async getListById(e,t){return this.profile.getListById(e,t)}async deleteList(e,t){return this.profile.deleteList(e,t)}async updateListSyncStatus(e,t,n,r=null,o,i){return this.profile.updateListSyncStatus(e,t,n,r,o,i)}async resetListSyncStatus(e){return this.profile.resetListSyncStatus(e)}async getUserLists(e){return this.user.getUserLists(e)}async addUserList(e,t,n=!1){return this.user.addUserList(e,t,n)}async getUserListByUrl(e,t){return this.user.getUserListByUrl(e,t)}async getUserListById(e,t){return this.user.getUserListById(e,t)}async deleteUserList(e,t){return this.user.deleteUserList(e,t)}async toggleUserList(e,t,n){return this.user.toggleUserList(e,t,n)}async hasListForUser(e,t){return this.user.hasListForUser(e,t)}async distributeListToAllUsers(e){return this.system.distributeListToAllUsers(e)}async getDistributedSystemLists(){return this.system.getDistributedSystemLists()}async revokeSystemList(e){return this.system.revokeSystemList(e)}async getGlobalListMetadata(e){return this.metadata.getGlobalListMetadata(e)}async updateGlobalListMetadata(e,t,n,r,o=null,i){return this.metadata.updateGlobalListMetadata(e,t,n,r,o,i)}async getDistinctActiveUrls(e,t=10){return this.metadata.getDistinctActiveUrls(e,t)}async getProfilesSubscribingToUrl(e){return this.metadata.getProfilesSubscribingToUrl(e)}};var $e=class s{constructor(e){this.db=e}db;static normalizeUrl(e){return e.trim().replace(/\/+$/,"")}async resolveUrl(e){if(typeof e=="string")return s.normalizeUrl(e);let t=await this.db.prepare("SELECT url FROM lists WHERE id = ?").bind(e).first();return t?.url?s.normalizeUrl(t.url):null}async upsertListBloom(e,t,n){let r=await this.resolveUrl(e);if(!r)return!1;let o=new Uint8Array(t),i=[];i.push(this.db.prepare("INSERT OR IGNORE INTO global_list_metadata (url, created_at) VALUES (?, ?)").bind(r,n)),i.push(this.db.prepare("DELETE FROM global_list_blooms WHERE url = ?").bind(r));let l=0;for(let c=0;c<o.length;c+=Kt){let u=o.slice(c,c+Kt).buffer;i.push(this.db.prepare("INSERT INTO global_list_blooms (url, chunk_index, bloom_filter_chunk, updated_at) VALUES (?, ?, ?, ?)").bind(r,l,u,n)),l++}return(await this.db.batch(i)).every(c=>c.success)}async hasListBloom(e){let t=await this.resolveUrl(e);return t?!!await this.db.prepare("SELECT 1 AS present FROM global_list_blooms WHERE url = ? LIMIT 1").bind(t).first():!1}async getListBloom(e){let t=await this.resolveUrl(e);if(!t)return null;let{results:n}=await this.db.prepare("SELECT bloom_filter_chunk FROM global_list_blooms WHERE url = ? ORDER BY chunk_index ASC").bind(t).all();if(!n||n.length===0)return null;let r=n.reduce((l,a)=>{let c=a.bloom_filter_chunk.byteLength??a.bloom_filter_chunk.length;return l+c},0),o=new Uint8Array(r),i=0;for(let l of n){let a=new Uint8Array(l.bloom_filter_chunk);o.set(a,i),i+=a.length}return o.buffer}async deleteListBloom(e){let t=await this.resolveUrl(e);return t?(await this.db.prepare("DELETE FROM global_list_blooms WHERE url = ?").bind(t).run()).success:!1}};async function Ir(s,e,t,n,r,o,i,l,a,c){let d=(await e.getLists(s)).filter(g=>!!g.enabled),p=new Set,f=[];for(let g of d){let y=me.normalizeUrl(g.url);p.has(y)||(p.add(y),f.push(g))}let m=c?.DB?new ht(c.DB):null;if(f.length===0)await Promise.all([n.clearProfileBlooms(s),m?.clearProfileRules(s)]);else if(f.length===1){let g=f[0],[y,h]=await Promise.all([t.getListBloom(g.url),m?m.getListRules(g.url):Promise.resolve(null)]),E=[];if(y?E.push(n.upsertProfileBloom(s,y,i)):E.push(n.clearProfileBlooms(s)),m){let _=h||{exceptions:[],rewrites:{},patterns:[]};E.push(m.upsertProfileRules(s,_,i))}await Promise.all(E)}else{let g=Oe.create(l,a),y=!1,h={exceptions:[],rewrites:{},patterns:[]},E=Number(c?.MAX_REGEX_RULES)||1e3,_=Number(c?.MAX_ADGUARD_EXCEPTIONS)||5e4,T=Number(c?.MAX_ADGUARD_REWRITES)||5e4,b=new Set,w=0;for(let S of f)try{let R=await t.getListBloom(S.url);if(R){let N=Oe.fromUint8Array(new Uint8Array(R));g.merge(N),y=!0}if(m){let N=await m.getListRules(S.url);if(N){if(Array.isArray(N.exceptions))for(let A of N.exceptions){if(h.exceptions.length>=_)break;let D=`${A.domain}:${A.includeSubdomains?1:0}`;b.has(D)||(b.add(D),h.exceptions.push(A))}if(N.rewrites&&typeof N.rewrites=="object")for(let[A,D]of Object.entries(N.rewrites)){if(w>=T)break;Object.prototype.hasOwnProperty.call(h.rewrites,A)||w++,h.rewrites[A]=D}if(Array.isArray(N.patterns))for(let A of N.patterns)h.patterns.length<E&&h.patterns.push(A)}}}catch(R){console.error(`[Sync] Failed to load/merge rules for list #${S.id}:`,R)}if(y){let S=g.toUint8Array();await n.upsertProfileBloom(s,S.buffer,i)}else await n.clearProfileBlooms(s);m&&await m.upsertProfileRules(s,h,i)}await r.updateListUpdatedAt(s,i),o&&typeof o.waitUntil=="function"&&o.waitUntil(io.clear(s,!0,c))}function Du(s){if(!s)return null;let e=Date.parse(s);return isNaN(e)?null:Math.floor(e/1e3)}var sm=new Set([429,502,503,504,520,521,522,523,524,525,526]),mw={"User-Agent":Ii(),Accept:"text/plain, text/*, */*","Accept-Encoding":"gzip, deflate, br"},kr=2,nm=1e3,Ou={"https://big.oisd.nl":"https://raw.githubusercontent.com/sjhgvr/oisd/main/abp_big.txt","https://big.oisd.nl/domainswild2":"https://raw.githubusercontent.com/sjhgvr/oisd/main/domainswild2_big.txt","https://small.oisd.nl":"https://raw.githubusercontent.com/sjhgvr/oisd/main/abp_small.txt","https://small.oisd.nl/domainswild2":"https://raw.githubusercontent.com/sjhgvr/oisd/main/domainswild2_small.txt"};async function Cu(s,e,t,n,r){let o=Date.now()+t,i=5,l=null,a=s;for(let c=0;c<=kr;c++){if(c>0){let f=nm*Math.pow(2,c-1);if(o-Date.now()<=f+1e3)break;await new Promise(g=>setTimeout(g,f))}let u=a,d=0,p;try{for(;;){if(!await an(u))return{count:0,error:"Invalid list URL. Private networks, localhosts, and internal domains are not allowed.",truncated:!1};let R=o-Date.now();if(R<=0)return{count:0,error:"Request timed out",truncated:!1};let N={"User-Agent":Ii(),Accept:"text/plain, text/*, */*","Accept-Encoding":"gzip, deflate, br"};if(r?.etag&&(N["If-None-Match"]=r.etag),r?.lastModified!==void 0&&r?.lastModified!==null){let A=typeof r.lastModified=="number"?new Date(r.lastModified*1e3).toUTCString():String(r.lastModified);N["If-Modified-Since"]=A}if(p=await fetch(u,{redirect:"manual",signal:AbortSignal.timeout(R),headers:N}),p.status===304){let A=p.headers.get("etag")||r?.etag||null,D=Du(p.headers.get("last-modified"))??r?.lastModified??null;return{count:0,error:null,truncated:!1,notModified:!0,etag:A,lastModified:D}}if(p.status>=300&&p.status<400){let A=p.headers.get("location");if(!A)return{count:0,error:`Redirect status ${p.status} without Location header`,truncated:!1};if(d++,d>i)return{count:0,error:`Too many redirects (max ${i})`,truncated:!1};try{let D=new URL(A,u).toString(),C=new URL(D).protocol;if(C!=="http:"&&C!=="https:")return{count:0,error:`Invalid redirect protocol: ${C}`,truncated:!1};u=D;continue}catch{return{count:0,error:`Invalid redirect location: ${A}`,truncated:!1}}}break}if(!p.ok){if(p.status===525){let N=u.replace(/\/+$/,"").toLowerCase(),A=Ou[N];if(A&&u!==A){console.warn(`[Fetcher] Origin ${u} failed with HTTP 525 (TLS renegotiation). Falling back to official mirror: ${A}`),a=A,u=A;continue}}let R=p.statusText||(p.status===525?"SSL Handshake Failed":"<none>");if(l=`HTTP error! Status: ${p.status} ${R}`,sm.has(p.status)&&c<kr&&o-Date.now()>2e3){console.warn(`[Fetcher] Transient HTTP ${p.status} for ${s}. Retrying attempt ${c+1}/${kr}...`);continue}return{count:0,error:l,truncated:!1}}let f=p.headers.get("content-length");if(f&&parseInt(f,10)>e)return{count:0,error:`List too large (${(parseInt(f,10)/1024/1024).toFixed(2)} MB), limit is ${(e/1024/1024).toFixed(0)} MB`,truncated:!0};let m=p.body?.getReader();if(!m)return{count:0,error:"Failed to get stream reader from response",truncated:!1};let g=new TextDecoder("utf-8",{fatal:!1,ignoreBOM:!0}),y="",h=0,E=0,_=0,T=0,b=!1;for(;;){let{done:R,value:N}=await m.read();if(R)break;if(N){if(T+=N.length,T>e){await m.cancel(),b=!0;break}let A=g.decode(N,{stream:!0});y+=A;let D=0,C;for(;(C=y.indexOf(`
|
|
2197
|
-
`,D))!==-1;){let I=C;I>D&&y.charCodeAt(I-1)===13&&I--;let $=y.slice(D,I);D=C+1;let j=aa($);if(j)if(j.kind===4)E++;else if(j.kind===5)_++;else{let B=n(j);B instanceof Promise&&await B,h++}}y=D>0?y.slice(D):y}}if(y){let R=y;R.charCodeAt(R.length-1)===13&&(R=R.slice(0,-1));let N=aa(R);if(N)if(N.kind===4)E++;else if(N.kind===5)_++;else{let A=n(N);A instanceof Promise&&await A,h++}}b&&console.warn(`[Fetcher] List truncated at ${(e/1024/1024).toFixed(0)} MB: ${s}`);let w=p.headers.get("etag")||null,S=Du(p.headers.get("last-modified"));return{count:h,error:null,truncated:b,totalBytes:T,commentLines:E,unsupportedLines:_,notModified:!1,etag:w,lastModified:S}}catch(f){l=f.message||String(f);let m=u.replace(/\/+$/,"").toLowerCase(),g=Ou[m];if(g&&u!==g){console.warn(`[Fetcher] Connection error for ${u} (${l}). Falling back to official mirror: ${g}`),a=g,u=g;continue}if(c<kr&&o-Date.now()>2e3){console.warn(`[Fetcher] Transient network error for ${s}: ${l}. Retrying attempt ${c+1}/${kr}...`);continue}return{count:0,error:l,truncated:!1}}}return{count:0,error:l||"Failed to fetch list after retries",truncated:!1}}var rm=20*1024*1024;async function Et(s,e,t,n,r){let o=me.normalizeUrl(s),i=Number(e.SYNC_TIMEOUT_MS)||9e4,l=Number(e.MAX_LIST_DOMAINS)||5e5,a=Number(e.MAX_SYNC_DOMAINS)||1e6,c=Number(e.MAX_LIST_BYTES)||rm,u=Number(e.BLOOM_FALSE_POSITIVE_RATE)||1e-4,d=Number(e.MAX_REGEX_RULES)||1e3,p=Number(e.MAX_ADGUARD_EXCEPTIONS)||5e4,f=Number(e.MAX_ADGUARD_REWRITES)||5e4,m=0,g=Number(e.SYNC_YIELD_BATCH_SIZE)||5e3,y=Number(e.SYNC_YIELD_SLEEP_MS)||10,h=await t.getGlobalListMetadata(o),E=Oe.create(a,u),_={exceptions:[],rewrites:{},patterns:[]},T=0,b=0,w={total_rules:0,exact_rules:0,subdomain_rules:0,wildcard_rules:0,regex_rules:0,exception_rules:0,rewrite_rules:0,comment_lines:0,unsupported_lines:0},{error:S,truncated:R,totalBytes:N,commentLines:A,unsupportedLines:D,notModified:C,etag:I,lastModified:$}=await Cu(o,c,i,B=>{if(T<l&&(B.kind===0&&B.domain?(E.add(B.domain),B.includeSubdomains?(E.addPipePipe(B.domain),w.subdomain_rules++):w.exact_rules++,T++):B.kind===1&&B.domain?_.exceptions.length<p&&(_.exceptions.push({domain:B.domain,includeSubdomains:!!B.includeSubdomains,raw:B.raw}),w.exception_rules++,T++):B.kind===2&&B.domain&&B.rewrite?m<f&&(Object.prototype.hasOwnProperty.call(_.rewrites,B.domain)||m++,_.rewrites[B.domain]={...B.rewrite,includeSubdomains:!!B.includeSubdomains,raw:B.raw},w.rewrite_rules++,T++):B.kind===3&&B.patternRegex&&_.patterns.length<d&&(_.patterns.push({pattern:B.patternRegex,apexIndex:B.apexIndex,raw:B.raw}),B.raw.startsWith("/")?w.regex_rules++:w.wildcard_rules++,T++),b++,b>=g))return b=0,new Promise(G=>setTimeout(G,y))},{etag:h?.etag,lastModified:h?.last_modified});if(C)return console.log(`[Sync Global] URL ${o} 304 Not Modified (using cached global bloom).`),await t.updateGlobalListMetadata(o,r,I??h?.etag,$??h?.last_modified,null),{syncError:null,notModified:!0};let j=S;if(S)console.warn(`[Sync Global] failed to fetch/parse global list ${o}. Skipping and keeping old bloom. Error: ${S}`);else{w.total_rules=T,w.comment_lines=A??0,w.unsupported_lines=D??0,w.total_bytes=N,w.truncated=R||T>=l,R&&(j=`List truncated at ${(c/1024/1024).toFixed(0)} MB: Maximum list size reached. Excess rules were omitted.`,console.warn(`[Sync Global] URL ${o} truncated at ${(c/1024/1024).toFixed(0)} MB with ${T} rules. Warning: ${j}`));let B=[n.upsertListBloom(o,E.toUint8Array().buffer,r)];e?.DB&&B.push(new ht(e.DB).upsertListRules(o,_,r)),await Promise.all(B),R||console.log(`[Sync Global] successfully updated global list ${o} with ${T} rules.`)}return await t.updateGlobalListMetadata(o,r,I??h?.etag,$??h?.last_modified,j,S?void 0:w),{syncError:j,notModified:!1}}var at=new Map;async function Za(s,e){let t=new me(s.DB),n=new $e(s.DB),r=new yt(s.DB),o=new q(s.DB),i=Math.floor(Date.now()/1e3),l=Number(s.SYNC_PROFILE_INTERVAL_SEC)||86400,a=i-l,c=await t.getDistinctActiveUrls(a,1);if(c.length===0)return!1;let u=c[0];console.log(`[Sync System] Checking unified update for global list: ${u}`);try{let{notModified:d,syncError:p}=await Et(u,s,t,n,i);if(!d&&!p){let f=await t.getProfilesSubscribingToUrl(u);console.log(`[Sync System] List updated: recompiling filters for ${f.length} affected profile(s).`);let m=Number(s.MAX_SYNC_DOMAINS)||1e6,g=Number(s.BLOOM_FALSE_POSITIVE_RATE)||1e-4,y=Number(s.MAX_RECOMBINE_PER_CRON)||50,h=f.slice(0,y);for(let E=0;E<h.length;E++){let _=h[E];try{await Ir(_,t,n,r,o,e,i,m,g,s)}catch(T){console.error(`[Sync System] Failed to recombine profile ${_}:`,T)}(E+1)%10===0&&await new Promise(T=>setTimeout(T,0))}}else d&&console.log(`[Sync System] List ${u} 304 Not Modified: 0 profiles need recombine.`);return!0}catch(d){return console.error(`[Sync System] Error updating global list ${u}:`,d),!1}}async function el(s,e,t){let n=at.get(s);if(n){if(n.type==="all")return console.log(`[Sync] Profile ${s}: manual sync already in-flight. Joining active promise.`),n.promise;console.log(`[Sync] Profile ${s}: waiting for in-flight ${n.type} sync to finish before running manual sync.`),await n.promise.catch(()=>{})}let r=at.get(s);if(r&&r.type==="all")return r.promise;let o=(async()=>{try{await im(s,e,t)}finally{at.delete(s)}})();return at.set(s,{type:"all",promise:o}),o}async function im(s,e,t){let n=new q(e.DB),r=new me(e.DB),o=new yt(e.DB),i=new $e(e.DB),l=Math.floor(Date.now()/1e3);try{if(!await n.getById(s)){console.error(`[Sync] Profile ${s} not found.`);return}let u=(await r.getLists(s)).filter(f=>!!f.enabled);if(u.length===0){await o.clearProfileBlooms(s),await n.updateListUpdatedAt(s,l);return}for(let f of u)await i.hasListBloom(f.url)||await Et(f.url,e,r,i,l);await n.updateListUpdatedAt(s,l);let d=Number(e.MAX_SYNC_DOMAINS)||1e6,p=Number(e.BLOOM_FALSE_POSITIVE_RATE)||1e-4;await Ir(s,r,i,o,n,t,l,d,p,e),console.log(`[Sync] Profile ${s}: manual recombine cycle complete.`)}catch(a){console.error(`[Sync] Critical failure in manual sync for Profile ${s}:`,a),await n.updateListUpdatedAt(s,l)}}async function hi(s,e,t,n){let r=at.get(s);if(r){if(r.type==="single"&&r.listId===e)return console.log(`[Sync] Profile ${s}: sync for list #${e} already in-flight. Joining active promise.`),r.promise;if(r.type==="all")return console.log(`[Sync] Profile ${s}: full sync in-flight (covers list #${e}). Joining active promise.`),r.promise;console.log(`[Sync] Profile ${s}: waiting for in-flight ${r.type} sync to finish before syncing list #${e}.`),await r.promise.catch(()=>{})}let o=at.get(s);if(o&&(o.type==="single"&&o.listId===e||o.type==="all"))return o.promise;let i=(async()=>{try{await am(s,e,t,n)}finally{at.delete(s)}})();return at.set(s,{type:"single",listId:e,promise:i}),i}async function am(s,e,t,n){let r=new me(t.DB),o=new $e(t.DB),i=new yt(t.DB),l=new q(t.DB),a=Math.floor(Date.now()/1e3);try{let c=await r.getListById(e,s);if(!c){console.error(`[Sync] List ${e} not found in profile ${s}`);return}await o.hasListBloom(c.url)||await Et(c.url,t,r,o,a),c.enabled&&(await l.updateListUpdatedAt(s,a),await Ir(s,r,o,i,l,n,a,Number(t.MAX_SYNC_DOMAINS)||1e6,Number(t.BLOOM_FALSE_POSITIVE_RATE)||1e-4,t)),console.log(`[Sync] Profile ${s}: list #${e} merged from system storage.`)}catch(c){console.error(`[Sync] Critical failure in single list merge for Profile ${s}, list ${e}:`,c)}}async function Tt(s,e,t){let n=at.get(s);n&&(console.log(`[Sync] Profile ${s}: waiting for in-flight ${n.type} sync before rebuilding bloom.`),await n.promise.catch(()=>{}));let r=(async()=>{try{await lm(s,e,t)}finally{at.delete(s)}})();return at.set(s,{type:"rebuild",promise:r}),r}async function lm(s,e,t){let n=new me(e.DB),r=new $e(e.DB),o=new yt(e.DB),i=new q(e.DB),a=(await i.getById(s))?.list_updated_at??0,c=(await n.getLists(s)).filter(m=>!!m.enabled),u=new Set,d=c.filter(m=>{let g=me.normalizeUrl(m.url);return u.has(g)?!1:(u.add(g),!0)}),f=(await Promise.all(d.map(m=>r.hasListBloom(m.url).catch(()=>!0)))).findIndex(m=>!m);if(f!==-1){let m=d[f];try{await Et(m.url,e,n,r,Math.floor(Date.now()/1e3))}catch(g){console.error(`[Sync] fetch of list ${m.url} during rebuild failed:`,g)}}await Ir(s,n,r,o,i,t,Math.floor(Date.now()/1e3),Number(e.MAX_SYNC_DOMAINS)||1e6,Number(e.BLOOM_FALSE_POSITIVE_RATE)||1e-4,e),await i.updateListUpdatedAt(s,a)}fe();var vr=0;async function xu(s,e,t){try{let n=typeof caches<"u"?caches.default:null,r=Math.floor(Date.now()/1e3),o=!0;vr&&r-vr<3600&&(o=!1);let i="cron:last_cleanup_timestamp",l=new ue(e.DB);if(o){let a=await O.get(n,i);a&&r-a<3600&&(vr=a,o=!1)}if(o)try{let a=await l.get("cron_last_cleanup_timestamp");if(a){let c=parseInt(a,10)||0;r-c<3600&&(vr=c,o=!1)}}catch(a){console.warn("[Cron] Failed to read persistent cleanup timestamp:",a)}if(o){vr=r,await O.set(n,i,r,3600);try{await l.set("cron_last_cleanup_timestamp",String(r))}catch(a){console.warn("[Cron] Failed to persist cleanup timestamp:",a)}try{let a=new V(e.DB,e),{clearedProfiles:c,deletedUsers:u,purgedLogsCount:d}=await a.applyInactivityPolicy(r);(c>0||u>0||d&&d>0)&&console.log(`[Cron] Inactivity policy: purged ${d||0} query log(s), cleared ${c} profile(s) from abandoned accounts, deleted ${u} abandoned user(s).`)}catch(a){console.error("[Cron] Inactivity policy execution failed:",a)}try{let a=new Be(e.DB),c=Number(e.DOMAIN_ROLLUP_MIN_COUNT)||1,u=await a.aggregateDomainRollups(void 0,c);u>0&&console.log(`[Cron] Domain rollups: aggregated ${u} row(s).`)}catch(a){console.error("[Cron] Domain rollup aggregation failed:",a)}try{let a=new Be(e.DB),c=e.MAX_LOG_RETENTION_DAYS!==void 0&&e.MAX_LOG_RETENTION_DAYS!==""?Number(e.MAX_LOG_RETENTION_DAYS):30,u=e.LOG_CLEANUP_BATCH_LIMIT!==void 0&&e.LOG_CLEANUP_BATCH_LIMIT!==""?Number(e.LOG_CLEANUP_BATCH_LIMIT):1e3,d=e.LOG_CLEANUP_DAILY_BUDGET!==void 0&&e.LOG_CLEANUP_DAILY_BUDGET!==""?Number(e.LOG_CLEANUP_DAILY_BUDGET):2e4;await a.cleanupGlobal(c,u,d)}catch(a){console.error("[Cron] Global log cleanup failed:",a)}try{let{SessionModel:a}=await Promise.resolve().then(()=>(Ie(),Qn)),c=new a(e.DB),{deletedSessions:u,deletedPending:d}=await c.deleteExpiredSessions(r);(u>0||d>0)&&console.log(`[Cron] Purged ${u} expired session(s) and ${d} pending token(s).`)}catch(a){console.error("[Cron] Session cleanup failed:",a)}console.log("[Cron] Cleanup phase completed at",new Date().toISOString())}try{await Gi(e.DB)}catch(a){console.error("[Cron] Cloudflare IP range sync failed:",a)}try{let a="cron:last_idle_sync_check",c=Number(e.SYNC_IDLE_INTERVAL_SEC)||1800,u=await O.get(n,a);u&&r-u<c||(await Za(e,t)?await O.delete(n,a):await O.set(n,a,r,c))}catch(a){console.error("[Cron] Unified global list sync failed:",a)}}catch(n){let r=n instanceof Error?n.message:String(n);console.error("[Cron] Critical Failure:",r)}}fe();he();ve();function Pu(s,e){if(!/^https?:\/\/[a-zA-Z0-9.-]+(:\d{1,5})?$/.test(s))throw new Error("Invalid origin for setup script");if(!/^[a-zA-Z0-9_-]{1,64}$/.test(e))throw new Error("Invalid profile key for setup script");return`#!/bin/bash
|
|
2197
|
+
`,D))!==-1;){let I=C;I>D&&y.charCodeAt(I-1)===13&&I--;let $=y.slice(D,I);D=C+1;let j=aa($);if(j)if(j.kind===4)E++;else if(j.kind===5)_++;else{let B=n(j);B instanceof Promise&&await B,h++}}y=D>0?y.slice(D):y}}if(y){let R=y;R.charCodeAt(R.length-1)===13&&(R=R.slice(0,-1));let N=aa(R);if(N)if(N.kind===4)E++;else if(N.kind===5)_++;else{let A=n(N);A instanceof Promise&&await A,h++}}b&&console.warn(`[Fetcher] List truncated at ${(e/1024/1024).toFixed(0)} MB: ${s}`);let w=p.headers.get("etag")||null,S=Du(p.headers.get("last-modified"));return{count:h,error:null,truncated:b,totalBytes:T,commentLines:E,unsupportedLines:_,notModified:!1,etag:w,lastModified:S}}catch(f){l=f.message||String(f);let m=u.replace(/\/+$/,"").toLowerCase(),g=Ou[m];if(g&&u!==g){console.warn(`[Fetcher] Connection error for ${u} (${l}). Falling back to official mirror: ${g}`),a=g,u=g;continue}if(c<kr&&o-Date.now()>2e3){console.warn(`[Fetcher] Transient network error for ${s}: ${l}. Retrying attempt ${c+1}/${kr}...`);continue}return{count:0,error:l,truncated:!1}}}return{count:0,error:l||"Failed to fetch list after retries",truncated:!1}}var rm=20*1024*1024;async function Et(s,e,t,n,r){let o=me.normalizeUrl(s),i=Number(e.SYNC_TIMEOUT_MS)||9e4,l=Number(e.MAX_LIST_DOMAINS)||5e5,a=Number(e.MAX_SYNC_DOMAINS)||1e6,c=Number(e.MAX_LIST_BYTES)||rm,u=Number(e.BLOOM_FALSE_POSITIVE_RATE)||1e-4,d=Number(e.MAX_REGEX_RULES)||1e3,p=Number(e.MAX_ADGUARD_EXCEPTIONS)||5e4,f=Number(e.MAX_ADGUARD_REWRITES)||5e4,m=0,g=Number(e.SYNC_YIELD_BATCH_SIZE)||5e3,y=Number(e.SYNC_YIELD_SLEEP_MS)||10,h=await t.getGlobalListMetadata(o),E=Oe.create(a,u),_={exceptions:[],rewrites:{},patterns:[]},T=0,b=0,w={total_rules:0,exact_rules:0,subdomain_rules:0,wildcard_rules:0,regex_rules:0,exception_rules:0,rewrite_rules:0,comment_lines:0,unsupported_lines:0},{error:S,truncated:R,totalBytes:N,commentLines:A,unsupportedLines:D,notModified:C,etag:I,lastModified:$}=await Cu(o,c,i,B=>{if(T<l&&(B.kind===0&&B.domain?(E.add(B.domain),B.includeSubdomains?(E.addPipePipe(B.domain),w.subdomain_rules++):w.exact_rules++,T++):B.kind===1&&B.domain?_.exceptions.length<p&&(_.exceptions.push({domain:B.domain,includeSubdomains:!!B.includeSubdomains,raw:B.raw}),w.exception_rules++,T++):B.kind===2&&B.domain&&B.rewrite?m<f&&(Object.prototype.hasOwnProperty.call(_.rewrites,B.domain)||m++,_.rewrites[B.domain]={...B.rewrite,includeSubdomains:!!B.includeSubdomains,raw:B.raw},w.rewrite_rules++,T++):B.kind===3&&B.patternRegex&&_.patterns.length<d&&(_.patterns.push({pattern:B.patternRegex,apexIndex:B.apexIndex,raw:B.raw}),B.raw.startsWith("/")?w.regex_rules++:w.wildcard_rules++,T++),b++,b>=g))return b=0,new Promise(G=>setTimeout(G,y))},h?.stats?{etag:h.etag,lastModified:h.last_modified}:void 0);if(C)return console.log(`[Sync Global] URL ${o} 304 Not Modified (using cached global bloom).`),await t.updateGlobalListMetadata(o,r,I??h?.etag,$??h?.last_modified,null),{syncError:null,notModified:!0};let j=S;if(S)console.warn(`[Sync Global] failed to fetch/parse global list ${o}. Skipping and keeping old bloom. Error: ${S}`);else{w.total_rules=T,w.comment_lines=A??0,w.unsupported_lines=D??0,w.total_bytes=N,w.truncated=R||T>=l,R&&(j=`List truncated at ${(c/1024/1024).toFixed(0)} MB: Maximum list size reached. Excess rules were omitted.`,console.warn(`[Sync Global] URL ${o} truncated at ${(c/1024/1024).toFixed(0)} MB with ${T} rules. Warning: ${j}`));let B=[n.upsertListBloom(o,E.toUint8Array().buffer,r)];e?.DB&&B.push(new ht(e.DB).upsertListRules(o,_,r)),await Promise.all(B),R||console.log(`[Sync Global] successfully updated global list ${o} with ${T} rules.`)}return await t.updateGlobalListMetadata(o,r,I??h?.etag,$??h?.last_modified,j,S?void 0:w),{syncError:j,notModified:!1}}var at=new Map;async function Za(s,e){let t=new me(s.DB),n=new $e(s.DB),r=new yt(s.DB),o=new q(s.DB),i=Math.floor(Date.now()/1e3),l=Number(s.SYNC_PROFILE_INTERVAL_SEC)||86400,a=i-l,c=await t.getDistinctActiveUrls(a,1);if(c.length===0)return!1;let u=c[0];console.log(`[Sync System] Checking unified update for global list: ${u}`);try{let{notModified:d,syncError:p}=await Et(u,s,t,n,i);if(!d&&!p){let f=await t.getProfilesSubscribingToUrl(u);console.log(`[Sync System] List updated: recompiling filters for ${f.length} affected profile(s).`);let m=Number(s.MAX_SYNC_DOMAINS)||1e6,g=Number(s.BLOOM_FALSE_POSITIVE_RATE)||1e-4,y=Number(s.MAX_RECOMBINE_PER_CRON)||50,h=f.slice(0,y);for(let E=0;E<h.length;E++){let _=h[E];try{await Ir(_,t,n,r,o,e,i,m,g,s)}catch(T){console.error(`[Sync System] Failed to recombine profile ${_}:`,T)}(E+1)%10===0&&await new Promise(T=>setTimeout(T,0))}}else d&&console.log(`[Sync System] List ${u} 304 Not Modified: 0 profiles need recombine.`);return!0}catch(d){return console.error(`[Sync System] Error updating global list ${u}:`,d),!1}}async function el(s,e,t){let n=at.get(s);if(n){if(n.type==="all")return console.log(`[Sync] Profile ${s}: manual sync already in-flight. Joining active promise.`),n.promise;console.log(`[Sync] Profile ${s}: waiting for in-flight ${n.type} sync to finish before running manual sync.`),await n.promise.catch(()=>{})}let r=at.get(s);if(r&&r.type==="all")return r.promise;let o=(async()=>{try{await im(s,e,t)}finally{at.delete(s)}})();return at.set(s,{type:"all",promise:o}),o}async function im(s,e,t){let n=new q(e.DB),r=new me(e.DB),o=new yt(e.DB),i=new $e(e.DB),l=Math.floor(Date.now()/1e3);try{if(!await n.getById(s)){console.error(`[Sync] Profile ${s} not found.`);return}let u=(await r.getLists(s)).filter(f=>!!f.enabled);if(u.length===0){await o.clearProfileBlooms(s),await n.updateListUpdatedAt(s,l);return}for(let f of u)await i.hasListBloom(f.url)||await Et(f.url,e,r,i,l);await n.updateListUpdatedAt(s,l);let d=Number(e.MAX_SYNC_DOMAINS)||1e6,p=Number(e.BLOOM_FALSE_POSITIVE_RATE)||1e-4;await Ir(s,r,i,o,n,t,l,d,p,e),console.log(`[Sync] Profile ${s}: manual recombine cycle complete.`)}catch(a){console.error(`[Sync] Critical failure in manual sync for Profile ${s}:`,a),await n.updateListUpdatedAt(s,l)}}async function hi(s,e,t,n){let r=at.get(s);if(r){if(r.type==="single"&&r.listId===e)return console.log(`[Sync] Profile ${s}: sync for list #${e} already in-flight. Joining active promise.`),r.promise;if(r.type==="all")return console.log(`[Sync] Profile ${s}: full sync in-flight (covers list #${e}). Joining active promise.`),r.promise;console.log(`[Sync] Profile ${s}: waiting for in-flight ${r.type} sync to finish before syncing list #${e}.`),await r.promise.catch(()=>{})}let o=at.get(s);if(o&&(o.type==="single"&&o.listId===e||o.type==="all"))return o.promise;let i=(async()=>{try{await am(s,e,t,n)}finally{at.delete(s)}})();return at.set(s,{type:"single",listId:e,promise:i}),i}async function am(s,e,t,n){let r=new me(t.DB),o=new $e(t.DB),i=new yt(t.DB),l=new q(t.DB),a=Math.floor(Date.now()/1e3);try{let c=await r.getListById(e,s);if(!c){console.error(`[Sync] List ${e} not found in profile ${s}`);return}await o.hasListBloom(c.url)||await Et(c.url,t,r,o,a),c.enabled&&(await l.updateListUpdatedAt(s,a),await Ir(s,r,o,i,l,n,a,Number(t.MAX_SYNC_DOMAINS)||1e6,Number(t.BLOOM_FALSE_POSITIVE_RATE)||1e-4,t)),console.log(`[Sync] Profile ${s}: list #${e} merged from system storage.`)}catch(c){console.error(`[Sync] Critical failure in single list merge for Profile ${s}, list ${e}:`,c)}}async function Tt(s,e,t){let n=at.get(s);n&&(console.log(`[Sync] Profile ${s}: waiting for in-flight ${n.type} sync before rebuilding bloom.`),await n.promise.catch(()=>{}));let r=(async()=>{try{await lm(s,e,t)}finally{at.delete(s)}})();return at.set(s,{type:"rebuild",promise:r}),r}async function lm(s,e,t){let n=new me(e.DB),r=new $e(e.DB),o=new yt(e.DB),i=new q(e.DB),a=(await i.getById(s))?.list_updated_at??0,c=(await n.getLists(s)).filter(m=>!!m.enabled),u=new Set,d=c.filter(m=>{let g=me.normalizeUrl(m.url);return u.has(g)?!1:(u.add(g),!0)}),f=(await Promise.all(d.map(m=>r.hasListBloom(m.url).catch(()=>!0)))).findIndex(m=>!m);if(f!==-1){let m=d[f];try{await Et(m.url,e,n,r,Math.floor(Date.now()/1e3))}catch(g){console.error(`[Sync] fetch of list ${m.url} during rebuild failed:`,g)}}await Ir(s,n,r,o,i,t,Math.floor(Date.now()/1e3),Number(e.MAX_SYNC_DOMAINS)||1e6,Number(e.BLOOM_FALSE_POSITIVE_RATE)||1e-4,e),await i.updateListUpdatedAt(s,a)}fe();var vr=0;async function xu(s,e,t){try{let n=typeof caches<"u"?caches.default:null,r=Math.floor(Date.now()/1e3),o=!0;vr&&r-vr<3600&&(o=!1);let i="cron:last_cleanup_timestamp",l=new ue(e.DB);if(o){let a=await O.get(n,i);a&&r-a<3600&&(vr=a,o=!1)}if(o)try{let a=await l.get("cron_last_cleanup_timestamp");if(a){let c=parseInt(a,10)||0;r-c<3600&&(vr=c,o=!1)}}catch(a){console.warn("[Cron] Failed to read persistent cleanup timestamp:",a)}if(o){vr=r,await O.set(n,i,r,3600);try{await l.set("cron_last_cleanup_timestamp",String(r))}catch(a){console.warn("[Cron] Failed to persist cleanup timestamp:",a)}try{let a=new V(e.DB,e),{clearedProfiles:c,deletedUsers:u,purgedLogsCount:d}=await a.applyInactivityPolicy(r);(c>0||u>0||d&&d>0)&&console.log(`[Cron] Inactivity policy: purged ${d||0} query log(s), cleared ${c} profile(s) from abandoned accounts, deleted ${u} abandoned user(s).`)}catch(a){console.error("[Cron] Inactivity policy execution failed:",a)}try{let a=new Be(e.DB),c=Number(e.DOMAIN_ROLLUP_MIN_COUNT)||1,u=await a.aggregateDomainRollups(void 0,c);u>0&&console.log(`[Cron] Domain rollups: aggregated ${u} row(s).`)}catch(a){console.error("[Cron] Domain rollup aggregation failed:",a)}try{let a=new Be(e.DB),c=e.MAX_LOG_RETENTION_DAYS!==void 0&&e.MAX_LOG_RETENTION_DAYS!==""?Number(e.MAX_LOG_RETENTION_DAYS):30,u=e.LOG_CLEANUP_BATCH_LIMIT!==void 0&&e.LOG_CLEANUP_BATCH_LIMIT!==""?Number(e.LOG_CLEANUP_BATCH_LIMIT):1e3,d=e.LOG_CLEANUP_DAILY_BUDGET!==void 0&&e.LOG_CLEANUP_DAILY_BUDGET!==""?Number(e.LOG_CLEANUP_DAILY_BUDGET):2e4;await a.cleanupGlobal(c,u,d)}catch(a){console.error("[Cron] Global log cleanup failed:",a)}try{let{SessionModel:a}=await Promise.resolve().then(()=>(Ie(),Qn)),c=new a(e.DB),{deletedSessions:u,deletedPending:d}=await c.deleteExpiredSessions(r);(u>0||d>0)&&console.log(`[Cron] Purged ${u} expired session(s) and ${d} pending token(s).`)}catch(a){console.error("[Cron] Session cleanup failed:",a)}console.log("[Cron] Cleanup phase completed at",new Date().toISOString())}try{await Gi(e.DB)}catch(a){console.error("[Cron] Cloudflare IP range sync failed:",a)}try{let a="cron:last_idle_sync_check",c=Number(e.SYNC_IDLE_INTERVAL_SEC)||1800,u=await O.get(n,a);u&&r-u<c||(await Za(e,t)?await O.delete(n,a):await O.set(n,a,r,c))}catch(a){console.error("[Cron] Unified global list sync failed:",a)}}catch(n){let r=n instanceof Error?n.message:String(n);console.error("[Cron] Critical Failure:",r)}}fe();he();ve();function Pu(s,e){if(!/^https?:\/\/[a-zA-Z0-9.-]+(:\d{1,5})?$/.test(s))throw new Error("Invalid origin for setup script");if(!/^[a-zA-Z0-9_-]{1,64}$/.test(e))throw new Error("Invalid profile key for setup script");return`#!/bin/bash
|
|
2198
2198
|
sudo curl -L 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64' -o /usr/local/bin/cloudflared
|
|
2199
2199
|
sudo chmod +x /usr/local/bin/cloudflared
|
|
2200
2200
|
sudo tee /etc/systemd/system/cloudflared-dns.service > /dev/null <<'EOF'
|