mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +00:00
Deploy to the gateway that actually serves shakespeare.wtf now
Shakespeare Deploy uploaded a zip to a host that kept the files itself. That host has been replaced: those domains are served out of nsite manifests, so a deploy through the old API has been succeeding and changing nothing anyone can see. This replaces it. NpanelAdapter is NsiteAdapter plus a name. The site is an ordinary nsite under the user's own key — same event, readable by any nsite client, gateway or no gateway — and the second half of the deploy asks the gateway to point a hostname at it. Its predecessor claimed names implicitly, by watching relays and reserving whichever d tag it saw first; this one keeps an explicit row, which is what makes a name something its owner holds rather than something they won a race for. The hostname is asked about before it is claimed, because "nobody holds this", "I already hold this" and "somebody else holds this" are three different acts and creating-then-reading-the-409 cannot tell the last two apart. The name field checks availability as you type, against an endpoint that takes no credentials: somebody choosing a name has not decided to make an account yet. A name this project already deployed to is not reported as taken — it is theirs. An unreachable gateway reports available, because being wrong that way costs a clear error at deploy time, and being wrong the other way tells someone a free name is taken and they settle for worse. Also fixes readDeploySettings, which swallowed a missing file and an unreadable one alike and answered "no providers" to both. The default provider it was meant to hand new users had therefore never reached anybody: it was written, saved back as an empty list on the next render, and gone. The two cases are now distinct, because inventing defaults for a file that exists but will not parse would silently replace whatever the user had. Providers and per-project deploy records saved under the old type are migrated on load rather than dropped. The project file holds one record per provider a project ever deployed to, so rejecting one entry would take a Netlify site id and a Vercel project id with it. Verified end to end against the live gateway: a fresh key self-enrolled, uploaded a blob, published a manifest, claimed a name, and the site served publicly with the SPA fallback working on a deep path. The package-lock version bump is npm reconciling it with package.json, which had drifted before this work.
This commit is contained in:
19 files changed
+1083
-353
No files matched your search
@@ -0,0 +1,225 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { generateSecretKey, getPublicKey } from 'nostr-tools';
|
||||
import type { NostrEvent, NostrSigner } from '@nostrify/nostrify';
|
||||
import { NpanelAdapter, checkNameAvailable } from './NpanelAdapter';
|
||||
import type { JSRuntimeFS } from '../JSRuntime';
|
||||
|
||||
const DASHBOARD_HOST = 'npanel.example.test';
|
||||
const DOMAIN = 'example.test';
|
||||
|
||||
const secretKey = generateSecretKey();
|
||||
const pubkey = getPublicKey(secretKey);
|
||||
|
||||
/**
|
||||
* A signer that fills in the fields a real one would, without signing.
|
||||
*
|
||||
* Not a shortcut around something worth testing: the adapter never verifies a
|
||||
* signature, it base64-encodes whatever it is handed, so what these tests are
|
||||
* about is which tags end up on the event and where it gets sent. Signing for
|
||||
* real is also not available here — jsdom's TextEncoder returns a Uint8Array
|
||||
* from its own realm, which fails the `instanceof` check inside @noble/hashes,
|
||||
* so nostr-tools cannot hash an event under this test environment at all.
|
||||
*/
|
||||
const signer: NostrSigner = {
|
||||
getPublicKey: async () => pubkey,
|
||||
signEvent: async (template) => ({
|
||||
...template,
|
||||
id: 'f'.repeat(64),
|
||||
pubkey,
|
||||
sig: '0'.repeat(128),
|
||||
}),
|
||||
} as NostrSigner;
|
||||
|
||||
/** Requests the adapter made, so a test can assert what it asked the gateway. */
|
||||
interface Call {
|
||||
method: string;
|
||||
path: string;
|
||||
body?: unknown;
|
||||
auth: NostrEvent;
|
||||
}
|
||||
|
||||
let calls: Call[] = [];
|
||||
let fetchMock: ReturnType<typeof vi.fn>;
|
||||
|
||||
/**
|
||||
* An adapter whose nsite half is stubbed out.
|
||||
*
|
||||
* Publishing the site is {@link NsiteAdapter}'s job and is covered where it
|
||||
* lives; what is worth pinning down here is the second half — which requests
|
||||
* the gateway gets, and what happens when it says no.
|
||||
*/
|
||||
function adapterWithStubbedSite(subdomain: string): NpanelAdapter {
|
||||
const adapter = new NpanelAdapter({
|
||||
fs: {} as JSRuntimeFS,
|
||||
nostr: {} as never,
|
||||
signer,
|
||||
dashboardHost: DASHBOARD_HOST,
|
||||
domain: DOMAIN,
|
||||
subdomain,
|
||||
gateway: DOMAIN,
|
||||
relayUrls: [],
|
||||
blossomServers: [],
|
||||
});
|
||||
|
||||
const inner = (adapter as unknown as { nsite: { deploy: unknown } }).nsite;
|
||||
inner.deploy = vi.fn(async () => ({
|
||||
url: `https://base36.${DOMAIN}`,
|
||||
metadata: { canonicalUrl: `https://base36.${DOMAIN}`, filesPublished: 3 },
|
||||
}));
|
||||
|
||||
return adapter;
|
||||
}
|
||||
|
||||
/** Respond to the adapter's requests in the order it makes them. */
|
||||
function respondWith(...responses: Array<{ status: number; body?: unknown }>): void {
|
||||
let index = 0;
|
||||
|
||||
fetchMock.mockImplementation(async (request: Request) => {
|
||||
const header = request.headers.get('Authorization') ?? '';
|
||||
const auth = JSON.parse(atob(header.replace(/^Nostr /, ''))) as NostrEvent;
|
||||
const body = request.body ? await request.clone().json() : undefined;
|
||||
|
||||
calls.push({ method: request.method, path: new URL(request.url).pathname, body, auth });
|
||||
|
||||
const next = responses[index++] ?? { status: 500 };
|
||||
return new Response(next.body === undefined ? null : JSON.stringify(next.body), {
|
||||
status: next.status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
calls = [];
|
||||
fetchMock = vi.fn();
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
describe('NpanelAdapter', () => {
|
||||
it('claims an unused name and returns the hostname it got', async () => {
|
||||
respondWith({ status: 404, body: { error: 'Host not found.' } }, { status: 201, body: { host: {} } });
|
||||
|
||||
const result = await adapterWithStubbedSite('mysite').deploy({
|
||||
projectId: 'p',
|
||||
projectPath: '/projects/p',
|
||||
});
|
||||
|
||||
expect(result.url).toBe(`https://mysite.${DOMAIN}`);
|
||||
expect(calls.map((c) => `${c.method} ${c.path}`)).toEqual([
|
||||
`GET /api/hosts/mysite.${DOMAIN}`,
|
||||
'POST /api/hosts',
|
||||
]);
|
||||
|
||||
// The site is served from a manifest that may not have every path, so the
|
||||
// gateway has to be told to fall back to the shell rather than 404.
|
||||
expect(calls[1].body).toMatchObject({
|
||||
hostname: `mysite.${DOMAIN}`,
|
||||
address: `35128:${pubkey}:mysite`,
|
||||
spa: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('signs each request for the URL it is sent to', async () => {
|
||||
respondWith({ status: 404 }, { status: 201, body: { host: {} } });
|
||||
|
||||
await adapterWithStubbedSite('mysite').deploy({ projectId: 'p', projectPath: '/projects/p' });
|
||||
|
||||
for (const call of calls) {
|
||||
const tag = (name: string) => call.auth.tags.find(([k]) => k === name)?.[1];
|
||||
|
||||
expect(call.auth.kind).toBe(27235);
|
||||
expect(call.auth.pubkey).toBe(pubkey);
|
||||
expect(tag('method')).toBe(call.method);
|
||||
expect(tag('u')).toBe(`https://${DASHBOARD_HOST}${call.path}`);
|
||||
}
|
||||
});
|
||||
|
||||
it('leaves a name alone when it already points at this site', async () => {
|
||||
respondWith({
|
||||
status: 200,
|
||||
body: { host: { address: `35128:${pubkey}:mysite` } },
|
||||
});
|
||||
|
||||
await adapterWithStubbedSite('mysite').deploy({ projectId: 'p', projectPath: '/projects/p' });
|
||||
|
||||
// A redeploy is the common case; it should cost one read and no write.
|
||||
expect(calls).toHaveLength(1);
|
||||
expect(calls[0].method).toBe('GET');
|
||||
});
|
||||
|
||||
it('repoints a name it holds that points somewhere else', async () => {
|
||||
respondWith(
|
||||
{ status: 200, body: { host: { address: '35128:someoneelse:mysite' } } },
|
||||
{ status: 200, body: { host: {} } },
|
||||
);
|
||||
|
||||
await adapterWithStubbedSite('mysite').deploy({ projectId: 'p', projectPath: '/projects/p' });
|
||||
|
||||
expect(calls[1].method).toBe('PATCH');
|
||||
expect(calls[1].body).toEqual({ address: `35128:${pubkey}:mysite` });
|
||||
});
|
||||
|
||||
it('says plainly when a name belongs to someone else', async () => {
|
||||
respondWith({ status: 403, body: { error: "You don't have access to this host." } });
|
||||
|
||||
await expect(
|
||||
adapterWithStubbedSite('taken').deploy({ projectId: 'p', projectPath: '/projects/p' }),
|
||||
).rejects.toThrow(/belongs to someone else/);
|
||||
});
|
||||
|
||||
it('says plainly when a name is claimed between the check and the claim', async () => {
|
||||
respondWith({ status: 404 }, { status: 409, body: { error: 'already configured.' } });
|
||||
|
||||
await expect(
|
||||
adapterWithStubbedSite('racy').deploy({ projectId: 'p', projectPath: '/projects/p' }),
|
||||
).rejects.toThrow(/was just taken/);
|
||||
});
|
||||
|
||||
it("passes on the gateway's own explanation of a refusal", async () => {
|
||||
respondWith(
|
||||
{ status: 404 },
|
||||
{ status: 403, body: { error: 'You already have 25 sites here, which is the limit.' } },
|
||||
);
|
||||
|
||||
await expect(
|
||||
adapterWithStubbedSite('over-quota').deploy({ projectId: 'p', projectPath: '/projects/p' }),
|
||||
).rejects.toThrow(/25 sites here/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkNameAvailable', () => {
|
||||
it('reports what the gateway says', async () => {
|
||||
fetchMock.mockResolvedValue(
|
||||
new Response(JSON.stringify({ hostname: `x.${DOMAIN}`, available: false, reason: 'taken' })),
|
||||
);
|
||||
|
||||
await expect(checkNameAvailable(DASHBOARD_HOST, `x.${DOMAIN}`)).resolves.toMatchObject({
|
||||
available: false,
|
||||
reason: 'taken',
|
||||
});
|
||||
});
|
||||
|
||||
it('asks without credentials', async () => {
|
||||
fetchMock.mockResolvedValue(new Response(JSON.stringify({ hostname: 'x', available: true })));
|
||||
|
||||
await checkNameAvailable(DASHBOARD_HOST, `x.${DOMAIN}`);
|
||||
|
||||
const [url, init] = fetchMock.mock.calls[0];
|
||||
expect(String(url)).toBe(`https://${DASHBOARD_HOST}/api/hosts/x.${DOMAIN}/available`);
|
||||
expect((init as RequestInit | undefined)?.headers).toBeUndefined();
|
||||
});
|
||||
|
||||
it('treats an unreachable gateway as available', async () => {
|
||||
// Being wrong this way costs a clear error at deploy time. Being wrong the
|
||||
// other way tells somebody a free name is taken and they settle for worse.
|
||||
fetchMock.mockRejectedValue(new Error('offline'));
|
||||
|
||||
await expect(checkNameAvailable(DASHBOARD_HOST, `x.${DOMAIN}`)).resolves.toMatchObject({
|
||||
available: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,182 @@
|
||||
import { NIP98 } from '@nostrify/nostrify';
|
||||
import { N64 } from '@nostrify/nostrify/utils';
|
||||
import type { NostrSigner } from '@nostrify/nostrify';
|
||||
import type { DeployAdapter, DeployOptions, DeployResult, NpanelDeployConfig } from './types';
|
||||
import { NsiteAdapter } from './NsiteAdapter';
|
||||
|
||||
/** nsite named-site kind. An npanel host always points at one of these. */
|
||||
const NAMED_SITE_KIND = 35128;
|
||||
|
||||
/** Timeout for a single API call (ms). */
|
||||
const FETCH_TIMEOUT_MS = 15_000;
|
||||
|
||||
/** What `GET /api/hosts/:hostname/available` answers. */
|
||||
export interface NameAvailability {
|
||||
hostname: string;
|
||||
available: boolean;
|
||||
reason?: 'taken' | 'invalid';
|
||||
/** Present when `reason` is `invalid`; written to be shown to whoever typed it. */
|
||||
error?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask whether a name can still be claimed.
|
||||
*
|
||||
* Unauthenticated, and deliberately so: someone choosing a name has not decided
|
||||
* to make an account yet, and making them prove who they are to find out their
|
||||
* first choice is taken would be a strange order to do things in.
|
||||
*
|
||||
* A network failure answers `available: true` rather than blocking the person.
|
||||
* Being wrong that way costs a clear error at deploy time; being wrong the other
|
||||
* way tells someone a free name is taken and they pick a worse one.
|
||||
*/
|
||||
export async function checkNameAvailable(
|
||||
dashboardHost: string,
|
||||
hostname: string,
|
||||
signal?: AbortSignal,
|
||||
): Promise<NameAvailability> {
|
||||
const url = `https://${dashboardHost}/api/hosts/${encodeURIComponent(hostname)}/available`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url, { signal: signal ?? AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
||||
if (!response.ok) return { hostname, available: true };
|
||||
return (await response.json()) as NameAvailability;
|
||||
} catch {
|
||||
return { hostname, available: true };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deploy to an npanel gateway: publish an nsite, then point a hostname at it.
|
||||
*
|
||||
* The site itself is an ordinary nsite published under the user's own key — this
|
||||
* adapter delegates all of that to {@link NsiteAdapter} rather than reimplementing
|
||||
* it, so a site deployed here is the same site, readable by any nsite client,
|
||||
* with or without this gateway.
|
||||
*
|
||||
* What npanel adds is the name. Its predecessor claimed one implicitly, by
|
||||
* watching relays for a manifest and reserving whatever `d` tag it saw first;
|
||||
* npanel instead keeps an explicit hostname → nsite row, which is what makes a
|
||||
* name something its owner holds rather than something they won a race for.
|
||||
* That row has to be asked for, which is the second half of this deploy.
|
||||
*/
|
||||
export class NpanelAdapter implements DeployAdapter {
|
||||
private readonly nsite: NsiteAdapter;
|
||||
private readonly signer: NostrSigner;
|
||||
private readonly dashboardHost: string;
|
||||
private readonly hostname: string;
|
||||
private readonly subdomain: string;
|
||||
|
||||
constructor(config: NpanelDeployConfig) {
|
||||
this.signer = config.signer;
|
||||
this.dashboardHost = config.dashboardHost;
|
||||
this.subdomain = config.subdomain;
|
||||
this.hostname = `${config.subdomain}.${config.domain}`;
|
||||
|
||||
// The identifier is the subdomain, so a site's name and its address agree
|
||||
// and a second gateway asked to serve it lands on the same name.
|
||||
this.nsite = new NsiteAdapter({ ...config, siteIdentifier: config.subdomain });
|
||||
}
|
||||
|
||||
async deploy(options: DeployOptions): Promise<DeployResult> {
|
||||
const result = await this.nsite.deploy(options);
|
||||
|
||||
const pubkey = await this.signer.getPublicKey();
|
||||
const address = `${NAMED_SITE_KIND}:${pubkey}:${this.subdomain}`;
|
||||
|
||||
await this.bindHostname(address);
|
||||
|
||||
return {
|
||||
url: `https://${this.hostname}`,
|
||||
metadata: {
|
||||
...result.metadata,
|
||||
provider: 'npanel',
|
||||
hostname: this.hostname,
|
||||
address,
|
||||
/** The URL any nsite gateway serves this at, gateway or no gateway. */
|
||||
canonicalUrl: result.metadata?.canonicalUrl ?? result.url,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Point {@link hostname} at `address`, whether or not it already exists.
|
||||
*
|
||||
* Asked about before being claimed, because the three outcomes are different
|
||||
* acts: a name nobody holds is created, a name this user already holds is
|
||||
* repointed — that is what a redeploy under a new key or a renamed site looks
|
||||
* like — and a name somebody else holds is refused. Creating first and reading
|
||||
* the 409 could not tell the last two apart.
|
||||
*/
|
||||
private async bindHostname(address: string): Promise<void> {
|
||||
const existing = await this.request('GET', `/api/hosts/${encodeURIComponent(this.hostname)}`);
|
||||
|
||||
if (existing.status === 200) {
|
||||
const { host } = (await existing.json()) as { host: { address: string } };
|
||||
if (host.address === address) return;
|
||||
|
||||
const patched = await this.request(
|
||||
'PATCH',
|
||||
`/api/hosts/${encodeURIComponent(this.hostname)}`,
|
||||
{ address },
|
||||
);
|
||||
if (!patched.ok) throw await this.error(patched, `Could not update ${this.hostname}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (existing.status === 403) {
|
||||
throw new Error(
|
||||
`${this.hostname} belongs to someone else. Choose a different name for this site.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (existing.status !== 404) {
|
||||
throw await this.error(existing, `Could not check whether ${this.hostname} is free`);
|
||||
}
|
||||
|
||||
const created = await this.request('POST', '/api/hosts', { hostname: this.hostname, address, spa: true });
|
||||
if (created.ok) return;
|
||||
|
||||
// Between the check and the claim, somebody else took it.
|
||||
if (created.status === 409) {
|
||||
throw new Error(`${this.hostname} was just taken. Choose a different name for this site.`);
|
||||
}
|
||||
|
||||
throw await this.error(created, `Could not claim ${this.hostname}`);
|
||||
}
|
||||
|
||||
/** A NIP-98 request to the gateway's API. */
|
||||
private async request(method: string, path: string, body?: unknown): Promise<Response> {
|
||||
const url = `https://${this.dashboardHost}${path}`;
|
||||
|
||||
let request = new Request(url, {
|
||||
method,
|
||||
...(body === undefined
|
||||
? {}
|
||||
: { body: JSON.stringify(body), headers: { 'Content-Type': 'application/json' } }),
|
||||
});
|
||||
|
||||
// Signed against the URL being requested, so the token authorizes this call
|
||||
// and no other. No CORS proxy: npanel answers browsers directly, and a proxy
|
||||
// would rewrite the URL out from under the signature.
|
||||
const template = await NIP98.template(request);
|
||||
const event = await this.signer.signEvent(template);
|
||||
|
||||
const headers = new Headers(request.headers);
|
||||
headers.set('Authorization', `Nostr ${N64.encodeEvent(event)}`);
|
||||
request = new Request(request, { headers, signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
||||
|
||||
return await fetch(request);
|
||||
}
|
||||
|
||||
/** The gateway's own sentence about a failure, which is written to be read. */
|
||||
private async error(response: Response, fallback: string): Promise<Error> {
|
||||
const body = await response.json().catch(() => null) as { error?: string } | null;
|
||||
|
||||
if (response.status === 403 && !body?.error) {
|
||||
return new Error(`${fallback}: this gateway is not accepting new sites right now.`);
|
||||
}
|
||||
|
||||
return new Error(body?.error ?? `${fallback} (HTTP ${response.status}).`);
|
||||
}
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
import JSZip from 'jszip';
|
||||
import { NIP98 } from '@nostrify/nostrify';
|
||||
import { N64 } from '@nostrify/nostrify/utils';
|
||||
import type { JSRuntimeFS } from '../JSRuntime';
|
||||
import type { DeployAdapter, DeployOptions, DeployResult, ShakespeareDeployConfig } from './types';
|
||||
import { proxyUrl } from '../proxyUrl';
|
||||
|
||||
/**
|
||||
* Shakespeare Deploy Adapter
|
||||
* Uses NIP-98 authentication with Nostr signer
|
||||
*/
|
||||
export class ShakespeareAdapter implements DeployAdapter {
|
||||
private fs: JSRuntimeFS;
|
||||
private signer: ShakespeareDeployConfig['signer'];
|
||||
private host: string;
|
||||
private subdomain?: string;
|
||||
private corsProxy?: string;
|
||||
|
||||
constructor(config: ShakespeareDeployConfig) {
|
||||
this.fs = config.fs;
|
||||
this.signer = config.signer;
|
||||
this.host = config.host || 'shakespeare.wtf';
|
||||
this.subdomain = config.subdomain;
|
||||
this.corsProxy = config.corsProxy;
|
||||
}
|
||||
|
||||
async deploy(options: DeployOptions): Promise<DeployResult> {
|
||||
const { projectId, projectPath } = options;
|
||||
|
||||
// Use custom subdomain if provided, otherwise construct from projectId
|
||||
const hostname = this.subdomain
|
||||
? `${this.subdomain}.${this.host}`
|
||||
: `${projectId}.${this.host}`;
|
||||
const deployUrl = `https://${this.host}/deploy`;
|
||||
const siteUrl = `https://${hostname}`;
|
||||
|
||||
// Check if dist directory exists and contains index.html
|
||||
const distPath = `${projectPath}/dist`;
|
||||
try {
|
||||
await this.fs.readFile(`${distPath}/index.html`, 'utf8');
|
||||
} catch {
|
||||
throw new Error('No index.html found in dist directory. Please build the project first.');
|
||||
}
|
||||
|
||||
// Create ZIP of dist directory
|
||||
const zip = new JSZip();
|
||||
await this.addDirectoryToZip(distPath, zip);
|
||||
|
||||
// Generate ZIP blob
|
||||
const zipBlob = await zip.generateAsync({ type: 'blob' });
|
||||
|
||||
// Create FormData
|
||||
const formData = new FormData();
|
||||
formData.append('hostname', hostname);
|
||||
formData.append('file', zipBlob, `${projectId}.zip`);
|
||||
|
||||
// Create the request
|
||||
let request = new Request(deployUrl, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
|
||||
// Create NIP-98 token for authentication
|
||||
const template = await NIP98.template(request);
|
||||
const event = await this.signer.signEvent(template);
|
||||
const token = N64.encodeEvent(event);
|
||||
|
||||
// Add the Authorization header
|
||||
const headers = new Headers(request.headers);
|
||||
headers.set('Authorization', `Nostr ${token}`);
|
||||
request = new Request(request, { headers });
|
||||
|
||||
// Apply proxy if configured
|
||||
if (this.corsProxy) {
|
||||
request = new Request(proxyUrl({ template: this.corsProxy, url: request.url }), request);
|
||||
}
|
||||
|
||||
// Deploy
|
||||
const response = await fetch(request);
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text().catch(() => 'Unknown error');
|
||||
throw new Error(`Deployment failed: ${response.status} ${response.statusText}. ${errorText}`);
|
||||
}
|
||||
|
||||
return {
|
||||
url: siteUrl,
|
||||
metadata: {
|
||||
hostname,
|
||||
provider: 'shakespeare',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private async addDirectoryToZip(dirPath: string, zip: JSZip): Promise<void> {
|
||||
try {
|
||||
const entries = await this.fs.readdir(dirPath, { withFileTypes: true });
|
||||
|
||||
for (const entry of entries) {
|
||||
const fullPath = `${dirPath}/${entry.name}`;
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
// Create folder in zip and recursively add its contents
|
||||
const folder = zip.folder(entry.name);
|
||||
if (folder) {
|
||||
await this.addDirectoryToZip(fullPath, folder);
|
||||
}
|
||||
} else if (entry.isFile()) {
|
||||
// Add file to zip
|
||||
try {
|
||||
const fileContent = await this.fs.readFile(fullPath);
|
||||
zip.file(entry.name, fileContent);
|
||||
} catch {
|
||||
console.warn(`Failed to read file ${fullPath}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
console.warn(`Failed to read directory ${dirPath}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
export * from './types';
|
||||
export * from './ShakespeareAdapter';
|
||||
export * from './NpanelAdapter';
|
||||
export * from './NetlifyAdapter';
|
||||
export * from './VercelAdapter';
|
||||
export * from './NsiteAdapter';
|
||||
|
||||
+21
-9
@@ -20,14 +20,6 @@ export interface DeployAdapter {
|
||||
deploy(options: DeployOptions): Promise<DeployResult>;
|
||||
}
|
||||
|
||||
export interface ShakespeareDeployConfig {
|
||||
fs: JSRuntimeFS;
|
||||
signer: NostrSigner;
|
||||
host?: string;
|
||||
subdomain?: string;
|
||||
corsProxy?: string;
|
||||
}
|
||||
|
||||
export interface NetlifyDeployConfig {
|
||||
fs: JSRuntimeFS;
|
||||
apiKey: string;
|
||||
@@ -68,6 +60,26 @@ export interface NsiteDeployConfig {
|
||||
siteIdentifier?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A gateway that serves an nsite under a name it holds for you.
|
||||
*
|
||||
* `siteIdentifier` is not configurable: the gateway's hostname and the site's
|
||||
* `d` tag are the same label, so that a second gateway asked to serve the site
|
||||
* lands on the same name.
|
||||
*/
|
||||
export interface NpanelDeployConfig extends Omit<NsiteDeployConfig, 'siteIdentifier'> {
|
||||
/**
|
||||
* The gateway's dashboard hostname, which is also its API origin — the `u`
|
||||
* tag of every NIP-98 request has to name it, so it is not interchangeable
|
||||
* with the domain sites are served under.
|
||||
*/
|
||||
dashboardHost: string;
|
||||
/** The domain the site is served under, e.g. `shakespeare.wtf`. */
|
||||
domain: string;
|
||||
/** The single label in front of {@link domain}, and the site's `d` tag. */
|
||||
subdomain: string;
|
||||
}
|
||||
|
||||
export interface CloudflareDeployConfig {
|
||||
fs: JSRuntimeFS;
|
||||
apiKey: string;
|
||||
@@ -103,7 +115,7 @@ export interface RailwayDeployConfig {
|
||||
|
||||
export interface PresetDeployProvider {
|
||||
id: string;
|
||||
type: 'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare' | 'deno' | 'railway';
|
||||
type: 'npanel' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare' | 'deno' | 'railway';
|
||||
name: string;
|
||||
description: string;
|
||||
baseURL?: string;
|
||||
|
||||
Reference in new issue
Block a user