style: cleanup and fix imports
This commit is contained in:
parent
bb6bf3128e
commit
2e7fdef740
|
@ -4,7 +4,7 @@ import {
|
||||||
OnBeforeSendHeadersDetailsType,
|
OnBeforeSendHeadersDetailsType,
|
||||||
OnHeadersReceivedDetailsType,
|
OnHeadersReceivedDetailsType,
|
||||||
OnRequestDetailsType,
|
OnRequestDetailsType,
|
||||||
} from "../types";
|
} from "../types.js";
|
||||||
import WebEngine from "../webEngine.js";
|
import WebEngine from "../webEngine.js";
|
||||||
import { getTld, isDomain, isIp, normalizeDomain } from "../util.js";
|
import { getTld, isDomain, isIp, normalizeDomain } from "../util.js";
|
||||||
import tldEnum from "@lumeweb/tld-enum";
|
import tldEnum from "@lumeweb/tld-enum";
|
||||||
|
@ -18,19 +18,19 @@ export default abstract class BaseProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
async shouldHandleRequest(
|
async shouldHandleRequest(
|
||||||
details: OnBeforeRequestDetailsType
|
details: OnBeforeRequestDetailsType,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleRequest(
|
async handleRequest(
|
||||||
details: OnBeforeRequestDetailsType
|
details: OnBeforeRequestDetailsType,
|
||||||
): Promise<BlockingResponse | boolean> {
|
): Promise<BlockingResponse | boolean> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleReqHeaders(
|
async handleReqHeaders(
|
||||||
details: OnBeforeSendHeadersDetailsType
|
details: OnBeforeSendHeadersDetailsType,
|
||||||
): Promise<BlockingResponse | boolean> {
|
): Promise<BlockingResponse | boolean> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -40,14 +40,14 @@ export default abstract class BaseProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleHeaders(
|
async handleHeaders(
|
||||||
details: OnHeadersReceivedDetailsType
|
details: OnHeadersReceivedDetailsType,
|
||||||
): Promise<BlockingResponse | boolean> {
|
): Promise<BlockingResponse | boolean> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async resolveDns(
|
protected async resolveDns(
|
||||||
details: OnBeforeRequestDetailsType,
|
details: OnBeforeRequestDetailsType,
|
||||||
recordTypes?: string[]
|
recordTypes?: string[],
|
||||||
) {
|
) {
|
||||||
const originalUrl = new URL(details.url);
|
const originalUrl = new URL(details.url);
|
||||||
const hostname = normalizeDomain(originalUrl.hostname);
|
const hostname = normalizeDomain(originalUrl.hostname);
|
||||||
|
@ -74,7 +74,7 @@ export default abstract class BaseProvider {
|
||||||
protected setData(
|
protected setData(
|
||||||
details: OnBeforeRequestDetailsType,
|
details: OnBeforeRequestDetailsType,
|
||||||
key: string,
|
key: string,
|
||||||
value: any
|
value: any,
|
||||||
) {
|
) {
|
||||||
return this.engine.setRequestData(details.requestId, key, value);
|
return this.engine.setRequestData(details.requestId, key, value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,18 +24,18 @@ export default class IpfsProvider extends BaseProvider {
|
||||||
private _client = createClient();
|
private _client = createClient();
|
||||||
|
|
||||||
async shouldHandleRequest(
|
async shouldHandleRequest(
|
||||||
details: OnBeforeRequestDetailsType
|
details: OnBeforeRequestDetailsType,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
let dnsResult: DNSResult | boolean | string = await this.resolveDns(
|
let dnsResult: DNSResult | boolean | string = await this.resolveDns(
|
||||||
details,
|
details,
|
||||||
[DNS_RECORD_TYPE.CONTENT, DNS_RECORD_TYPE.TEXT]
|
[DNS_RECORD_TYPE.CONTENT, DNS_RECORD_TYPE.TEXT],
|
||||||
);
|
);
|
||||||
if (!dnsResult) {
|
if (!dnsResult) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let contentRecords = (dnsResult as DNSResult).records.map(
|
let contentRecords = (dnsResult as DNSResult).records.map(
|
||||||
(item: { value: string }) =>
|
(item: { value: string }) =>
|
||||||
"/" + item.value.replace("://", "/").replace(/^\+/, "/")
|
"/" + item.value.replace("://", "/").replace(/^\+/, "/"),
|
||||||
);
|
);
|
||||||
|
|
||||||
contentRecords = contentRecords.filter((item) => checkPath(item));
|
contentRecords = contentRecords.filter((item) => checkPath(item));
|
||||||
|
@ -53,7 +53,7 @@ export default class IpfsProvider extends BaseProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleReqHeaders(
|
async handleReqHeaders(
|
||||||
details: OnBeforeSendHeadersDetailsType
|
details: OnBeforeSendHeadersDetailsType,
|
||||||
): Promise<BlockingResponse | boolean> {
|
): Promise<BlockingResponse | boolean> {
|
||||||
return {
|
return {
|
||||||
requestHeaders: [
|
requestHeaders: [
|
||||||
|
@ -63,7 +63,7 @@ export default class IpfsProvider extends BaseProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleRequest(
|
async handleRequest(
|
||||||
details: OnBeforeRequestDetailsType
|
details: OnBeforeRequestDetailsType,
|
||||||
): Promise<BlockingResponse | boolean> {
|
): Promise<BlockingResponse | boolean> {
|
||||||
let urlObj = new URL(details.url);
|
let urlObj = new URL(details.url);
|
||||||
let urlPath = urlObj.pathname;
|
let urlPath = urlObj.pathname;
|
||||||
|
@ -130,7 +130,7 @@ export default class IpfsProvider extends BaseProvider {
|
||||||
|
|
||||||
let bufferRead = 0;
|
let bufferRead = 0;
|
||||||
const fileTypeBufferLength = 4100;
|
const fileTypeBufferLength = 4100;
|
||||||
const mimeBuffer = [];
|
const mimeBuffer: Uint8Array[] = [];
|
||||||
|
|
||||||
for await (const chunk of reader.iterable()) {
|
for await (const chunk of reader.iterable()) {
|
||||||
if (bufferRead < fileTypeBufferLength) {
|
if (bufferRead < fileTypeBufferLength) {
|
||||||
|
@ -156,7 +156,7 @@ export default class IpfsProvider extends BaseProvider {
|
||||||
const mime = await fileTypeFromBuffer(
|
const mime = await fileTypeFromBuffer(
|
||||||
mimeBuffer.reduce((acc, val) => {
|
mimeBuffer.reduce((acc, val) => {
|
||||||
return new Uint8Array([...acc, ...val]);
|
return new Uint8Array([...acc, ...val]);
|
||||||
}, new Uint8Array())
|
}, new Uint8Array()),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (mime) {
|
if (mime) {
|
||||||
|
@ -194,9 +194,9 @@ export default class IpfsProvider extends BaseProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleHeaders(
|
async handleHeaders(
|
||||||
details: OnHeadersReceivedDetailsType
|
details: OnHeadersReceivedDetailsType,
|
||||||
): Promise<BlockingResponse | boolean> {
|
): Promise<BlockingResponse | boolean> {
|
||||||
let headers = [];
|
let headers: any = [];
|
||||||
headers.push({
|
headers.push({
|
||||||
name: "Content-Type",
|
name: "Content-Type",
|
||||||
value: this.getData(details, "contentType"),
|
value: this.getData(details, "contentType"),
|
||||||
|
|
|
@ -6,15 +6,15 @@ import { init } from "@lumeweb/libkernel/kernel";
|
||||||
import IpfsProvider from "../contentProviders/ipfsProvider.js";
|
import IpfsProvider from "../contentProviders/ipfsProvider.js";
|
||||||
import {
|
import {
|
||||||
addQuery,
|
addQuery,
|
||||||
getAuthStatusResolve,
|
|
||||||
getBlockForBootloader,
|
|
||||||
getBlockForBridge,
|
|
||||||
getBridgeLoadedResolve,
|
|
||||||
clearOpenPorts,
|
clearOpenPorts,
|
||||||
deleteOpenPort,
|
deleteOpenPort,
|
||||||
deleteQuery,
|
deleteQuery,
|
||||||
getAuthStatus,
|
getAuthStatus,
|
||||||
getAuthStatusKnown,
|
getAuthStatusKnown,
|
||||||
|
getAuthStatusResolve,
|
||||||
|
getBlockForBootloader,
|
||||||
|
getBlockForBridge,
|
||||||
|
getBridgeLoadedResolve,
|
||||||
getKernelIframe,
|
getKernelIframe,
|
||||||
getOpenPorts,
|
getOpenPorts,
|
||||||
getPortsNonce,
|
getPortsNonce,
|
||||||
|
@ -29,18 +29,10 @@ import {
|
||||||
setKernelIframe,
|
setKernelIframe,
|
||||||
setOpenPort,
|
setOpenPort,
|
||||||
setTimer,
|
setTimer,
|
||||||
getDnsSetupDefer,
|
weAreBooted,
|
||||||
} from "./vars.js";
|
} from "./vars.js";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import browser from "@lumeweb/webextension-polyfill";
|
import browser from "@lumeweb/webextension-polyfill";
|
||||||
import setupContextMenus from "../contextMenu.js";
|
|
||||||
import { callModule } from "libkernel";
|
|
||||||
import {
|
|
||||||
dnsClient,
|
|
||||||
ipfsClient,
|
|
||||||
peerDiscoveryClient,
|
|
||||||
swarmClient,
|
|
||||||
} from "../clients.js";
|
|
||||||
|
|
||||||
function logLargeObjects() {
|
function logLargeObjects() {
|
||||||
let queriesLen = Object.keys(getQueries()).length;
|
let queriesLen = Object.keys(getQueries()).length;
|
||||||
|
@ -71,11 +63,11 @@ export function queryKernel(query: any): Promise<any> {
|
||||||
if (getKernelIframe().contentWindow !== null) {
|
if (getKernelIframe().contentWindow !== null) {
|
||||||
(getKernelIframe() as any).contentWindow.postMessage(
|
(getKernelIframe() as any).contentWindow.postMessage(
|
||||||
query,
|
query,
|
||||||
"http://kernel.lume"
|
"http://kernel.lume",
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
console.error(
|
console.error(
|
||||||
"kernelFrame.contentWindow was null, cannot send message!"
|
"kernelFrame.contentWindow was null, cannot send message!",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -157,7 +149,7 @@ function handleBridgeMessage(
|
||||||
port: any,
|
port: any,
|
||||||
portNonce: number,
|
portNonce: number,
|
||||||
data: any,
|
data: any,
|
||||||
domain: string
|
domain: string,
|
||||||
) {
|
) {
|
||||||
if (data.method === "bridgeLoaded") {
|
if (data.method === "bridgeLoaded") {
|
||||||
getBridgeLoadedResolve()();
|
getBridgeLoadedResolve()();
|
||||||
|
|
Reference in New Issue