-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1fc79a
commit 0494e16
Showing
5 changed files
with
163 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,20 @@ import { Mutation, RootResolver } from "./resolvers/root.ts"; | |
import * as gql from "https://esm.sh/[email protected]"; | ||
import { parseJSON } from "./nostr.ts/_helper.ts"; | ||
import { PublicKey } from "./nostr.ts/key.ts"; | ||
import { NostrEvent, NostrFilters, verifyEvent } from "./nostr.ts/nostr.ts"; | ||
import { NostrEvent, NostrFilters, NostrKind, verifyEvent } from "./nostr.ts/nostr.ts"; | ||
import { PolicyResolver } from "./resolvers/policy.ts"; | ||
|
||
const schema = gql.buildSchema(gql.print(typeDefs)); | ||
|
||
export type DefaultPolicy = { | ||
allowed_kinds: "all" | "none" | NostrKind[]; | ||
}; | ||
|
||
export async function run(args: { | ||
port: number; | ||
admin?: PublicKey; | ||
password: string; | ||
default_policy: DefaultPolicy; | ||
}) { | ||
const connections = new Map<WebSocket, Map<string, NostrFilters>>(); | ||
|
||
|
@@ -36,19 +42,26 @@ export async function run(args: { | |
connections, | ||
}), | ||
); | ||
const resolvePolicyByKind = PolicyResolver(args.default_policy); | ||
const mutation_resolver = Mutation(resolvePolicyByKind); | ||
return { | ||
server, | ||
url: `ws://${await hostname}:${port}`, | ||
shutdown: async () => { | ||
await server.shutdown(); | ||
}, | ||
set_policy: Mutation.set_policy, | ||
set_policy: mutation_resolver.set_policy, | ||
get_policy: (kind: NostrKind) => { | ||
return resolvePolicyByKind(kind); | ||
}, | ||
default_policy: args.default_policy, | ||
}; | ||
} | ||
|
||
const root_handler = (args: { | ||
password: string; | ||
connections: Map<WebSocket, Map<string, NostrFilters>>; | ||
default_policy: DefaultPolicy; | ||
}) => | ||
async (req: Request, info: Deno.ServeHandlerInfo) => { | ||
console.log(info.remoteAddr); | ||
|
@@ -58,7 +71,7 @@ async (req: Request, info: Deno.ServeHandlerInfo) => { | |
return graphql_handler(password)(req); | ||
} | ||
if (pathname == "/") { | ||
return ws_handler(connections)(req); | ||
return ws_handler(args)(req); | ||
} | ||
const resp = new Response(render(Error404()), { status: 404 }); | ||
resp.headers.set("content-type", "html"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.