Fix images in note rich text (#6550)
## Before <img width="439" alt="Screenshot 2024-08-06 at 11 20 06" src="https://github.com/user-attachments/assets/d2aa9411-cdf4-4457-8997-7cbecb8fe7e3"> ## After <img width="501" alt="Screenshot 2024-08-06 at 11 20 09" src="https://github.com/user-attachments/assets/a5a68fff-1542-4b62-939c-50070f15b692">
This commit is contained in:
@ -0,0 +1,57 @@
|
||||
import { QueryResultGetterHandlerInterface } from 'src/engine/api/graphql/workspace-query-runner/factories/query-result-getters/interfaces/query-result-getter-handler.interface';
|
||||
|
||||
import { FileService } from 'src/engine/core-modules/file/services/file.service';
|
||||
import { NoteWorkspaceEntity } from 'src/modules/note/standard-objects/note.workspace-entity';
|
||||
import { TaskWorkspaceEntity } from 'src/modules/task/standard-objects/task.workspace-entity';
|
||||
|
||||
type RichTextBlock = Record<string, any>;
|
||||
|
||||
type RichTextBody = RichTextBlock[];
|
||||
|
||||
export class ActivityQueryResultGetterHandler
|
||||
implements QueryResultGetterHandlerInterface
|
||||
{
|
||||
constructor(private readonly fileService: FileService) {}
|
||||
|
||||
async handle(
|
||||
activity: TaskWorkspaceEntity | NoteWorkspaceEntity,
|
||||
workspaceId: string,
|
||||
): Promise<TaskWorkspaceEntity | NoteWorkspaceEntity> {
|
||||
if (!activity.id || !activity.body) {
|
||||
return activity;
|
||||
}
|
||||
|
||||
const body: RichTextBody = JSON.parse(activity.body);
|
||||
|
||||
const bodyWithSignedPayload = await Promise.all(
|
||||
body.map(async (block: RichTextBlock) => {
|
||||
if (block.type !== 'image' || !block.props.url) {
|
||||
return block;
|
||||
}
|
||||
|
||||
const imageProps = block.props;
|
||||
const imageUrl = new URL(imageProps.url);
|
||||
|
||||
imageUrl.searchParams.delete('token');
|
||||
|
||||
const signedPayload = await this.fileService.encodeFileToken({
|
||||
note_block_id: block.id,
|
||||
workspace_id: workspaceId,
|
||||
});
|
||||
|
||||
return {
|
||||
...block,
|
||||
props: {
|
||||
...imageProps,
|
||||
url: `${imageUrl.toString()}?token=${signedPayload}`,
|
||||
},
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
return {
|
||||
...activity,
|
||||
body: JSON.stringify(bodyWithSignedPayload),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,13 +1,17 @@
|
||||
import { QueryResultGetterHandlerInterface } from 'src/engine/api/graphql/workspace-query-runner/factories/query-result-getters/interfaces/query-result-getter-handler.interface';
|
||||
|
||||
import { FileService } from 'src/engine/core-modules/file/services/file.service';
|
||||
import { AttachmentWorkspaceEntity } from 'src/modules/attachment/standard-objects/attachment.workspace-entity';
|
||||
|
||||
export class AttachmentQueryResultGetterHandler
|
||||
implements QueryResultGetterHandlerInterface
|
||||
{
|
||||
constructor(private readonly fileService: FileService) {}
|
||||
|
||||
async handle(attachment: any, workspaceId: string): Promise<any> {
|
||||
async handle(
|
||||
attachment: AttachmentWorkspaceEntity,
|
||||
workspaceId: string,
|
||||
): Promise<AttachmentWorkspaceEntity> {
|
||||
if (!attachment.id || !attachment?.fullPath) {
|
||||
return attachment;
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ export class PersonQueryResultGetterHandler
|
||||
async handle(
|
||||
person: PersonWorkspaceEntity,
|
||||
workspaceId: string,
|
||||
): Promise<any> {
|
||||
): Promise<PersonWorkspaceEntity> {
|
||||
if (!person.id || !person?.avatarUrl) {
|
||||
return person;
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ export class WorkspaceMemberQueryResultGetterHandler
|
||||
async handle(
|
||||
workspaceMember: WorkspaceMemberWorkspaceEntity,
|
||||
workspaceId: string,
|
||||
): Promise<any> {
|
||||
): Promise<WorkspaceMemberWorkspaceEntity> {
|
||||
if (!workspaceMember.id || !workspaceMember?.avatarUrl) {
|
||||
return workspaceMember;
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ import { Injectable } from '@nestjs/common';
|
||||
import { QueryResultGetterHandlerInterface } from 'src/engine/api/graphql/workspace-query-runner/factories/query-result-getters/interfaces/query-result-getter-handler.interface';
|
||||
import { ObjectMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/object-metadata.interface';
|
||||
|
||||
import { ActivityQueryResultGetterHandler } from 'src/engine/api/graphql/workspace-query-runner/factories/query-result-getters/handlers/activity-query-result-getter.handler';
|
||||
import { AttachmentQueryResultGetterHandler } from 'src/engine/api/graphql/workspace-query-runner/factories/query-result-getters/handlers/attachment-query-result-getter.handler';
|
||||
import { PersonQueryResultGetterHandler } from 'src/engine/api/graphql/workspace-query-runner/factories/query-result-getters/handlers/person-query-result-getter.handler';
|
||||
import { WorkspaceMemberQueryResultGetterHandler } from 'src/engine/api/graphql/workspace-query-runner/factories/query-result-getters/handlers/workspace-member-query-result-getter.handler';
|
||||
@ -24,6 +25,8 @@ export class QueryResultGettersFactory {
|
||||
'workspaceMember',
|
||||
new WorkspaceMemberQueryResultGetterHandler(this.fileService),
|
||||
],
|
||||
['note', new ActivityQueryResultGetterHandler(this.fileService)],
|
||||
['task', new ActivityQueryResultGetterHandler(this.fileService)],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user