mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
feat(server): add full content support for doc (#11149)
This commit is contained in:
@@ -183,6 +183,27 @@ test('should get doc content in json format', async t => {
|
||||
t.pass();
|
||||
});
|
||||
|
||||
test('should get full doc content in json format', async t => {
|
||||
const { app } = t.context;
|
||||
mock.method(t.context.databaseDocReader, 'getFullDocContent', async () => {
|
||||
return {
|
||||
title: 'test title',
|
||||
summary: 'test summary',
|
||||
};
|
||||
});
|
||||
|
||||
const docId = randomUUID();
|
||||
await app
|
||||
.GET(`/rpc/workspaces/${workspace.id}/docs/${docId}/content?full=true`)
|
||||
.set('x-access-token', t.context.crypto.sign(docId))
|
||||
.expect({
|
||||
title: 'test title',
|
||||
summary: 'test summary',
|
||||
})
|
||||
.expect(200);
|
||||
t.pass();
|
||||
});
|
||||
|
||||
test('should 404 when workspace content not found', async t => {
|
||||
const { app } = t.context;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
RawBody,
|
||||
Res,
|
||||
} from '@nestjs/common';
|
||||
import { Args } from '@nestjs/graphql';
|
||||
import type { Response } from 'express';
|
||||
|
||||
import { NotFound, SkipThrottle } from '../../base';
|
||||
@@ -76,9 +77,12 @@ export class DocRpcController {
|
||||
@Get('/workspaces/:workspaceId/docs/:docId/content')
|
||||
async getDocContent(
|
||||
@Param('workspaceId') workspaceId: string,
|
||||
@Param('docId') docId: string
|
||||
@Param('docId') docId: string,
|
||||
@Args('full', { nullable: true }) fullContent?: boolean
|
||||
) {
|
||||
const content = await this.docReader.getDocContent(workspaceId, docId);
|
||||
const content = fullContent
|
||||
? await this.docReader.getFullDocContent(workspaceId, docId)
|
||||
: await this.docReader.getDocContent(workspaceId, docId);
|
||||
if (!content) {
|
||||
throw new NotFound('Doc not found');
|
||||
}
|
||||
|
||||
@@ -347,9 +347,10 @@ export class RpcDocReader extends DatabaseDocReader {
|
||||
|
||||
protected override async getDocContentWithoutCache(
|
||||
workspaceId: string,
|
||||
docId: string
|
||||
docId: string,
|
||||
fullContent = false
|
||||
): Promise<PageDocContent | null> {
|
||||
const url = `${this.config.docService.endpoint}/rpc/workspaces/${workspaceId}/docs/${docId}/content`;
|
||||
const url = `${this.config.docService.endpoint}/rpc/workspaces/${workspaceId}/docs/${docId}/content?full=${fullContent}`;
|
||||
const accessToken = this.crypto.sign(docId);
|
||||
try {
|
||||
const res = await this.fetch(accessToken, url, 'GET');
|
||||
@@ -366,7 +367,11 @@ export class RpcDocReader extends DatabaseDocReader {
|
||||
`Failed to fetch doc content ${url}, fallback to database doc reader`,
|
||||
err
|
||||
);
|
||||
return await super.getDocContentWithoutCache(workspaceId, docId);
|
||||
return await super.getDocContentWithoutCache(
|
||||
workspaceId,
|
||||
docId,
|
||||
fullContent
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user