Skip to content

Commit 746fc81

Browse files
committed
feat: Self-host command
1 parent 728a327 commit 746fc81

File tree

5 files changed

+662
-2
lines changed

5 files changed

+662
-2
lines changed

src/RelayManager.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,6 +1790,52 @@ export class RelayManager extends HasLogging {
17901790
return relay;
17911791
}
17921792

1793+
async createSelfHostedRelay(
1794+
url?: string,
1795+
providerId?: string,
1796+
organizationId?: string,
1797+
): Promise<Relay> {
1798+
if (!this.pb) {
1799+
throw new Error("Not connected to relay service");
1800+
}
1801+
1802+
// Prepare request body - either url for new host or provider for existing
1803+
const requestBody: {
1804+
url?: string;
1805+
provider?: string;
1806+
organization?: string;
1807+
} = {};
1808+
if (providerId) {
1809+
requestBody.provider = providerId;
1810+
} else if (url) {
1811+
requestBody.url = url;
1812+
} else {
1813+
throw new Error("Either URL or provider ID must be provided");
1814+
}
1815+
1816+
// Add organization if provided
1817+
if (organizationId) {
1818+
requestBody.organization = organizationId;
1819+
}
1820+
1821+
// Call the self-host endpoint
1822+
const response = await this.pb.send("/api/collections/relays/self-host", {
1823+
method: "POST",
1824+
headers: {
1825+
"Content-Type": "application/json",
1826+
},
1827+
body: JSON.stringify(requestBody),
1828+
});
1829+
1830+
// Ingest the response into the store
1831+
const relay = this.store?.ingest<Relay>(response);
1832+
if (!relay) {
1833+
throw new Error("Failed to create self-hosted relay");
1834+
}
1835+
1836+
return relay;
1837+
}
1838+
17931839
async updateRelay(relay: Relay): Promise<Relay> {
17941840
if (!this.pb) throw new Error("Failed to update relay");
17951841
const record = await this.pb

src/components/ManageRelay.svelte

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,19 @@
765765
</p>
766766
{/if}
767767
{/await}
768+
{#if relay.provider.publicKey}
769+
<SettingItem
770+
name="Relay Auth Token"
771+
description="Copy this key to your Relay Server's TOML configuration."
772+
>
773+
<SecretText
774+
value={relay.provider.publicKey}
775+
readonly={true}
776+
copyOnClick={true}
777+
successMessage="Public key copied"
778+
/>
779+
</SettingItem>
780+
{/if}
768781
{/if}
769782
{/if}
770783
{/if}

0 commit comments

Comments
 (0)