UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 2.49 kB
import*as i18n from"../../core/i18n/i18n.js";import*as Platform from"../../core/platform/platform.js";import*as Logs from"../../models/logs/logs.js";import*as NetworkForward from"../../panels/network/forward/forward.js";const UIStrings={url:"URL"},str_=i18n.i18n.registerUIStrings("panels/network/NetworkSearchScope.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class NetworkSearchScope{performIndexing(e){queueMicrotask((()=>{e.done()}))}async performSearch(e,t,r,o){const s=[],n=Logs.NetworkLog.NetworkLog.instance().requests().filter((t=>e.filePathMatchesFileQuery(t.url())));t.setTotalWork(n.length);for(const r of n){const o=this.searchRequest(e,r,t);s.push(o)}const a=(await Promise.all(s)).filter((e=>null!==e));if(t.isCanceled())o(!1);else{for(const e of a.sort(((e,t)=>e.label().localeCompare(t.label()))))e.matchesCount()>0&&r(e);t.done(),o(!0)}}async searchRequest(e,t,r){let o=[];if(t.contentType().isTextType()&&(o=await t.searchInContent(e.query(),!e.ignoreCase(),e.isRegex())),r.isCanceled())return null;const s=[];a(t.url())&&s.push(NetworkForward.UIRequestLocation.UIRequestLocation.urlMatch(t));for(const e of t.requestHeaders())n(e)&&s.push(NetworkForward.UIRequestLocation.UIRequestLocation.requestHeaderMatch(t,e));for(const e of t.responseHeaders)n(e)&&s.push(NetworkForward.UIRequestLocation.UIRequestLocation.responseHeaderMatch(t,e));for(const e of o)s.push(NetworkForward.UIRequestLocation.UIRequestLocation.bodyMatch(t,e));return r.incrementWorked(),new NetworkSearchResult(t,s);function n(e){return a(`${e.name}: ${e.value}`)}function a(t){const r=e.ignoreCase()?"i":"",o=e.queries().map((e=>new RegExp(Platform.StringUtilities.escapeForRegExp(e),r)));let s=0;for(const e of o){const r=t.substr(s).match(e);if(!r||void 0===r.index)return!1;s+=r.index+r[0].length}return!0}}stopSearch(){}}export class NetworkSearchResult{request;locations;constructor(e,t){this.request=e,this.locations=t}matchesCount(){return this.locations.length}label(){return this.request.displayName}description(){const e=this.request.parsedURL;return e?e.urlWithoutScheme():this.request.url()}matchLineContent(e){const t=this.locations[e];if(t.isUrlMatch)return this.request.url();const r=t?.header?.header;return r?r.value:t.searchMatch.lineContent}matchRevealable(e){return this.locations[e]}matchLabel(e){const t=this.locations[e];if(t.isUrlMatch)return i18nString(UIStrings.url);const r=t?.header?.header;return r?`${r.name}:`:t.searchMatch.lineNumber+1}}