Files
speckle-server/packages/frontend-2/middleware/thread.ts
T
Kristaps Fabians Geikins c3f13d4e66 fix: multiple FE2 and server speed improvements, mainly focusing on the project page (#1975)
* introduced app cache & optimized /downloads

* added redis cache storage

* optimizing latest thread retrieval

* more dataloaders

* undid debug stuff

* deployment changes

* minor change to reqTouched

* connectorTag parallel resolution

* added redis key prefix

* gqlgen cleanup

* Amend network policy to allow egress to Redis

---------

Co-authored-by: Iain Sproat <68657+iainsproat@users.noreply.github.com>
2024-01-22 11:08:53 +02:00

51 lines
1.2 KiB
TypeScript

import { useApolloClientFromNuxt } from '~/lib/common/composables/graphql'
import { graphql } from '~/lib/common/generated/gql'
import { convertThrowIntoFetchResult } from '~/lib/common/helpers/graphql'
import { getLinkToThread } from '~/lib/viewer/helpers/comments'
const resolveLinkQuery = graphql(`
query ResolveCommentLink($commentId: String!, $projectId: String!) {
comment(id: $commentId, streamId: $projectId) {
...LinkableComment
}
}
`)
export default defineNuxtRouteMiddleware(async (to) => {
const client = useApolloClientFromNuxt()
const threadId = to.params.threadId as string
const projectId = to.params.id as string
const res = await client
.query({
query: resolveLinkQuery,
variables: {
commentId: threadId,
projectId
}
})
.catch(convertThrowIntoFetchResult)
const comment = res.data?.comment
if (!comment) {
return abortNavigation(
createError({
message: 'Comment thread not found',
statusCode: 404
})
)
}
const link = getLinkToThread(projectId, comment)
if (!link) {
return abortNavigation(
createError({
message: 'Comment thread not found',
statusCode: 404
})
)
}
return navigateTo(link)
})