streamingController: allow to connect without authorization
This commit is contained in:
parent
648c32986b
commit
2a0cba55e6
|
@ -38,12 +38,8 @@ const streamingController: AppController = (c) => {
|
||||||
return c.text('Please use websocket protocol', 400);
|
return c.text('Please use websocket protocol', 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!token) {
|
|
||||||
return c.json({ error: 'Missing access token' }, 401);
|
|
||||||
}
|
|
||||||
|
|
||||||
const pubkey = token ? bech32ToPubkey(token) : undefined;
|
const pubkey = token ? bech32ToPubkey(token) : undefined;
|
||||||
if (!pubkey) {
|
if (token && !pubkey) {
|
||||||
return c.json({ error: 'Invalid access token' }, 401);
|
return c.json({ error: 'Invalid access token' }, 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +58,7 @@ const streamingController: AppController = (c) => {
|
||||||
|
|
||||||
socket.onopen = async () => {
|
socket.onopen = async () => {
|
||||||
if (!stream) return;
|
if (!stream) return;
|
||||||
const filter = await topicToFilter(stream, pubkey, c.req.query());
|
const filter = await topicToFilter(stream, c.req.query(), pubkey);
|
||||||
|
|
||||||
if (filter) {
|
if (filter) {
|
||||||
for await (const event of Sub.sub(socket, '1', [filter])) {
|
for await (const event of Sub.sub(socket, '1', [filter])) {
|
||||||
|
@ -84,8 +80,8 @@ const streamingController: AppController = (c) => {
|
||||||
|
|
||||||
async function topicToFilter(
|
async function topicToFilter(
|
||||||
topic: Stream,
|
topic: Stream,
|
||||||
pubkey: string,
|
|
||||||
query: Record<string, string>,
|
query: Record<string, string>,
|
||||||
|
pubkey: string | undefined,
|
||||||
): Promise<DittoFilter | undefined> {
|
): Promise<DittoFilter | undefined> {
|
||||||
switch (topic) {
|
switch (topic) {
|
||||||
case 'public':
|
case 'public':
|
||||||
|
@ -102,7 +98,7 @@ async function topicToFilter(
|
||||||
// HACK: this puts the user's entire contacts list into RAM,
|
// HACK: this puts the user's entire contacts list into RAM,
|
||||||
// and then calls `matchFilters` over it. Refreshing the page
|
// and then calls `matchFilters` over it. Refreshing the page
|
||||||
// is required after following a new user.
|
// is required after following a new user.
|
||||||
return { kinds: [1], authors: await getFeedPubkeys(pubkey) };
|
return pubkey ? { kinds: [1], authors: await getFeedPubkeys(pubkey) } : undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue