@hashtree/worker 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +38 -0
- package/dist/capabilities/blossomBandwidthTracker.d.ts +26 -0
- package/dist/capabilities/blossomBandwidthTracker.d.ts.map +1 -0
- package/dist/capabilities/blossomBandwidthTracker.js +53 -0
- package/dist/capabilities/blossomBandwidthTracker.js.map +1 -0
- package/dist/capabilities/blossomTransport.d.ts +22 -0
- package/dist/capabilities/blossomTransport.d.ts.map +1 -0
- package/dist/capabilities/blossomTransport.js +124 -0
- package/dist/capabilities/blossomTransport.js.map +1 -0
- package/dist/capabilities/connectivity.d.ts +3 -0
- package/dist/capabilities/connectivity.d.ts.map +1 -0
- package/dist/capabilities/connectivity.js +49 -0
- package/dist/capabilities/connectivity.js.map +1 -0
- package/dist/capabilities/idbStorage.d.ts +25 -0
- package/dist/capabilities/idbStorage.d.ts.map +1 -0
- package/dist/capabilities/idbStorage.js +73 -0
- package/dist/capabilities/idbStorage.js.map +1 -0
- package/dist/client.d.ts +54 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +336 -0
- package/dist/client.js.map +1 -0
- package/dist/entry.d.ts +2 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +2 -0
- package/dist/entry.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/iris/identity.d.ts +36 -0
- package/dist/iris/identity.d.ts.map +1 -0
- package/dist/iris/identity.js +78 -0
- package/dist/iris/identity.js.map +1 -0
- package/dist/iris/mediaHandler.d.ts +16 -0
- package/dist/iris/mediaHandler.d.ts.map +1 -0
- package/dist/iris/mediaHandler.js +529 -0
- package/dist/iris/mediaHandler.js.map +1 -0
- package/dist/iris/ndk.d.ts +95 -0
- package/dist/iris/ndk.d.ts.map +1 -0
- package/dist/iris/ndk.js +496 -0
- package/dist/iris/ndk.js.map +1 -0
- package/dist/iris/nostr-wasm.d.ts +14 -0
- package/dist/iris/nostr-wasm.d.ts.map +1 -0
- package/dist/iris/nostr-wasm.js +246 -0
- package/dist/iris/nostr-wasm.js.map +1 -0
- package/dist/iris/nostr.d.ts +60 -0
- package/dist/iris/nostr.d.ts.map +1 -0
- package/dist/iris/nostr.js +207 -0
- package/dist/iris/nostr.js.map +1 -0
- package/dist/iris/protocol.d.ts +574 -0
- package/dist/iris/protocol.d.ts.map +1 -0
- package/dist/iris/protocol.js +16 -0
- package/dist/iris/protocol.js.map +1 -0
- package/dist/iris/signing.d.ts +50 -0
- package/dist/iris/signing.d.ts.map +1 -0
- package/dist/iris/signing.js +299 -0
- package/dist/iris/signing.js.map +1 -0
- package/dist/iris/treeRootCache.d.ts +73 -0
- package/dist/iris/treeRootCache.d.ts.map +1 -0
- package/dist/iris/treeRootCache.js +191 -0
- package/dist/iris/treeRootCache.js.map +1 -0
- package/dist/iris/treeRootSubscription.d.ts +49 -0
- package/dist/iris/treeRootSubscription.d.ts.map +1 -0
- package/dist/iris/treeRootSubscription.js +185 -0
- package/dist/iris/treeRootSubscription.js.map +1 -0
- package/dist/iris/utils/constants.d.ts +76 -0
- package/dist/iris/utils/constants.d.ts.map +1 -0
- package/dist/iris/utils/constants.js +113 -0
- package/dist/iris/utils/constants.js.map +1 -0
- package/dist/iris/utils/errorMessage.d.ts +5 -0
- package/dist/iris/utils/errorMessage.d.ts.map +1 -0
- package/dist/iris/utils/errorMessage.js +8 -0
- package/dist/iris/utils/errorMessage.js.map +1 -0
- package/dist/iris/utils/lruCache.d.ts +26 -0
- package/dist/iris/utils/lruCache.d.ts.map +1 -0
- package/dist/iris/utils/lruCache.js +66 -0
- package/dist/iris/utils/lruCache.js.map +1 -0
- package/dist/iris/webrtc.d.ts +2 -0
- package/dist/iris/webrtc.d.ts.map +1 -0
- package/dist/iris/webrtc.js +3 -0
- package/dist/iris/webrtc.js.map +1 -0
- package/dist/iris/webrtcSignaling.d.ts +37 -0
- package/dist/iris/webrtcSignaling.d.ts.map +1 -0
- package/dist/iris/webrtcSignaling.js +86 -0
- package/dist/iris/webrtcSignaling.js.map +1 -0
- package/dist/iris/worker.d.ts +12 -0
- package/dist/iris/worker.d.ts.map +1 -0
- package/dist/iris/worker.js +1582 -0
- package/dist/iris/worker.js.map +1 -0
- package/dist/iris-entry.d.ts +2 -0
- package/dist/iris-entry.d.ts.map +1 -0
- package/dist/iris-entry.js +2 -0
- package/dist/iris-entry.js.map +1 -0
- package/dist/mediaStreaming.d.ts +7 -0
- package/dist/mediaStreaming.d.ts.map +1 -0
- package/dist/mediaStreaming.js +48 -0
- package/dist/mediaStreaming.js.map +1 -0
- package/dist/p2p/boundedQueue.d.ts +74 -0
- package/dist/p2p/boundedQueue.d.ts.map +1 -0
- package/dist/p2p/boundedQueue.js +112 -0
- package/dist/p2p/boundedQueue.js.map +1 -0
- package/dist/p2p/errorMessage.d.ts +5 -0
- package/dist/p2p/errorMessage.d.ts.map +1 -0
- package/dist/p2p/errorMessage.js +7 -0
- package/dist/p2p/errorMessage.js.map +1 -0
- package/dist/p2p/index.d.ts +7 -0
- package/dist/p2p/index.d.ts.map +1 -0
- package/dist/p2p/index.js +5 -0
- package/dist/p2p/index.js.map +1 -0
- package/dist/p2p/lruCache.d.ts +26 -0
- package/dist/p2p/lruCache.d.ts.map +1 -0
- package/dist/p2p/lruCache.js +65 -0
- package/dist/p2p/lruCache.js.map +1 -0
- package/dist/p2p/protocol.d.ts +10 -0
- package/dist/p2p/protocol.d.ts.map +1 -0
- package/dist/p2p/protocol.js +2 -0
- package/dist/p2p/protocol.js.map +1 -0
- package/dist/p2p/queryForwardingMachine.d.ts +46 -0
- package/dist/p2p/queryForwardingMachine.d.ts.map +1 -0
- package/dist/p2p/queryForwardingMachine.js +144 -0
- package/dist/p2p/queryForwardingMachine.js.map +1 -0
- package/dist/p2p/signaling.d.ts +63 -0
- package/dist/p2p/signaling.d.ts.map +1 -0
- package/dist/p2p/signaling.js +165 -0
- package/dist/p2p/signaling.js.map +1 -0
- package/dist/p2p/webrtcController.d.ts +152 -0
- package/dist/p2p/webrtcController.d.ts.map +1 -0
- package/dist/p2p/webrtcController.js +813 -0
- package/dist/p2p/webrtcController.js.map +1 -0
- package/dist/p2p/webrtcProxy.d.ts +55 -0
- package/dist/p2p/webrtcProxy.d.ts.map +1 -0
- package/dist/p2p/webrtcProxy.js +386 -0
- package/dist/p2p/webrtcProxy.js.map +1 -0
- package/dist/privacyGuards.d.ts +14 -0
- package/dist/privacyGuards.d.ts.map +1 -0
- package/dist/privacyGuards.js +27 -0
- package/dist/privacyGuards.js.map +1 -0
- package/dist/protocol.d.ts +171 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +2 -0
- package/dist/protocol.js.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/worker.d.ts +2 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +616 -0
- package/dist/worker.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* Media Streaming Handler for Hashtree Worker
|
|
4
|
+
*
|
|
5
|
+
* Handles media requests from the service worker via MessagePort.
|
|
6
|
+
* Supports both direct CID-based requests and path-based requests with live streaming.
|
|
7
|
+
*/
|
|
8
|
+
import { getCachedRoot } from './treeRootCache';
|
|
9
|
+
import { subscribeToTreeRoots } from './treeRootSubscription';
|
|
10
|
+
import { getErrorMessage } from './utils/errorMessage';
|
|
11
|
+
import { nhashDecode } from '@hashtree/core';
|
|
12
|
+
import { nip19 } from 'nostr-tools';
|
|
13
|
+
// Thumbnail filename patterns to look for (in priority order)
|
|
14
|
+
const THUMBNAIL_PATTERNS = ['thumbnail.jpg', 'thumbnail.webp', 'thumbnail.png', 'thumbnail.jpeg'];
|
|
15
|
+
// Timeout for considering a stream "done" (no updates)
|
|
16
|
+
const LIVE_STREAM_TIMEOUT = 10000; // 10 seconds
|
|
17
|
+
const ROOT_WAIT_TIMEOUT_MS = 15000;
|
|
18
|
+
const ROOT_WAIT_INTERVAL_MS = 200;
|
|
19
|
+
// Chunk size for streaming to media port
|
|
20
|
+
const MEDIA_CHUNK_SIZE = 256 * 1024; // 256KB chunks - matches videoChunker's firstChunkSize
|
|
21
|
+
const activeMediaStreams = new Map();
|
|
22
|
+
let mediaPort = null;
|
|
23
|
+
let tree = null;
|
|
24
|
+
let mediaDebugEnabled = false;
|
|
25
|
+
function logMediaDebug(event, data) {
|
|
26
|
+
if (!mediaDebugEnabled)
|
|
27
|
+
return;
|
|
28
|
+
if (data) {
|
|
29
|
+
console.log(`[WorkerMedia] ${event}`, data);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
console.log(`[WorkerMedia] ${event}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Initialize the media handler with the HashTree instance
|
|
37
|
+
*/
|
|
38
|
+
export function initMediaHandler(hashTree) {
|
|
39
|
+
tree = hashTree;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Register a MessagePort from the service worker for media streaming
|
|
43
|
+
*/
|
|
44
|
+
export function registerMediaPort(port, debug) {
|
|
45
|
+
mediaPort = port;
|
|
46
|
+
mediaDebugEnabled = !!debug;
|
|
47
|
+
port.onmessage = async (e) => {
|
|
48
|
+
const req = e.data;
|
|
49
|
+
if (req.type === 'hashtree-file') {
|
|
50
|
+
// SW file request format (direct from service worker)
|
|
51
|
+
await handleSwFileRequest(req);
|
|
52
|
+
}
|
|
53
|
+
else if (req.type === 'media') {
|
|
54
|
+
await handleMediaRequestByCid(req);
|
|
55
|
+
}
|
|
56
|
+
else if (req.type === 'mediaByPath') {
|
|
57
|
+
await handleMediaRequestByPath(req);
|
|
58
|
+
}
|
|
59
|
+
else if (req.type === 'cancelMedia') {
|
|
60
|
+
// Cancel an active stream
|
|
61
|
+
const stream = activeMediaStreams.get(req.requestId);
|
|
62
|
+
if (stream) {
|
|
63
|
+
stream.cancelled = true;
|
|
64
|
+
activeMediaStreams.delete(req.requestId);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
console.log('[Worker] Media port registered');
|
|
69
|
+
logMediaDebug('port:registered', { debug: mediaDebugEnabled });
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Handle direct CID-based media request
|
|
73
|
+
*/
|
|
74
|
+
async function handleMediaRequestByCid(req) {
|
|
75
|
+
if (!tree || !mediaPort)
|
|
76
|
+
return;
|
|
77
|
+
const { requestId, cid: cidHex, start, end, mimeType } = req;
|
|
78
|
+
try {
|
|
79
|
+
// Convert hex CID to proper CID object
|
|
80
|
+
const hash = new Uint8Array(cidHex.length / 2);
|
|
81
|
+
for (let i = 0; i < hash.length; i++) {
|
|
82
|
+
hash[i] = parseInt(cidHex.substr(i * 2, 2), 16);
|
|
83
|
+
}
|
|
84
|
+
const cid = { hash };
|
|
85
|
+
// Get file size first
|
|
86
|
+
const totalSize = await tree.getSize(hash);
|
|
87
|
+
// Send headers
|
|
88
|
+
mediaPort.postMessage({
|
|
89
|
+
type: 'headers',
|
|
90
|
+
requestId,
|
|
91
|
+
totalSize,
|
|
92
|
+
mimeType: mimeType || 'application/octet-stream',
|
|
93
|
+
isLive: false,
|
|
94
|
+
});
|
|
95
|
+
// Read range and stream chunks
|
|
96
|
+
const data = await tree.readFileRange(cid, start, end);
|
|
97
|
+
if (data) {
|
|
98
|
+
await streamChunksToPort(requestId, data);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
mediaPort.postMessage({
|
|
102
|
+
type: 'error',
|
|
103
|
+
requestId,
|
|
104
|
+
message: 'File not found',
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
mediaPort.postMessage({
|
|
110
|
+
type: 'error',
|
|
111
|
+
requestId,
|
|
112
|
+
message: getErrorMessage(err),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Handle npub/path-based media request (supports live streaming)
|
|
118
|
+
*/
|
|
119
|
+
async function handleMediaRequestByPath(req) {
|
|
120
|
+
if (!tree || !mediaPort)
|
|
121
|
+
return;
|
|
122
|
+
const { requestId, npub, path, start, mimeType } = req;
|
|
123
|
+
try {
|
|
124
|
+
// Parse path to get tree name
|
|
125
|
+
const pathParts = path.split('/').filter(Boolean);
|
|
126
|
+
const treeName = pathParts[0] || 'public';
|
|
127
|
+
const filePath = pathParts.slice(1).join('/');
|
|
128
|
+
// Resolve npub to current CID
|
|
129
|
+
let cid = await waitForCachedRoot(npub, treeName);
|
|
130
|
+
if (!cid) {
|
|
131
|
+
mediaPort.postMessage({
|
|
132
|
+
type: 'error',
|
|
133
|
+
requestId,
|
|
134
|
+
message: `Tree root not found for ${npub}/${treeName}`,
|
|
135
|
+
});
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
// Navigate to file within tree if path specified
|
|
139
|
+
if (filePath) {
|
|
140
|
+
const resolved = await tree.resolvePath(cid, filePath);
|
|
141
|
+
if (!resolved) {
|
|
142
|
+
mediaPort.postMessage({
|
|
143
|
+
type: 'error',
|
|
144
|
+
requestId,
|
|
145
|
+
message: `File not found: ${filePath}`,
|
|
146
|
+
});
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
cid = resolved.cid;
|
|
150
|
+
}
|
|
151
|
+
// Get file size
|
|
152
|
+
const totalSize = await tree.getSize(cid.hash);
|
|
153
|
+
// Send headers (isLive will be determined by watching for updates)
|
|
154
|
+
mediaPort.postMessage({
|
|
155
|
+
type: 'headers',
|
|
156
|
+
requestId,
|
|
157
|
+
totalSize,
|
|
158
|
+
mimeType: mimeType || 'application/octet-stream',
|
|
159
|
+
isLive: false, // Will update if we detect changes
|
|
160
|
+
});
|
|
161
|
+
// Stream initial content
|
|
162
|
+
const data = await tree.readFileRange(cid, start);
|
|
163
|
+
let offset = start;
|
|
164
|
+
if (data) {
|
|
165
|
+
await streamChunksToPort(requestId, data, false); // Don't close yet
|
|
166
|
+
offset += data.length;
|
|
167
|
+
}
|
|
168
|
+
// Register for live updates
|
|
169
|
+
const streamInfo = {
|
|
170
|
+
requestId,
|
|
171
|
+
npub,
|
|
172
|
+
path,
|
|
173
|
+
offset,
|
|
174
|
+
cancelled: false,
|
|
175
|
+
};
|
|
176
|
+
activeMediaStreams.set(requestId, streamInfo);
|
|
177
|
+
// Set up tree root watcher for this npub
|
|
178
|
+
// When root changes, we'll check if this file has new data
|
|
179
|
+
watchTreeRootForStream(npub, treeName, filePath, streamInfo);
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
mediaPort.postMessage({
|
|
183
|
+
type: 'error',
|
|
184
|
+
requestId,
|
|
185
|
+
message: getErrorMessage(err),
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Stream data chunks to media port
|
|
191
|
+
*/
|
|
192
|
+
async function streamChunksToPort(requestId, data, sendDone = true) {
|
|
193
|
+
if (!mediaPort)
|
|
194
|
+
return;
|
|
195
|
+
for (let offset = 0; offset < data.length; offset += MEDIA_CHUNK_SIZE) {
|
|
196
|
+
const chunk = data.slice(offset, offset + MEDIA_CHUNK_SIZE);
|
|
197
|
+
mediaPort.postMessage({ type: 'chunk', requestId, data: chunk }, [chunk.buffer]);
|
|
198
|
+
}
|
|
199
|
+
if (sendDone) {
|
|
200
|
+
mediaPort.postMessage({ type: 'done', requestId });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Watch for tree root updates and push new data to stream
|
|
205
|
+
*/
|
|
206
|
+
function watchTreeRootForStream(npub, treeName, filePath, streamInfo) {
|
|
207
|
+
let lastActivity = Date.now();
|
|
208
|
+
let timeoutId = null;
|
|
209
|
+
const checkForUpdates = async () => {
|
|
210
|
+
if (streamInfo.cancelled || !tree || !mediaPort) {
|
|
211
|
+
cleanup();
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
// Check if stream timed out
|
|
215
|
+
if (Date.now() - lastActivity > LIVE_STREAM_TIMEOUT) {
|
|
216
|
+
// No updates for a while, close the stream
|
|
217
|
+
mediaPort.postMessage({
|
|
218
|
+
type: 'done',
|
|
219
|
+
requestId: streamInfo.requestId,
|
|
220
|
+
});
|
|
221
|
+
cleanup();
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
try {
|
|
225
|
+
// Get current root
|
|
226
|
+
const cid = await getCachedRoot(npub, treeName);
|
|
227
|
+
if (!cid) {
|
|
228
|
+
scheduleNext();
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
// Navigate to file
|
|
232
|
+
let fileCid = cid;
|
|
233
|
+
if (filePath) {
|
|
234
|
+
const resolved = await tree.resolvePath(cid, filePath);
|
|
235
|
+
if (!resolved) {
|
|
236
|
+
scheduleNext();
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
fileCid = resolved.cid;
|
|
240
|
+
}
|
|
241
|
+
// Check for new data
|
|
242
|
+
const totalSize = await tree.getSize(fileCid.hash);
|
|
243
|
+
if (totalSize > streamInfo.offset) {
|
|
244
|
+
// New data available!
|
|
245
|
+
lastActivity = Date.now();
|
|
246
|
+
const newData = await tree.readFileRange(fileCid, streamInfo.offset);
|
|
247
|
+
if (newData && newData.length > 0) {
|
|
248
|
+
await streamChunksToPort(streamInfo.requestId, newData, false);
|
|
249
|
+
streamInfo.offset += newData.length;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
catch {
|
|
254
|
+
// Ignore errors, just try again
|
|
255
|
+
}
|
|
256
|
+
scheduleNext();
|
|
257
|
+
};
|
|
258
|
+
const scheduleNext = () => {
|
|
259
|
+
if (!streamInfo.cancelled) {
|
|
260
|
+
timeoutId = setTimeout(checkForUpdates, 1000); // Check every second
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
const cleanup = () => {
|
|
264
|
+
if (timeoutId)
|
|
265
|
+
clearTimeout(timeoutId);
|
|
266
|
+
activeMediaStreams.delete(streamInfo.requestId);
|
|
267
|
+
};
|
|
268
|
+
// Start watching
|
|
269
|
+
scheduleNext();
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Handle file request from service worker (hashtree-file format)
|
|
273
|
+
* This is the main entry point for direct SW → Worker communication
|
|
274
|
+
*/
|
|
275
|
+
async function handleSwFileRequest(req) {
|
|
276
|
+
if (!tree || !mediaPort)
|
|
277
|
+
return;
|
|
278
|
+
const { requestId, npub, nhash, treeName, path, start, end, mimeType, download } = req;
|
|
279
|
+
logMediaDebug('sw:request', {
|
|
280
|
+
requestId,
|
|
281
|
+
npub: npub ?? null,
|
|
282
|
+
nhash: nhash ?? null,
|
|
283
|
+
treeName: treeName ?? null,
|
|
284
|
+
path,
|
|
285
|
+
start,
|
|
286
|
+
end: end ?? null,
|
|
287
|
+
mimeType,
|
|
288
|
+
download: !!download,
|
|
289
|
+
});
|
|
290
|
+
try {
|
|
291
|
+
let cid = null;
|
|
292
|
+
if (nhash) {
|
|
293
|
+
// Direct nhash request - decode to CID
|
|
294
|
+
const rootCid = nhashDecode(nhash);
|
|
295
|
+
// If path provided AND it contains a slash, navigate within the nhash directory
|
|
296
|
+
// Single filename without slashes is just a hint for MIME type - use rootCid directly
|
|
297
|
+
if (path && path.includes('/')) {
|
|
298
|
+
const entry = await tree.resolvePath(rootCid, path);
|
|
299
|
+
if (!entry) {
|
|
300
|
+
sendSwError(requestId, 404, `File not found: ${path}`);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
cid = entry.cid;
|
|
304
|
+
}
|
|
305
|
+
else if (path && !path.includes('/')) {
|
|
306
|
+
// Try to resolve as file within directory first
|
|
307
|
+
const entry = await tree.resolvePath(rootCid, path);
|
|
308
|
+
cid = entry ? entry.cid : rootCid;
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
cid = rootCid;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
else if (npub && treeName) {
|
|
315
|
+
// Npub-based request - resolve through cached root
|
|
316
|
+
const rootCid = await waitForCachedRoot(npub, treeName);
|
|
317
|
+
if (!rootCid) {
|
|
318
|
+
sendSwError(requestId, 404, 'Tree not found');
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
// Handle thumbnail requests without extension
|
|
322
|
+
let resolvedPath = path || '';
|
|
323
|
+
if (resolvedPath.endsWith('/thumbnail') || resolvedPath === 'thumbnail') {
|
|
324
|
+
const dirPath = resolvedPath.endsWith('/thumbnail')
|
|
325
|
+
? resolvedPath.slice(0, -'/thumbnail'.length)
|
|
326
|
+
: '';
|
|
327
|
+
const actualPath = await findThumbnailInDir(rootCid, dirPath);
|
|
328
|
+
if (actualPath) {
|
|
329
|
+
resolvedPath = actualPath;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
// Navigate to file
|
|
333
|
+
if (resolvedPath) {
|
|
334
|
+
const entry = await tree.resolvePath(rootCid, resolvedPath);
|
|
335
|
+
if (!entry) {
|
|
336
|
+
sendSwError(requestId, 404, 'File not found');
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
cid = entry.cid;
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
cid = rootCid;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (!cid) {
|
|
346
|
+
sendSwError(requestId, 400, 'Invalid request');
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
// Get file size
|
|
350
|
+
const totalSize = await getFileSize(cid);
|
|
351
|
+
if (totalSize === null) {
|
|
352
|
+
sendSwError(requestId, 404, 'File data not found');
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
// Stream the content
|
|
356
|
+
await streamSwResponse(requestId, cid, totalSize, {
|
|
357
|
+
npub,
|
|
358
|
+
path,
|
|
359
|
+
start,
|
|
360
|
+
end,
|
|
361
|
+
mimeType,
|
|
362
|
+
download,
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
catch (err) {
|
|
366
|
+
sendSwError(requestId, 500, getErrorMessage(err));
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
async function waitForCachedRoot(npub, treeName) {
|
|
370
|
+
let cached = await getCachedRoot(npub, treeName);
|
|
371
|
+
if (cached)
|
|
372
|
+
return cached;
|
|
373
|
+
const pubkey = decodeNpubToPubkey(npub);
|
|
374
|
+
if (pubkey) {
|
|
375
|
+
subscribeToTreeRoots(pubkey);
|
|
376
|
+
}
|
|
377
|
+
const deadline = Date.now() + ROOT_WAIT_TIMEOUT_MS;
|
|
378
|
+
while (Date.now() < deadline) {
|
|
379
|
+
await new Promise((resolve) => setTimeout(resolve, ROOT_WAIT_INTERVAL_MS));
|
|
380
|
+
cached = await getCachedRoot(npub, treeName);
|
|
381
|
+
if (cached)
|
|
382
|
+
return cached;
|
|
383
|
+
}
|
|
384
|
+
logMediaDebug('root:timeout', { npub, treeName });
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
function decodeNpubToPubkey(npub) {
|
|
388
|
+
if (!npub.startsWith('npub1'))
|
|
389
|
+
return null;
|
|
390
|
+
try {
|
|
391
|
+
const decoded = nip19.decode(npub);
|
|
392
|
+
if (decoded.type !== 'npub')
|
|
393
|
+
return null;
|
|
394
|
+
return decoded.data;
|
|
395
|
+
}
|
|
396
|
+
catch {
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Send error response to SW
|
|
402
|
+
*/
|
|
403
|
+
function sendSwError(requestId, status, message) {
|
|
404
|
+
if (!mediaPort)
|
|
405
|
+
return;
|
|
406
|
+
logMediaDebug('sw:error', { requestId, status, message });
|
|
407
|
+
mediaPort.postMessage({
|
|
408
|
+
type: 'error',
|
|
409
|
+
requestId,
|
|
410
|
+
status,
|
|
411
|
+
message,
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Get file size from CID (handles both chunked and single blob files)
|
|
416
|
+
*/
|
|
417
|
+
async function getFileSize(cid) {
|
|
418
|
+
if (!tree)
|
|
419
|
+
return null;
|
|
420
|
+
const treeNode = await tree.getTreeNode(cid);
|
|
421
|
+
if (treeNode) {
|
|
422
|
+
// Chunked file - sum link sizes from decrypted tree node
|
|
423
|
+
return treeNode.links.reduce((sum, l) => sum + l.size, 0);
|
|
424
|
+
}
|
|
425
|
+
// Single blob - fetch to check existence and get size
|
|
426
|
+
const blob = await tree.getBlob(cid.hash);
|
|
427
|
+
if (!blob)
|
|
428
|
+
return null;
|
|
429
|
+
// For encrypted blobs, decrypted size = encrypted size - 16 (nonce overhead)
|
|
430
|
+
return cid.key ? Math.max(0, blob.length - 16) : blob.length;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Find actual thumbnail file in a directory
|
|
434
|
+
*/
|
|
435
|
+
async function findThumbnailInDir(rootCid, dirPath) {
|
|
436
|
+
if (!tree)
|
|
437
|
+
return null;
|
|
438
|
+
try {
|
|
439
|
+
// Get directory CID
|
|
440
|
+
const dirEntry = dirPath
|
|
441
|
+
? await tree.resolvePath(rootCid, dirPath)
|
|
442
|
+
: { cid: rootCid };
|
|
443
|
+
if (!dirEntry)
|
|
444
|
+
return null;
|
|
445
|
+
// List directory contents
|
|
446
|
+
const entries = await tree.listDirectory(dirEntry.cid);
|
|
447
|
+
if (!entries)
|
|
448
|
+
return null;
|
|
449
|
+
// Find first matching thumbnail pattern
|
|
450
|
+
for (const pattern of THUMBNAIL_PATTERNS) {
|
|
451
|
+
if (entries.some(e => e.name === pattern)) {
|
|
452
|
+
return dirPath ? `${dirPath}/${pattern}` : pattern;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
return null;
|
|
456
|
+
}
|
|
457
|
+
catch {
|
|
458
|
+
return null;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Stream response to SW with proper HTTP headers
|
|
463
|
+
*/
|
|
464
|
+
async function streamSwResponse(requestId, cid, totalSize, options) {
|
|
465
|
+
if (!tree || !mediaPort)
|
|
466
|
+
return;
|
|
467
|
+
const { npub, path, start = 0, end, mimeType = 'application/octet-stream', download } = options;
|
|
468
|
+
const rangeStart = start;
|
|
469
|
+
const rangeEnd = end !== undefined ? Math.min(end, totalSize - 1) : totalSize - 1;
|
|
470
|
+
const contentLength = rangeEnd - rangeStart + 1;
|
|
471
|
+
// Build cache control header
|
|
472
|
+
const isNpubRequest = !!npub;
|
|
473
|
+
const isImage = mimeType.startsWith('image/');
|
|
474
|
+
let cacheControl;
|
|
475
|
+
if (!isNpubRequest) {
|
|
476
|
+
cacheControl = 'public, max-age=31536000, immutable'; // nhash: immutable
|
|
477
|
+
}
|
|
478
|
+
else if (isImage) {
|
|
479
|
+
cacheControl = 'public, max-age=60, stale-while-revalidate=86400';
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
cacheControl = 'no-cache, no-store, must-revalidate';
|
|
483
|
+
}
|
|
484
|
+
// Build headers
|
|
485
|
+
const headers = {
|
|
486
|
+
'Content-Type': mimeType,
|
|
487
|
+
'Accept-Ranges': 'bytes',
|
|
488
|
+
'Cache-Control': cacheControl,
|
|
489
|
+
'Content-Length': String(contentLength),
|
|
490
|
+
};
|
|
491
|
+
if (download) {
|
|
492
|
+
const filename = path || 'file';
|
|
493
|
+
headers['Content-Disposition'] = `attachment; filename="${filename}"`;
|
|
494
|
+
}
|
|
495
|
+
// Determine status (206 for range requests)
|
|
496
|
+
const isRangeRequest = end !== undefined || start > 0;
|
|
497
|
+
const status = isRangeRequest ? 206 : 200;
|
|
498
|
+
if (isRangeRequest) {
|
|
499
|
+
headers['Content-Range'] = `bytes ${rangeStart}-${rangeEnd}/${totalSize}`;
|
|
500
|
+
}
|
|
501
|
+
logMediaDebug('sw:response', {
|
|
502
|
+
requestId,
|
|
503
|
+
status,
|
|
504
|
+
totalSize,
|
|
505
|
+
rangeStart,
|
|
506
|
+
rangeEnd,
|
|
507
|
+
});
|
|
508
|
+
// Send headers
|
|
509
|
+
mediaPort.postMessage({
|
|
510
|
+
type: 'headers',
|
|
511
|
+
requestId,
|
|
512
|
+
status,
|
|
513
|
+
headers,
|
|
514
|
+
totalSize,
|
|
515
|
+
});
|
|
516
|
+
// Stream chunks
|
|
517
|
+
let offset = rangeStart;
|
|
518
|
+
while (offset <= rangeEnd) {
|
|
519
|
+
const chunkEnd = Math.min(offset + MEDIA_CHUNK_SIZE - 1, rangeEnd);
|
|
520
|
+
const chunk = await tree.readFileRange(cid, offset, chunkEnd + 1);
|
|
521
|
+
if (!chunk)
|
|
522
|
+
break;
|
|
523
|
+
mediaPort.postMessage({ type: 'chunk', requestId, data: chunk }, [chunk.buffer]);
|
|
524
|
+
offset = chunkEnd + 1;
|
|
525
|
+
}
|
|
526
|
+
// Signal done
|
|
527
|
+
mediaPort.postMessage({ type: 'done', requestId });
|
|
528
|
+
}
|
|
529
|
+
//# sourceMappingURL=mediaHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mediaHandler.js","sourceRoot":"","sources":["../../src/iris/mediaHandler.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;;;;GAKG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,8DAA8D;AAC9D,MAAM,kBAAkB,GAAG,CAAC,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,gBAAgB,CAAC,CAAC;AA+BlG,u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AI,SAAS,EAAE,CAAC;IAC5E,CAAC;IAED,aAAa,CAAC,aAAa,EAAE;QAC3B,SAAS;QACT,MAAM;QACN,SAAS;QACT,UAAU;QACV,QAAQ;KACT,CAAC,CAAC;IAEH,eAAe;IACf,SAAS,CAAC,WAAW,CAAC;QACpB,IAAI,EAAE,SAAS;QACf,SAAS;QACT,MAAM;QACN,OAAO;QACP,SAAS;KACQ,CAAC,CAAC;IAErB,gBAAgB;IAChB,IAAI,MAAM,GAAG,UAAU,CAAC;IACxB,OAAO,MAAM,IAAI,QAAQ,EAAE,CAAC;QAC1B,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,gBAAgB,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC;QACnE,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,GAAG,CAAC,CAAC,CAAC;QAElE,IAAI,CAAC,KAAK;YAAE,MAAM;QAElB,SAAS,CAAC,WAAW,CACnB,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAoB,EAC3D,CAAC,KAAK,CAAC,MAAM,CAAC,CACf,CAAC;QAEF,MAAM,GAAG,QAAQ,GAAG,CAAC,CAAC;IACxB,CAAC;IAED,cAAc;IACd,SAAS,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAoB,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NDK instance for Worker
|
|
3
|
+
*
|
|
4
|
+
* Runs NDK with:
|
|
5
|
+
* - Real relay connections
|
|
6
|
+
* - ndk-cache (Dexie) for IndexedDB caching
|
|
7
|
+
* - nostr-wasm for fast signature verification
|
|
8
|
+
*
|
|
9
|
+
* Main thread communicates via WorkerAdapter postMessage.
|
|
10
|
+
*/
|
|
11
|
+
import type { SignedEvent, NostrFilter } from './protocol';
|
|
12
|
+
/**
|
|
13
|
+
* Initialize NDK with cache and nostr-wasm
|
|
14
|
+
*/
|
|
15
|
+
export declare function initNdk(relays: string[], options?: {
|
|
16
|
+
pubkey?: string;
|
|
17
|
+
nsec?: string;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Get the NDK instance
|
|
21
|
+
*/
|
|
22
|
+
export declare function getNdk(): NDK | null;
|
|
23
|
+
/**
|
|
24
|
+
* Set event callback
|
|
25
|
+
*/
|
|
26
|
+
export declare function setOnEvent(callback: (subId: string, event: SignedEvent) => void | Promise<void>): void;
|
|
27
|
+
/**
|
|
28
|
+
* Set EOSE callback
|
|
29
|
+
*/
|
|
30
|
+
export declare function setOnEose(callback: (subId: string) => void): void;
|
|
31
|
+
/**
|
|
32
|
+
* Subscribe to events
|
|
33
|
+
*/
|
|
34
|
+
export declare function subscribe(subId: string, filters: NostrFilter[]): void;
|
|
35
|
+
/**
|
|
36
|
+
* Unsubscribe
|
|
37
|
+
*/
|
|
38
|
+
export declare function unsubscribe(subId: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* Publish an event
|
|
41
|
+
*/
|
|
42
|
+
export declare function publish(event: SignedEvent): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Close NDK and all subscriptions
|
|
45
|
+
*/
|
|
46
|
+
export declare function closeNdk(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Update relays dynamically
|
|
49
|
+
* Disconnects old relays and connects to new ones
|
|
50
|
+
*/
|
|
51
|
+
export declare function setRelays(relays: string[]): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Get relay stats
|
|
54
|
+
*/
|
|
55
|
+
export declare function getRelayStats(): {
|
|
56
|
+
url: string;
|
|
57
|
+
connected: boolean;
|
|
58
|
+
eventsReceived: number;
|
|
59
|
+
eventsSent: number;
|
|
60
|
+
}[];
|
|
61
|
+
/**
|
|
62
|
+
* Republish all user's hashtree events from cache to relays
|
|
63
|
+
* This helps recover when events exist locally but weren't properly published
|
|
64
|
+
*
|
|
65
|
+
* For unsigned events (never signed), we sign them using the worker's signing flow.
|
|
66
|
+
* For signed events, we republish directly.
|
|
67
|
+
* Also pushes blob data to Blossom servers.
|
|
68
|
+
*
|
|
69
|
+
* @param prefix - Optional URL-encoded prefix to filter trees by d-tag
|
|
70
|
+
*/
|
|
71
|
+
export declare function republishTrees(pubkey: string, signFn: (template: {
|
|
72
|
+
kind: number;
|
|
73
|
+
created_at: number;
|
|
74
|
+
content: string;
|
|
75
|
+
tags: string[][];
|
|
76
|
+
}) => Promise<{
|
|
77
|
+
id: string;
|
|
78
|
+
pubkey: string;
|
|
79
|
+
kind: number;
|
|
80
|
+
content: string;
|
|
81
|
+
tags: string[][];
|
|
82
|
+
created_at: number;
|
|
83
|
+
sig: string;
|
|
84
|
+
}>, pushToBlossomFn?: (hash: Uint8Array, key?: Uint8Array, treeName?: string) => Promise<{
|
|
85
|
+
pushed: number;
|
|
86
|
+
skipped: number;
|
|
87
|
+
failed: number;
|
|
88
|
+
}>, prefix?: string): Promise<number>;
|
|
89
|
+
/**
|
|
90
|
+
* Republish a single tree's event from cache to relays
|
|
91
|
+
* This republishes the original event as-is (preserves signature/timestamp)
|
|
92
|
+
* Works for any user's tree, not just own.
|
|
93
|
+
*/
|
|
94
|
+
export declare function republishTree(pubkey: string, treeName: string): Promise<boolean>;
|
|
95
|
+
//# sourceMappingURL=ndk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ndk.d.ts","sourceRoot":"","sources":["../../src/iris/ndk.ts"],"names":[],"mappings":"AACA;;;;;;;;;GASG;AAMH,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA2E3D;;GAEG;AACH,wBAAsB,OAAO,CAC3B,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC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