diff --git a/packages/text/src/markdown/serializer.ts b/packages/text/src/markdown/serializer.ts index 6a11631e2d..f3d8fa58fc 100644 --- a/packages/text/src/markdown/serializer.ts +++ b/packages/text/src/markdown/serializer.ts @@ -140,7 +140,22 @@ export const storeNodes: Record = { image: (state, node) => { const attrs = nodeAttrs(node) - if (attrs['file-id'] != null) { + if (attrs.token != null && attrs['file-id'] != null) { + // Convert image to token format + state.write( + '![' + + state.esc(`${attrs.alt ?? ''}`) + + '](' + + (state.imageUrl + + `${attrs['file-id']}` + + `?file=${attrs['file-id']}` + + (attrs.width != null ? '&width=' + state.esc(`${attrs.width}`) : '') + + (attrs.height != null ? '&height=' + state.esc(`${attrs.height}`) : '') + + (attrs.token != null ? '&token=' + state.esc(`${attrs.token}`) : '')) + + (attrs.title != null ? ' ' + state.quote(`${attrs.title}`) : '') + + ')' + ) + } else if (attrs['file-id'] != null) { // Convert image to fileid format state.write( '![' + diff --git a/services/github/pod-github/src/sync/guest.ts b/services/github/pod-github/src/sync/guest.ts index 9c38dc064e..f4baacf87f 100644 --- a/services/github/pod-github/src/sync/guest.ts +++ b/services/github/pod-github/src/sync/guest.ts @@ -2,10 +2,11 @@ // Copyright © 2023 Hardcore Engineering Inc. // -import { Branding, TxOperations, WorkspaceIdWithUrl } from '@hcengineering/core' +import { Branding, generateId, TxOperations, WorkspaceIdWithUrl } from '@hcengineering/core' import { MarkupMarkType, MarkupNode, MarkupNodeType, traverseMarkupNode } from '@hcengineering/text' import { getPublicLink } from '@hcengineering/server-guest-resources' import { Task } from '@hcengineering/task' +import { generateToken } from '@hcengineering/server-token' const githubLinkText = process.env.LINK_TEXT ?? 'Huly®:' @@ -54,6 +55,7 @@ export async function appendGuestLink ( const publicLink = await getPublicLink(doc, client, workspace, false, branding) await stripGuestLink(markdown) appendGuestLinkToModel(markdown, publicLink, doc.identifier) + appendGuestLinkToImage(markdown, workspace) } export function appendGuestLinkToModel (markdown: MarkupNode, publicLink: string, identifier: string): void { @@ -76,3 +78,31 @@ export function appendGuestLinkToModel (markdown: MarkupNode, publicLink: string } ] } + +function findImageTags (node: MarkupNode): MarkupNode[] { + if (node.type === MarkupNodeType.paragraph) { + return node.content?.flatMap(findImageTags) ?? [] + } + if (node.type === MarkupNodeType.image) { + return [node] + } + return [] +} + +export function appendGuestLinkToImage (markdown: MarkupNode, workspace: WorkspaceIdWithUrl): void { + const imageTags: MarkupNode[] = markdown.content?.flatMap(findImageTags) ?? [] + + if (imageTags.length === 0) { + return + } + + const id = generateId() + const token = generateToken(id, workspace, { linkId: id, guest: 'true' }) + + for (const imageTag of imageTags) { + const src = imageTag.attrs?.src + if (src !== undefined && imageTag.attrs !== undefined) { + imageTag.attrs.token = token + } + } +} diff --git a/services/github/pod-github/src/worker.ts b/services/github/pod-github/src/worker.ts index 45e168a622..6ffd45a024 100644 --- a/services/github/pod-github/src/worker.ts +++ b/services/github/pod-github/src/worker.ts @@ -191,7 +191,7 @@ export class GithubWorker implements IntegrationManager { text ?? '', concatLink(this.getBranding()?.front ?? config.FrontURL, `/browse/?workspace=${this.workspace.name}`), // TODO storage URL - concatLink(this.getBranding()?.front ?? config.FrontURL, `/files?workspace=${this.workspace.name}&file=`), + concatLink(this.getBranding()?.front ?? config.FrontURL, `/files/${this.workspace.name}/`), preprocessor ) }