mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-03 16:03:34 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc98f0e181 | ||
|
|
27dec36a3f |
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Rocket, ExternalLink, AlertCircle } from 'lucide-react';
|
||||
import { Rocket, ExternalLink, AlertCircle, Settings, Cloud } from 'lucide-react';
|
||||
import { ExternalFavicon } from '@/components/ExternalFavicon';
|
||||
import {
|
||||
Dialog,
|
||||
@@ -562,19 +562,42 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
{settings.providers.length === 0 ? (
|
||||
<Alert>
|
||||
<AlertCircle className="h-4 w-4" />
|
||||
<AlertDescription>
|
||||
No deployment providers configured.{' '}
|
||||
<Link
|
||||
to="/settings/deploy"
|
||||
className="underline hover:no-underline"
|
||||
onClick={handleClose}
|
||||
>
|
||||
Configure deployment settings
|
||||
</Link>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
<div className="py-8 px-4">
|
||||
<div className="max-w-md mx-auto space-y-6 text-center">
|
||||
{/* Icon */}
|
||||
<div className="flex justify-center">
|
||||
<div className="relative">
|
||||
<div className="absolute inset-0 bg-primary/10 rounded-full blur-xl"></div>
|
||||
<div className="relative bg-gradient-to-br from-primary/20 to-primary/5 p-6 rounded-2xl border border-primary/20">
|
||||
<Cloud className="h-12 w-12 text-primary" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Heading */}
|
||||
<div className="space-y-2">
|
||||
<h3 className="text-xl font-semibold">Choose Your Deployment Platform</h3>
|
||||
<p className="text-sm text-muted-foreground leading-relaxed">
|
||||
Deploy your Shakespeare projects to any hosting provider. Configure your preferred platform to get started.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* CTA */}
|
||||
<div className="pt-2">
|
||||
<Button
|
||||
asChild
|
||||
size="lg"
|
||||
className="w-full"
|
||||
onClick={handleClose}
|
||||
>
|
||||
<Link to="/settings/deploy">
|
||||
<Settings className="h-4 w-4 mr-2" />
|
||||
Configure Deployment Provider
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="space-y-2">
|
||||
|
||||
@@ -33,7 +33,6 @@ import { Terminal as TerminalComponent } from '@/components/Terminal';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
import { isMediaFile } from '@/lib/fileUtils';
|
||||
import { injectNostrShim, getNostrShimCode, NOSTR_SHIM_PATH } from '@/lib/nostrShim';
|
||||
|
||||
interface PreviewPaneProps {
|
||||
projectId: string;
|
||||
@@ -320,104 +319,6 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
||||
}
|
||||
}, [historyIndex, navigationHistory, sendNavigationCommand]);
|
||||
|
||||
// Handle nostr.* requests from iframe (NIP-07 proxy)
|
||||
const handleNostrRequest = useCallback(async (message: {
|
||||
jsonrpc: '2.0';
|
||||
method: string;
|
||||
params: Record<string, unknown>;
|
||||
id: number;
|
||||
}) => {
|
||||
const { method, params, id } = message;
|
||||
const nostrMethod = method.replace('nostr.', '');
|
||||
|
||||
try {
|
||||
// Check if window.nostr is available in the parent
|
||||
if (!window.nostr) {
|
||||
throw new Error('Nostr extension not found. Please install a NIP-07 browser extension.');
|
||||
}
|
||||
|
||||
let result: unknown;
|
||||
|
||||
switch (nostrMethod) {
|
||||
case 'getPublicKey':
|
||||
result = await window.nostr.getPublicKey();
|
||||
break;
|
||||
|
||||
case 'signEvent':
|
||||
result = await window.nostr.signEvent(params.event as Parameters<typeof window.nostr.signEvent>[0]);
|
||||
break;
|
||||
|
||||
case 'getRelays':
|
||||
if (window.nostr.getRelays) {
|
||||
result = await window.nostr.getRelays();
|
||||
} else {
|
||||
result = {};
|
||||
}
|
||||
break;
|
||||
|
||||
case 'nip04.encrypt':
|
||||
if (!window.nostr.nip04) {
|
||||
throw new Error('NIP-04 encryption not supported by this extension');
|
||||
}
|
||||
result = await window.nostr.nip04.encrypt(
|
||||
params.pubkey as string,
|
||||
params.plaintext as string
|
||||
);
|
||||
break;
|
||||
|
||||
case 'nip04.decrypt':
|
||||
if (!window.nostr.nip04) {
|
||||
throw new Error('NIP-04 decryption not supported by this extension');
|
||||
}
|
||||
result = await window.nostr.nip04.decrypt(
|
||||
params.pubkey as string,
|
||||
params.ciphertext as string
|
||||
);
|
||||
break;
|
||||
|
||||
case 'nip44.encrypt':
|
||||
if (!window.nostr.nip44) {
|
||||
throw new Error('NIP-44 encryption not supported by this extension');
|
||||
}
|
||||
result = await window.nostr.nip44.encrypt(
|
||||
params.pubkey as string,
|
||||
params.plaintext as string
|
||||
);
|
||||
break;
|
||||
|
||||
case 'nip44.decrypt':
|
||||
if (!window.nostr.nip44) {
|
||||
throw new Error('NIP-44 decryption not supported by this extension');
|
||||
}
|
||||
result = await window.nostr.nip44.decrypt(
|
||||
params.pubkey as string,
|
||||
params.ciphertext as string
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error(`Unknown nostr method: ${nostrMethod}`);
|
||||
}
|
||||
|
||||
// Send success response
|
||||
sendResponse({
|
||||
jsonrpc: '2.0',
|
||||
result: result as JSONRPCResponse['result'],
|
||||
id
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`[Preview] Nostr ${nostrMethod} error:`, error);
|
||||
sendError({
|
||||
jsonrpc: '2.0',
|
||||
error: {
|
||||
code: -32000,
|
||||
message: error instanceof Error ? error.message : 'Unknown error',
|
||||
},
|
||||
id
|
||||
});
|
||||
}
|
||||
}, [sendResponse, sendError]);
|
||||
|
||||
const handleFetch = useCallback(async (request: JSONRPCRequest) => {
|
||||
const { params, id } = request;
|
||||
const { request: fetchRequest } = params;
|
||||
@@ -447,41 +348,11 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
||||
// Skip SPA fallback for static assets (files with extensions)
|
||||
const isStaticAsset = /\.[a-zA-Z0-9]+$/.test(path);
|
||||
|
||||
// Serve the nostr shim script at the special path
|
||||
if (path === NOSTR_SHIM_PATH) {
|
||||
console.log('[Preview] Serving nostr shim script');
|
||||
const shimCode = getNostrShimCode();
|
||||
sendResponse({
|
||||
jsonrpc: '2.0',
|
||||
result: {
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: {
|
||||
'Content-Type': 'application/javascript',
|
||||
'Cache-Control': 'no-cache',
|
||||
},
|
||||
body: encodeBase64(new TextEncoder().encode(shimCode)),
|
||||
},
|
||||
id
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// SPA routing: try to serve the exact file first
|
||||
try {
|
||||
const bytes = await projectsManager.readFileBytes(projectId, 'dist' + filePath);
|
||||
console.log(`Serving file: ${filePath}`);
|
||||
|
||||
// Inject nostr shim into index.html
|
||||
let responseBody: string;
|
||||
if (filePath === '/index.html') {
|
||||
const html = new TextDecoder().decode(bytes);
|
||||
const injectedHtml = injectNostrShim(html);
|
||||
responseBody = encodeBase64(new TextEncoder().encode(injectedHtml));
|
||||
} else {
|
||||
responseBody = encodeBase64(bytes);
|
||||
}
|
||||
|
||||
sendResponse({
|
||||
jsonrpc: '2.0',
|
||||
result: {
|
||||
@@ -491,7 +362,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
||||
'Content-Type': getContentType(filePath),
|
||||
'Cache-Control': 'no-cache',
|
||||
},
|
||||
body: responseBody,
|
||||
body: encodeBase64(bytes),
|
||||
},
|
||||
id
|
||||
});
|
||||
@@ -522,10 +393,6 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
||||
const bytes = await projectsManager.readFileBytes(projectId, 'dist/index.html');
|
||||
console.log(`Serving index.html fallback for: ${path}`);
|
||||
|
||||
// Inject nostr shim into index.html for SPA fallback
|
||||
const html = new TextDecoder().decode(bytes);
|
||||
const injectedHtml = injectNostrShim(html);
|
||||
|
||||
sendResponse({
|
||||
jsonrpc: '2.0',
|
||||
result: {
|
||||
@@ -535,7 +402,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
||||
'Content-Type': 'text/html',
|
||||
'Cache-Control': 'no-cache',
|
||||
},
|
||||
body: encodeBase64(new TextEncoder().encode(injectedHtml)),
|
||||
body: encodeBase64(bytes),
|
||||
},
|
||||
id
|
||||
});
|
||||
@@ -586,14 +453,12 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
||||
handleConsoleMessage(message);
|
||||
} else if (message.jsonrpc === '2.0' && message.method === 'updateNavigationState') {
|
||||
handleUpdateNavigationState(message);
|
||||
} else if (message.jsonrpc === '2.0' && message.method?.startsWith('nostr.')) {
|
||||
handleNostrRequest(message);
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('message', handleMessage);
|
||||
return () => window.removeEventListener('message', handleMessage);
|
||||
}, [handleFetch, handleConsoleMessage, handleUpdateNavigationState, handleNostrRequest, projectId, previewDomain]);
|
||||
}, [handleFetch, handleConsoleMessage, handleUpdateNavigationState, projectId, previewDomain]);
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedFile) {
|
||||
|
||||
@@ -113,6 +113,10 @@
|
||||
border-color: hsl(var(--border));
|
||||
}
|
||||
|
||||
html {
|
||||
overscroll-behavior: none;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: hsl(var(--background));
|
||||
color: hsl(var(--foreground));
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
/**
|
||||
* The path where the nostr shim script is served from.
|
||||
* This special path is intercepted by PreviewPane and serves the shim JavaScript.
|
||||
*
|
||||
* NOTE: Cannot start with /_ because the iframe-fetch-client's Service Worker
|
||||
* ignores paths starting with /_ (reserved for its own system files).
|
||||
*/
|
||||
export const NOSTR_SHIM_PATH = '/.nostr/shim.js';
|
||||
|
||||
/**
|
||||
* Returns the JavaScript code for the nostr shim (without script tags).
|
||||
* This is served as an external script to work with the iframe-fetch-client's
|
||||
* document replacement which only re-executes external scripts.
|
||||
*/
|
||||
export function getNostrShimCode(): string {
|
||||
return `(function() {
|
||||
// Map to track pending requests
|
||||
var pendingRequests = new Map();
|
||||
var requestId = 0;
|
||||
|
||||
// Send a request to the parent and wait for response
|
||||
function sendNostrRequest(method, params) {
|
||||
params = params || {};
|
||||
return new Promise(function(resolve, reject) {
|
||||
var id = ++requestId;
|
||||
|
||||
pendingRequests.set(id, { resolve: resolve, reject: reject });
|
||||
|
||||
window.parent.postMessage({
|
||||
jsonrpc: '2.0',
|
||||
method: 'nostr.' + method,
|
||||
params: params,
|
||||
id: id
|
||||
}, '*');
|
||||
|
||||
// Timeout after 60 seconds (signing can take time with hardware wallets)
|
||||
setTimeout(function() {
|
||||
if (pendingRequests.has(id)) {
|
||||
pendingRequests.delete(id);
|
||||
reject(new Error('Nostr request timed out'));
|
||||
}
|
||||
}, 60000);
|
||||
});
|
||||
}
|
||||
|
||||
// Handle responses from parent
|
||||
window.addEventListener('message', function(event) {
|
||||
var message = event.data;
|
||||
|
||||
// Check if this is a nostr response
|
||||
if (message && message.jsonrpc === '2.0' && message.id && pendingRequests.has(message.id)) {
|
||||
var pending = pendingRequests.get(message.id);
|
||||
pendingRequests.delete(message.id);
|
||||
|
||||
if (message.error) {
|
||||
pending.reject(new Error(message.error.message || 'Unknown error'));
|
||||
} else {
|
||||
pending.resolve(message.result);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Create the window.nostr shim
|
||||
window.nostr = {
|
||||
getPublicKey: function() {
|
||||
return sendNostrRequest('getPublicKey');
|
||||
},
|
||||
|
||||
signEvent: function(event) {
|
||||
return sendNostrRequest('signEvent', { event: event });
|
||||
},
|
||||
|
||||
getRelays: function() {
|
||||
return sendNostrRequest('getRelays');
|
||||
},
|
||||
|
||||
nip04: {
|
||||
encrypt: function(pubkey, plaintext) {
|
||||
return sendNostrRequest('nip04.encrypt', { pubkey: pubkey, plaintext: plaintext });
|
||||
},
|
||||
decrypt: function(pubkey, ciphertext) {
|
||||
return sendNostrRequest('nip04.decrypt', { pubkey: pubkey, ciphertext: ciphertext });
|
||||
}
|
||||
},
|
||||
|
||||
nip44: {
|
||||
encrypt: function(pubkey, plaintext) {
|
||||
return sendNostrRequest('nip44.encrypt', { pubkey: pubkey, plaintext: plaintext });
|
||||
},
|
||||
decrypt: function(pubkey, ciphertext) {
|
||||
return sendNostrRequest('nip44.decrypt', { pubkey: pubkey, ciphertext: ciphertext });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
console.log('[Preview] window.nostr shim installed - NIP-07 calls will be proxied to parent');
|
||||
})();`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Injects a reference to the nostr shim external script into an HTML string.
|
||||
* Inserts the script at the start of <head> to ensure it runs before any app code.
|
||||
*
|
||||
* We use an external script instead of inline because the iframe-fetch-client's
|
||||
* replaceDocument() only re-executes external scripts (those with src attribute).
|
||||
*/
|
||||
export function injectNostrShim(html: string): string {
|
||||
// Use external script reference - the script will be served by PreviewPane
|
||||
const shimScript = `<script src="${NOSTR_SHIM_PATH}"></script>`;
|
||||
|
||||
// Try to inject after <head> tag
|
||||
const headMatch = html.match(/<head[^>]*>/i);
|
||||
if (headMatch) {
|
||||
const insertPos = headMatch.index! + headMatch[0].length;
|
||||
return html.slice(0, insertPos) + '\n' + shimScript + '\n' + html.slice(insertPos);
|
||||
}
|
||||
|
||||
// Fallback: inject after <!DOCTYPE html> or at the very start
|
||||
const doctypeMatch = html.match(/<!DOCTYPE[^>]*>/i);
|
||||
if (doctypeMatch) {
|
||||
const insertPos = doctypeMatch.index! + doctypeMatch[0].length;
|
||||
return html.slice(0, insertPos) + '\n' + shimScript + '\n' + html.slice(insertPos);
|
||||
}
|
||||
|
||||
// Last resort: prepend
|
||||
return shimScript + '\n' + html;
|
||||
}
|
||||
Reference in new issue
Block a user