PageSourceSearch

https://www.htx.com/web-v4/sw/sw.js

js htx.com collected 2026-10-01 10:25:27 UTC 17,424 bytes, 15 lines download raw bytes

1/*!
2 * file: Web v4 Service Worker
3 * version: PRD_H418964
4 */
5/*!
6 *    888       888          888               d8888       .d8888b.
7 *    888   o   888          888              d8P888      d88P  Y88b
8 *    888  d8b  888          888             d8P 888      888    888
9 *    888 d888b 888  .d88b.  88888b.        d8P  888      888    888
10 *    888d88888b888 d8P  Y8b 888 "88b      d88   888      888    888
11 *    88888P Y88888 88888888 888  888      8888888888     888    888
12 *    8888P   Y8888 Y8b.     888 d88P            888  d8b Y88b  d88P
13 *    888P     Y888  "Y8888  88888P"             888  Y8P  "Y8888P"
14 */
15const e="PRD_H418964";importScripts("/web-v4/sw/workbox-v7.4.0/workbox-sw.js"),workbox.setConfig({modulePathPrefix:"/web-v4/sw/workbox-v7.4.0/",debug:!1}),workbox.core.setCacheNameDetails({prefix:"",suffix:""});const t=/^(?:[a-z0-9-]*-)?(?:test|stag|tc-jp1|dev|huobiapps|localhost)(?:[-_]?\d+)?$/i;const r=function(){const e=self.location.hostname;return"localhost"===e||"127.0.0.1"===e?"development":e.split(".").some(e=>t.test(e))?"test":"prod"}(),a="/-/x/woodpecker/open/v1/log/trend",n="development"===r?a:`https://open.woodpeckerlog.com${a}`,s="@fe/www-sw",o="www.htx.com",i=new Set(["sw_install","sw_activate","sw_unregister"]),c=new Set(["sw_error","sw_v4_cache_stats","sw_entry_cache"]);let u=[],p=null;const l={};function h(t,a){return{app:1,pid:g,url:self.location.href,source:m,env:r,...l,ext:{version:e,repo:s},action:t,date:Date.now(),data:a}}const m=/huobi/i.test(self.navigator.userAgent)?4:1;const g=function(){const e="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";let t="";for(let r=0;r<12;r++)t+=e[Math.floor(48*Math.random())];return t}();async function y(){if(0===u.length)return;const e=u.splice(0);try{const t=JSON.stringify(e),r=await async function(e){try{const t=new Blob([e]).stream().pipeThrough(new CompressionStream("gzip"));return await new Response(t).arrayBuffer()}catch{return null}}(t),a={"Content-Type":"text/plain; charset=UTF-8"};r&&(a.decode="unzip"),fetch(n,{method:"POST",body:r??t,headers:a,keepalive:!0}).catch(()=>{})}catch{}}function d(e){const t=i.has(e.type);if(!t&&!c.has(e.type)&&Math.random()>=.1)return;u.push(function(e){const{type:t,...r}=e,a="sw_error"===t?"error":"debug",n=Object.keys(r).length>0?JSON.stringify(r):void 0;return h(a,{key:t,...n?{msg:n}:{}})}(e));const r=function(e){const t={host:o,repo:s};return"sw_error"===e.type?h("metrics",{metric_name:"web_sw_error_count",value:1,type:"counter",tags:{...t,sw_error_type:e.type_detail},details:{message:e.message}}):"sw_lazy_init"===e.type?h("metrics",{metric_name:"web_sw_lazy_init_count",value:1,type:"counter",tags:{...t,project:e.project,result:e.result}}):"sw_entry_cache"===e.type?h("metrics",{metric_name:"web_sw_entry_cache_count",value:1,type:"counter",tags:{...t,project:e.project,strategy:e.strategy,result:e.result}}):"sw_v4_cache_stats"===e.type&&e.hits>0?h("metrics",{metric_name:"web_sw_v4_cache_count",value:e.hits,type:"counter",tags:{...t,result:"hit"}}):null}(e);r&&u.push(r);const a=function(e){if("sw_v4_cache_stats"!==e.type||e.misses<=0)return null;const t={host:o,repo:s};return h("metrics",{metric_name:"web_sw_v4_cache_count",value:e.misses,type:"counter",tags:{...t,result:"miss"}}
15)}(e);a&&u.push(a),t||u.length>=20?y():p||(p=setInterval(()=>y(),6e3))}const w="projects";let f=null;function _(){return f||(f=new Promise((e,t)=>{const r=indexedDB.open("fed-www-sw",1);r.onupgradeneeded=()=>{const e=r.result;e.objectStoreNames.contains(w)||e.createObjectStore(w,{keyPath:"projectName"})},r.onsuccess=()=>{const t=r.result;t.onversionchange=()=>{t.close(),f=null},e(t)},r.onerror=()=>t(r.error),r.onblocked=()=>t(new Error("idb open blocked"))}),f.catch(()=>{f=null}),f)}function v(e){return new Promise((t,r)=>{e.oncomplete=()=>t(),e.onabort=()=>r(e.error),e.onerror=()=>r(e.error)})}async function b(e){try{const t=(await _()).transaction(w,"readwrite");t.objectStore(w).put(e),await v(t)}catch(e){throw d({type:"sw_error",type_detail:"idb_write",message:String(e)}),e}}async function x(e){try{const t=(await _()).transaction(w,"readwrite");t.objectStore(w).delete(e),await v(t)}catch(e){throw d({type:"sw_error",type_detail:"idb_delete",message:String(e)}),e}}const $=/(^|\/)preload(\/|$)/,S=/\$(\$|[1-9])/g,k=/\$(?!\$|[1-9](?![0-9]))/;const j=["/web-v4/sw/opt-out.html"],R=new Set(["navigate","asset","api"]),E=new Set(["CacheFirst","StaleWhileRevalidate","NetworkFirst"]);function A(e){let t;if(e.paths){const r=new Set(e.paths);t=e=>r.has(e)?[e]:null}else{const r=new RegExp(e.pathname);t=e=>r.exec(e)}return"navigate"!==e.type?t:e=>$.test(e)?null:t(e)}function N(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function O(e,t){if(!N(e))return P(`${t}: not an object`);if("string"!=typeof e.name||!e.name)return P(`${t}.name: missing or empty`);if(!N(e.match))return P(`${t}.match: not an object`);if(!R.has(e.match.type))return P(`${t}.match.type: invalid ${JSON.stringify(e.match.type)}`);if(void 0!==e.match.sameOrigin&&"boolean"!=typeof e.match.sameOrigin)return P(`${t}.match.sameOrigin: must be boolean`);const r=void 0!==e.match.paths,a=void 0!==e.match.pathname;if(r&&a)return P(`${t}.match: provide either "paths" or "pathname", not both`);if(!r&&!a)return P(`${t}.match: one of "paths" or "pathname" is required`);if(r){const r=e.match.paths;if(!Array.isArray(r)||0===r.length)return P(`${t}.match.paths: must be a non-empty array`);for(let a=0;a<r.length;a++){if("string"!=typeof r[a]||!r[a].startsWith("/"))return P(`${t}.match.paths[${a}]: must be a string starting with "/"`);if("navigate"===e.match.type&&$.test(r[a]))return P(`${t}.match.paths[${a}]: preload pages are never cached for match.type "navigate"`)}}else if("string"!=typeof e.match.pathname||!e.match.pathname)return P(`${t}.match.pathname: missing or empty`);let n;try{n=A(e.match)}catch(e){return P(`${t}.match.pathname: invalid regex (${String(e)})`)}if(!N(e.strategy))return P(`${t}.strategy: not an object`);if(!E.has(e.strategy.type))return P(`${t}.strategy.type: invalid ${JSON.stringify(e.strategy.type)}`);if(void 0!==e.strategy.cacheName)return P(`${t}.strategy.cacheName: not a config field (桶名由 v4/{project}/{rule.name} 自动生成)`);if(void 0!==e.strategy.cacheKey){if("string"!=typeof e.strategy.cacheKey)return P(`${t}.strategy.cacheKey: must be string`);if("navigate"!==e.match.type)return P(`${t}.strategy.cacheKey: not allowed for match.type "${e.match.type}" (only "navigate")`);const r=e.strategy.cacheKey,a=k.exec(r);if(a){const e=r.slice(a.index,a.index+3);return P(`${t}.strategy.cacheKey: invalid placeholder ${JSON.stringify(e)} (only $1-$9 and $$ are allowed)`)}const n=function(e){const t=new RegExp(S.source,"g");let r,a=0;for(;null!==(r=t.exec(e));)"$"!==r[1]&&(a=Math.max(a,Number(r[1])));return a}(r);if(n>0){if(e.match.paths)return P(`${t}.strategy.cacheKey: $${n} needs match.pathname ("paths" has no capture groups)`);const r=function(e){const t=new RegExp(e+"|").exec("");return t?t.length-1:0}(e.match.pathname);if(n>r)return P(`${t}.strategy.cacheKey: $${n} but match.pathname has ${r} capture group(s)`)}}return"number"!=typeof e.strategy.maxAgeSeconds||e.strategy.maxAgeSeconds<=0?P(`${t}.strategy.maxAgeSeconds: must be positive number`):void 0!==e.strategy.maxEntries&&("number"!=typeof e.strategy.maxEntries||e.strategy.maxEntries<=0)?P(`${t}.strategy.maxEntries: must be positive number`):"api"===e.match.type&&void 0===e.strategy.maxEntries?P(`${t}.strategy.maxEntries: required for match.type "api"`):void 0===e.strategy.statuses||Array.isArray(e.strategy.statuses)&&e.strategy.statuses.every(e=>"number"==typeof e)?{ok:!0,value:e,matcher:n}:P(`${t}.strategy.statuses: must be number[]`)}function P(e){return{ok:!1,reason:e}}const W=/\.(?:js|mjs|cjs|css)$/i,C=new Set(["document","iframe","frame","embed","object"]);async function T(e){const t=e.clone().body;if(!t)return!1;const r=t.getReader();try{const{value:e}=await r.read();if(!e||0===e.length)return!1;let t=0;for(239===e[0]&&187===e[1]&&191===e[2]&&(t=3);t<e.length&&(32===e[t]||e[t]>=9&&e[t]<=13);)t++;return 60===e[t]}finally{r.cancel().catch(()=>{})}}function D(e){return e.headers.get("content-type")||"-"}const K={cacheWillUpdate:async({request:e,response:t})=>{if(!t)return null;
15const r=new URL(e.url);if(!function(e,t){const r=e.destination;return"script"===r||"style"===r||""===r&&W.test(t.pathname)}(e,r))return t;if(t.redirected)return d({type:"sw_error",type_detail:"code_redirected",message:r.pathname}),null;let a=!1;try{a=await T(t)}catch{return t}return a?(d({type:"sw_error",type_detail:"markup_for_code",message:`${r.pathname} ct=${D(t)}`}),null):t}},U={cacheWillUpdate:async({request:e,response:t})=>{if(!t)return null;if(C.has(e.destination))return t;let r=!1;try{r=await T(t)}catch{return t}return r?(d({type:"sw_error",type_detail:"markup_for_api",message:`${new URL(e.url).pathname} ct=${D(t)}`}),null):t}};function F(e,t){return`${e}/${t}`}function M(e,t){return`v4/${F(e,t)}`}const z=new Map;function J(e,t){for(const r of e.rules){const a=F(e.project,r.name);try{const n=t?.get(r.name)??A(r.match),s=z.get(a);s&&(s.alive=!1);const o={alive:!0};B(r,n,o,e.project),z.set(a,o)}catch(e){d({type:"sw_error",type_detail:"register_route",message:`${a}: ${String(e)}`})}}}function B(e,t,r,a){const n=!1!==e.match.sameOrigin,s=function(e,t){const{type:r,cacheKey:a,maxAgeSeconds:n,maxEntries:s,statuses:o}=e.strategy,i="CacheFirst"===r?[200]:[200,304],c=[];a&&c.push({cacheKeyWillBeUsed:async({params:e})=>{return t=a,r=Array.isArray(e)?e:null,-1===t.indexOf("$")?t:t.replace(S,(e,t)=>"$"===t?"$":r&&r[Number(t)]||"");var t,r}});"navigate"===e.match.type&&c.push(function(e,t){const r=e.strategy.type;return{cachedResponseWillBeUsed:async({cachedResponse:e})=>(d({type:"sw_entry_cache",project:t,strategy:r,result:e?"hit":"miss"}),e)}}(e,t));c.push(new workbox.cacheableResponse.CacheableResponsePlugin({statuses:o??i}));const u={maxAgeSeconds:n,purgeOnQuotaError:!0};void 0!==s?u.maxEntries=s:"navigate"===e.match.type&&a&&(u.maxEntries=30);c.push(new workbox.expiration.ExpirationPlugin(u)),c.push("api"===e.match.type?U:K);const p={cacheName:M(t,e.name),plugins:c};"api"===e.match.type&&(p.fetchOptions={credentials:"omit"});
15return"CacheFirst"===r?new workbox.strategies.CacheFirst(p):"NetworkFirst"===r?new workbox.strategies.NetworkFirst(p):new workbox.strategies.StaleWhileRevalidate(p)}(e,a);workbox.routing.registerRoute(({url:a,request:s,sameOrigin:o})=>!!r.alive&&(!(n&&!o)&&(("navigate"!==e.match.type||"navigate"===s.mode)&&(("api"!==e.match.type||"navigate"!==s.mode)&&(t(a.pathname)??!1)))),s,"GET")}const G=864e5,L=new Set,q=new Set;async function H(e){try{await b({projectName:e,status:"no_sw_config_project",lastAttempt:Date.now()})}catch{}d({type:"sw_lazy_init",project:e,result:"no_sw_config_project"})}async function Q(e,t){try{await b({projectName:e,status:"error",lastAttempt:Date.now(),errorMessage:t})}catch{}d({type:"sw_lazy_init",project:e,result:"error"})}(async()=>{try{const e=await async function(){try{const e=(await _()).transaction(w,"readonly").objectStore(w).getAll();return await new Promise((t,r)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>r(e.error)})}catch(e){throw d({type:"sw_error",type_detail:"idb_readAll",message:String(e)}),e}}();let t=0;const r=[];for(const a of e)"success"===a.status&&a.config?(J(a.config),t++):"success"!==a.status&&Date.now()-a.lastAttempt>6048e5&&r.push(a.projectName);d({type:"sw_boot_restore",count:t});for(const e of r)try{await x(e)}catch{}}catch(e){d({type:"sw_error",type_detail:"boot_restore",message:String(e)})}})(),self.addEventListener("fetch",e=>{const t=e.request;if("navigate"===t.mode)return void q.clear();if("GET"!==t.method)return;let r;try{r=new URL(t.url)}catch{return}if(r.origin!==self.location.origin)return;const a=function(e){const t=/^\/v4\/([^/]+)\//.exec(e);return t?"-"===t[1]||e.endsWith("/sw-config.json")?null:t[1]:null}(r.pathname);a&&(q.has(a)||(q.add(a),async function(e){if(L.has(e))return;L.add(e);try{let r;try{r=await async function(e){try{const t=(await _()).transaction(w,"readonly").objectStore(w).get(e);return await new Promise((e,r)=>{t.onsuccess=()=>e(t.result??null),t.onerror=()=>r(t.error)})}catch(e){throw d({type:"sw_error",type_detail:"idb_read",message:String(e)}),e}}(e)}catch{return}if(r?.config?.dev_mode&&d({type:"sw_config_dev_mode",project:e}),r&&("error"!==(t=r).status&&!t.config?.dev_mode&&Date.now()-t.lastAttempt<=G))return;await async function(e,t){const r="success"===t?.status,a=r?t?.configHash:void 0;let n;try{n=await fetch(`/v4/${e}/sw-config.json`,{cache:"no-store"})}catch(t){return void d({type:"sw_error",type_detail:"fetch_config",message:`${e}: ${String(t)}`})}if(404===n.status||403===n.status)return void await H(e);if(!n.ok)return void d({type:"sw_error",type_detail:"config_5xx",message:`${e}: ${n.status}`});if(!(n.headers.get("content-type")||"").includes("application/json"))return void await H(e);const s=await n.text(),o=await async function(e){const t=(new TextEncoder).encode(e),r=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(r)).map(e=>e.toString(16).padStart(2,"0")).join("")}(s);if(a&&o===a){try{t&&await b({...t,lastAttempt:Date.now()})}catch{}return}let i;try{i=JSON.parse(s)}catch(t){return void await Q(e,`json parse: ${String(t)}`)}const c=function(e,t){if(!N(e))return P("config: not an object");if("1"!==e.schema_version)return P(`schema_version: expected "1", got ${JSON.stringify(e.schema_version)}`);if("string"!=typeof e.project||!e.project)return P("project: missing or empty");if(e.project!==t)return P(`project: "${e.project}" !== expected "${t}"`);if(void 0!==e.dev_mode&&"boolean"!=typeof e.dev_mode)return P(`dev_mode: must be a boolean, got ${JSON.stringify(e.dev_mode)}`);if(!Array.isArray(e.rules))return P("rules: not an array");const r=new Map,a=new Set;for(let t=0;t<e.rules.length;t++){const n=`rules[${t}]`,s=O(e.rules[t],n);if(!1===s.ok)return s;if(a.has(s.value.name))return P(`${n}.name: duplicate "${s.value.name}"`);a.add(s.value.name);for(const e of j)if(s.matcher(e))return P(`${n}.match.${s.value.match.paths?"paths":"pathname"}: must not match protected path "${e}"`);r.set(s.value.name,s.matcher)}return{ok:!0,value:e,compiled:r}}(i,e);if(!1===c.ok)return void await Q(e,c.reason);J(c.value,c.compiled);try{await b({projectName:e,status:"success",config:c.value,configHash:o,lastAttempt:Date.now()})}catch{}d(r?{type:"sw_config_changed",project:e}:{type:"sw_lazy_init",project:e,result:"success"})}(e,r)}finally{L.delete(e)}var t}(a)))}),workbox.routing.registerRoute(({url:e})=>e.pathname.startsWith("/web-v4/uniframe/uniframe"),new workbox.strategies.StaleWhileRevalidate({cacheName:"uniframe",fetchOptions:{mode:"cors",credentials:"same-origin"}
15,plugins:[new workbox.cacheableResponse.CacheableResponsePlugin({statuses:[200,304]}),new workbox.expiration.ExpirationPlugin({maxAgeSeconds:2592e3}),K]}),"GET"),workbox.routing.registerRoute(({url:e})=>e.pathname.startsWith("/web-v4/entry/"),new workbox.strategies.StaleWhileRevalidate({cacheName:"entry",fetchOptions:{mode:"cors",credentials:"same-origin"},plugins:[new workbox.cacheableResponse.CacheableResponsePlugin({statuses:[200,304]}),new workbox.expiration.ExpirationPlugin({maxAgeSeconds:2592e3}),K]}),"GET"),workbox.routing.registerRoute(({url:e})=>e.pathname.startsWith("/web-v4/woodpecker/"),new workbox.strategies.StaleWhileRevalidate({cacheName:"woodpecker",fetchOptions:{mode:"cors",credentials:"same-origin"},plugins:[new workbox.cacheableResponse.CacheableResponsePlugin({statuses:[200,304]}),new workbox.expiration.ExpirationPlugin({maxAgeSeconds:2592e3}),K]}),"GET"),workbox.routing.registerRoute(({url:e})=>e.search.includes("sw-cache=revalidate"),new workbox.strategies.StaleWhileRevalidate({cacheName:"api",fetchOptions:{mode:"cors",credentials:"same-origin"},plugins:[new workbox.cacheableResponse.CacheableResponsePlugin({statuses:[200,304]}),new workbox.expiration.ExpirationPlugin({maxAgeSeconds:2592e3}),U]}),"GET");const I=new Map;function X(e){const t=I.get(e);t&&(I.delete(e),clearTimeout(t.timer),0===t.hits&&0===t.misses||d({type:"sw_v4_cache_stats",hits:t.hits,misses:t.misses}))}const Y={cachedResponseWillBeUsed:async({cachedResponse:e,event:t})=>(function(e,t){if(!e)return void d({type:"sw_v4_cache_stats",hits:t?1:0,misses:t?0:1});const r=Date.now();let a=I.get(e);a&&r-a.firstSeen>15e3&&(X(e),a=void 0),a?clearTimeout(a.timer):(a={hits:0,misses:0,firstSeen:r,timer:void 0},I.set(e,a)),t?a.hits++:a.misses++,a.timer=setTimeout(()=>X(e),2e3)}(t.clientId,Boolean(e)),e)};workbox.routing.registerRoute(({url:e,sameOrigin:t})=>!!t&&(!!e.pathname.startsWith("/v4/")&&!e.pathname.endsWith("/sw-config.json")),new workbox.strategies.CacheFirst({cacheName:"cdn-v4",plugins:[new workbox.cacheableResponse.CacheableResponsePlugin({statuses:[200]}),new workbox.expiration.ExpirationPlugin({maxAgeSeconds:2592e3,maxEntries:1e3,purgeOnQuotaError:!0}),Y,K]}),"GET"),self.skipWaiting(),self.addEventListener("install",()=>{d({type:"sw_install",version:e})}),self.addEventListener("activate",t=>{d({type:"sw_activate",version:e}),t.waitUntil(y())}),self.addEventListener("message",e=>{var t;e.data&&((e.data.sid||e.data.uuid)&&("string"==typeof(t={sid:e.data.sid,uuid:e.data.uuid}).sid&&t.sid&&(l.sid=t.sid),"string"==typeof t.uuid&&t.uuid&&(l.uuid=t.uuid)),"ping"===e.data.action&&e.source?.postMessage({action:"pong",args:{now:Date.now()}}))});

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.