fix(github): broken images in issue description (#7534)
Some checks are pending
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions

Signed-off-by: Dakshesh Jain <dakshesh.jain14@gmail.com>
This commit is contained in:
Dakshesh Jain 2025-01-05 21:13:47 +05:30 committed by GitHub
parent 5becc4137f
commit aaf2c14e7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 48 additions and 3 deletions

View File

@ -140,7 +140,22 @@ export const storeNodes: Record<string, NodeProcessor> = {
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(
'![' +

View File

@ -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&reg;:'
@ -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
}
}
}

View File

@ -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
)
}