style: cleanup and fix imports

This commit is contained in:
Derrick Hammer 2023-07-17 10:42:35 -04:00
parent bb6bf3128e
commit 2e7fdef740
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 24 additions and 32 deletions

View File

@ -4,7 +4,7 @@ import {
OnBeforeSendHeadersDetailsType,
OnHeadersReceivedDetailsType,
OnRequestDetailsType,
} from "../types";
} from "../types.js";
import WebEngine from "../webEngine.js";
import { getTld, isDomain, isIp, normalizeDomain } from "../util.js";
import tldEnum from "@lumeweb/tld-enum";
@ -18,19 +18,19 @@ export default abstract class BaseProvider {
}
async shouldHandleRequest(
details: OnBeforeRequestDetailsType
details: OnBeforeRequestDetailsType,
): Promise<boolean> {
return false;
}
async handleRequest(
details: OnBeforeRequestDetailsType
details: OnBeforeRequestDetailsType,
): Promise<BlockingResponse | boolean> {
return false;
}
async handleReqHeaders(
details: OnBeforeSendHeadersDetailsType
details: OnBeforeSendHeadersDetailsType,
): Promise<BlockingResponse | boolean> {
return false;
}
@ -40,14 +40,14 @@ export default abstract class BaseProvider {
}
async handleHeaders(
details: OnHeadersReceivedDetailsType
details: OnHeadersReceivedDetailsType,
): Promise<BlockingResponse | boolean> {
return false;
}
protected async resolveDns(
details: OnBeforeRequestDetailsType,
recordTypes?: string[]
recordTypes?: string[],
) {
const originalUrl = new URL(details.url);
const hostname = normalizeDomain(originalUrl.hostname);
@ -74,7 +74,7 @@ export default abstract class BaseProvider {
protected setData(
details: OnBeforeRequestDetailsType,
key: string,
value: any
value: any,
) {
return this.engine.setRequestData(details.requestId, key, value);
}

View File

@ -24,18 +24,18 @@ export default class IpfsProvider extends BaseProvider {
private _client = createClient();
async shouldHandleRequest(
details: OnBeforeRequestDetailsType
details: OnBeforeRequestDetailsType,
): Promise<boolean> {
let dnsResult: DNSResult | boolean | string = await this.resolveDns(
details,
[DNS_RECORD_TYPE.CONTENT, DNS_RECORD_TYPE.TEXT]
[DNS_RECORD_TYPE.CONTENT, DNS_RECORD_TYPE.TEXT],
);
if (!dnsResult) {
return false;
}
let contentRecords = (dnsResult as DNSResult).records.map(
(item: { value: string }) =>
"/" + item.value.replace("://", "/").replace(/^\+/, "/")
"/" + item.value.replace("://", "/").replace(/^\+/, "/"),
);
contentRecords = contentRecords.filter((item) => checkPath(item));
@ -53,7 +53,7 @@ export default class IpfsProvider extends BaseProvider {
}
async handleReqHeaders(
details: OnBeforeSendHeadersDetailsType
details: OnBeforeSendHeadersDetailsType,
): Promise<BlockingResponse | boolean> {
return {
requestHeaders: [
@ -63,7 +63,7 @@ export default class IpfsProvider extends BaseProvider {
}
async handleRequest(
details: OnBeforeRequestDetailsType
details: OnBeforeRequestDetailsType,
): Promise<BlockingResponse | boolean> {
let urlObj = new URL(details.url);
let urlPath = urlObj.pathname;
@ -130,7 +130,7 @@ export default class IpfsProvider extends BaseProvider {
let bufferRead = 0;
const fileTypeBufferLength = 4100;
const mimeBuffer = [];
const mimeBuffer: Uint8Array[] = [];
for await (const chunk of reader.iterable()) {
if (bufferRead < fileTypeBufferLength) {
@ -156,7 +156,7 @@ export default class IpfsProvider extends BaseProvider {
const mime = await fileTypeFromBuffer(
mimeBuffer.reduce((acc, val) => {
return new Uint8Array([...acc, ...val]);
}, new Uint8Array())
}, new Uint8Array()),
);
if (mime) {
@ -194,9 +194,9 @@ export default class IpfsProvider extends BaseProvider {
}
async handleHeaders(
details: OnHeadersReceivedDetailsType
details: OnHeadersReceivedDetailsType,
): Promise<BlockingResponse | boolean> {
let headers = [];
let headers: any = [];
headers.push({
name: "Content-Type",
value: this.getData(details, "contentType"),

View File

@ -6,15 +6,15 @@ import { init } from "@lumeweb/libkernel/kernel";
import IpfsProvider from "../contentProviders/ipfsProvider.js";
import {
addQuery,
getAuthStatusResolve,
getBlockForBootloader,
getBlockForBridge,
getBridgeLoadedResolve,
clearOpenPorts,
deleteOpenPort,
deleteQuery,
getAuthStatus,
getAuthStatusKnown,
getAuthStatusResolve,
getBlockForBootloader,
getBlockForBridge,
getBridgeLoadedResolve,
getKernelIframe,
getOpenPorts,
getPortsNonce,
@ -29,18 +29,10 @@ import {
setKernelIframe,
setOpenPort,
setTimer,
getDnsSetupDefer,
weAreBooted,
} from "./vars.js";
// @ts-ignore
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() {
let queriesLen = Object.keys(getQueries()).length;
@ -71,11 +63,11 @@ export function queryKernel(query: any): Promise<any> {
if (getKernelIframe().contentWindow !== null) {
(getKernelIframe() as any).contentWindow.postMessage(
query,
"http://kernel.lume"
"http://kernel.lume",
);
} else {
console.error(
"kernelFrame.contentWindow was null, cannot send message!"
"kernelFrame.contentWindow was null, cannot send message!",
);
}
});
@ -157,7 +149,7 @@ function handleBridgeMessage(
port: any,
portNonce: number,
data: any,
domain: string
domain: string,
) {
if (data.method === "bridgeLoaded") {
getBridgeLoadedResolve()();