Skip to content

Commit

Permalink
Site serves correct group for site, group v query
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvicenti committed Sep 21, 2023
1 parent 456ceb6 commit c183d4b
Show file tree
Hide file tree
Showing 11 changed files with 410 additions and 22 deletions.
2 changes: 2 additions & 0 deletions frontend/apps/site/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Daemon,
Networking,
Groups,
Website,
} from '@mintter/shared'

const loggingInterceptor: Interceptor = (next) => async (req) => {
Expand Down Expand Up @@ -82,3 +83,4 @@ export const accountsClient = createPromiseClient(Accounts, transport)
export const groupsClient = createPromiseClient(Groups, transport)
export const daemonClient = createPromiseClient(Daemon, transport)
export const networkingClient = createPromiseClient(Networking, transport)
export const websiteClient = createPromiseClient(Website, transport)
4 changes: 3 additions & 1 deletion frontend/apps/site/pages/[pathName].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ export const getServerSideProps: GetServerSideProps<
EveryPageProps & PubSlugPageProps
> = async (context) => {
const pathName = (context.params?.pathName as string) || ''
const {groupEid} = await getSiteGroup()
const {groupEid, version} = await getSiteGroup()
if (!groupEid) return {notFound: true}
return await getGroupPathNamePageProps({
groupEid,
version,
pathName,
context,
})
Expand Down
6 changes: 3 additions & 3 deletions frontend/apps/site/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export default function HomePage(props: GroupPageProps) {
export const getServerSideProps: GetServerSideProps<
EveryPageProps & PubSlugPageProps
> = async (context) => {
const {groupEid} = await getSiteGroup()
console.log('serer side', context.query)
const {groupEid, version} = await getSiteGroup()
if (!groupEid) return {notFound: true}
const view = getGroupView(context.query.view)
return await getGroupPageProps({groupEid, context, view})
return await getGroupPageProps({groupEid, version, context, view})
}
17 changes: 14 additions & 3 deletions frontend/apps/site/server/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ export function getGroupView(input: string | string[] | undefined): GroupView {

export async function getGroupPathNamePageProps({
groupEid,
version,
pathName,
context,
}: {
groupEid: string
version: string | undefined
pathName: string
context: GetServerSidePropsContext
}) {
Expand All @@ -34,8 +36,13 @@ export async function getGroupPathNamePageProps({
'x-mintter-site-p2p-addresses',
peerInfo.addrs.join(','),
)
const group = await helpers.group.get.fetch({groupId})
const groupContent = await helpers.group.listContent.fetch({groupId})
const {query} = context
const groupVersion = query.v ? String(query.v) : version
const group = await helpers.group.get.fetch({groupId, version: groupVersion})
const groupContent = await helpers.group.listContent.fetch({
groupId,
version: groupVersion,
})

return {
props: await getPageProps(helpers, {pathName, groupId}),
Expand All @@ -44,17 +51,19 @@ export async function getGroupPathNamePageProps({

export async function getGroupPageProps({
groupEid,
version,
context,
view,
}: {
groupEid: string
version: string | undefined
context: GetServerSidePropsContext
view: GroupView
}) {
const {params, query} = context
const groupId = groupEid ? createHmId('g', groupEid) : undefined

let version = query.v ? String(query.v) : null
const groupVersion = query.v ? String(query.v) : version

setAllowAnyHostGetCORS(context.res)

Expand All @@ -64,9 +73,11 @@ export async function getGroupPageProps({

const groupRecord = await helpers.group.get.fetch({
groupId,
version: groupVersion,
})
const members = await helpers.group.listMembers.fetch({
groupId,
version: groupVersion,
})
await Promise.all(
members.map((member) =>
Expand Down
4 changes: 4 additions & 0 deletions frontend/apps/site/server/routers/_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,13 @@ const groupRouter = router({
.input(
z.object({
groupId: z.string(),
version: z.string().optional(),
}),
)
.query(async ({input}) => {
const list = await groupsClient.listContent({
id: input.groupId,
version: input.version,
})
const listedDocs = await Promise.all(
Object.entries(list.content).map(async ([pathName, pubUrl]) => {
Expand Down Expand Up @@ -281,11 +283,13 @@ const groupRouter = router({
.input(
z.object({
groupId: z.string(),
version: z.string().optional(),
}),
)
.query(async ({input}) => {
const list = await groupsClient.listMembers({
id: input.groupId,
version: input.version,
})
return Object.entries(list.members || {}).map(([account, role]) => ({
account,
Expand Down
11 changes: 5 additions & 6 deletions frontend/apps/site/server/site-info.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// const gatewayHostWithProtocol = process.env.HM_BASE_URL
// const gatewayHost = new URL(gatewayHostWithProtocol || '').hostname
import {websiteClient} from '../client'

export async function getSiteGroup(): Promise<{
groupEid: string
groupEid?: string
version?: string | null
}> {
// todo, query for site group
const siteInfo = await websiteClient.getSiteInfo({})
return {
groupEid: '8ctYvUJwv9kmpjCT4RjBeD',
version: null,
groupEid: siteInfo.groupId || undefined,
version: siteInfo.groupVersion || null,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// @generated by protoc-gen-connect-es v0.13.0 with parameter "target=ts,import_extension=none"
// @generated from file groups/v1alpha/website.proto (package com.mintter.groups.v1alpha, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import { GetSiteInfoRequest, InitializeServerRequest, InitializeServerResponse, PublicSiteInfo, PublishBlobsRequest, PublishBlobsResponse } from "./website_pb";
import { MethodKind } from "@bufbuild/protobuf";

/**
* API service exposed by the website server.
* It's exposed as gRPC over Libp2p.
*
* @generated from service com.mintter.groups.v1alpha.Website
*/
export const Website = {
typeName: "com.mintter.groups.v1alpha.Website",
methods: {
/**
* Gets the public information about the website.
* This information is also available as JSON over HTTP on `/.well-known/hypermedia-site`.
*
* @generated from rpc com.mintter.groups.v1alpha.Website.GetSiteInfo
*/
getSiteInfo: {
name: "GetSiteInfo",
I: GetSiteInfoRequest,
O: PublicSiteInfo,
kind: MethodKind.Unary,
},
/**
* Initializes the server to become a website for a specific group.
*
* @generated from rpc com.mintter.groups.v1alpha.Website.InitializeServer
*/
initializeServer: {
name: "InitializeServer",
I: InitializeServerRequest,
O: InitializeServerResponse,
kind: MethodKind.Unary,
},
/**
* Publishes blobs to the website.
*
* @generated from rpc com.mintter.groups.v1alpha.Website.PublishBlobs
*/
publishBlobs: {
name: "PublishBlobs",
I: PublishBlobsRequest,
O: PublishBlobsResponse,
kind: MethodKind.Unary,
},
}
} as const;

Loading

0 comments on commit c183d4b

Please sign in to comment.