chore: Add something

This commit is contained in:
BluJ
2023-04-14 09:16:59 -06:00
parent 556b1b03f1
commit df6f0c6efb
7 changed files with 30 additions and 16 deletions

View File

@@ -1,11 +1,11 @@
import { Origin } from "./Origin";
export class LocalBinding {
constructor(readonly localAddress: string, readonly ipAddress: string) {}
constructor(readonly localHost: string, readonly ipHost: string) {}
createOrigins(protocol: string) {
return {
local: new Origin(protocol, this.localAddress),
ip: new Origin(protocol, this.ipAddress),
local: new Origin(protocol, this.localHost),
ip: new Origin(protocol, this.ipHost),
};
}
}

View File

@@ -18,11 +18,8 @@ export class NetworkInterfaceBuilder {
async exportAddresses(addresses: Iterable<Origin>) {
const { name, description, id, ui, path, search } = this.options;
// prettier-ignore
const urlAuth = !!(this.options?.basic) ? `${this.options.basic.username}:${this.options.basic.password}@` :
'';
for (const origin of addresses) {
const address = `${origin.protocol}://${urlAuth}${origin.address}`;
const address = origin.withAuth(this.options.basic);
await this.options.effects.exportAddress({
name,
description,

View File

@@ -1,3 +1,18 @@
export class Origin {
constructor(readonly protocol: string, readonly address: string) {}
constructor(readonly protocol: string, readonly host: string) {}
withAuth(
origin?:
| {
password: string;
username: string;
}
| null
| undefined
) {
// prettier-ignore
const urlAuth = !!(origin) ? `${origin.username}:${origin.password}@` :
'';
return `${this.protocol}://${urlAuth}${this.host}`;
}
}

View File

@@ -1,8 +1,8 @@
import { Origin } from "./Origin";
export class TorBinding {
constructor(readonly address: string) {}
constructor(readonly host: string) {}
createOrigin(protocol: string) {
return new Origin(protocol, this.address);
return new Origin(protocol, this.host);
}
}

View File

@@ -20,8 +20,10 @@ export type UnionToIntersection<T> = ((x: T) => any) extends (x: infer R) => any
export function setupPropertiesExport(
fn: (
...args: Parameters<ExpectedExports.properties>
) => Promise<Properties<PackagePropertiesV2>>
) => Promise<void> | void | Promise<Properties<PackagePropertiesV2>>
): ExpectedExports.properties {
return (...args: Parameters<ExpectedExports.properties>) =>
fn(...args).then((x) => x.build());
return async (...args: Parameters<ExpectedExports.properties>) => {
const value = await fn(...args);
if (value) return value.build();
};
}