mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
@@ -47,9 +47,14 @@ export class DocRpcController {
|
||||
@Get('/workspaces/:workspaceId/docs/:docId/markdown')
|
||||
async getDocMarkdown(
|
||||
@Param('workspaceId') workspaceId: string,
|
||||
@Param('docId') docId: string
|
||||
@Param('docId') docId: string,
|
||||
@Query('aiEditable') aiEditable?: string
|
||||
) {
|
||||
const result = await this.docReader.getDocMarkdown(workspaceId, docId);
|
||||
const result = await this.docReader.getDocMarkdown(
|
||||
workspaceId,
|
||||
docId,
|
||||
aiEditable === 'true'
|
||||
);
|
||||
if (!result) {
|
||||
throw new NotFound('Doc not found');
|
||||
}
|
||||
|
||||
@@ -269,7 +269,11 @@ test('should return doc markdown success', async t => {
|
||||
user,
|
||||
});
|
||||
|
||||
const result = await docReader.getDocMarkdown(workspace.id, docSnapshot.id);
|
||||
const result = await docReader.getDocMarkdown(
|
||||
workspace.id,
|
||||
docSnapshot.id,
|
||||
false
|
||||
);
|
||||
t.snapshot(result);
|
||||
});
|
||||
|
||||
@@ -279,6 +283,10 @@ test('should read markdown return null when doc not exists', async t => {
|
||||
name: '',
|
||||
});
|
||||
|
||||
const result = await docReader.getDocMarkdown(workspace.id, randomUUID());
|
||||
const result = await docReader.getDocMarkdown(
|
||||
workspace.id,
|
||||
randomUUID(),
|
||||
false
|
||||
);
|
||||
t.is(result, null);
|
||||
});
|
||||
|
||||
@@ -389,7 +389,11 @@ test('should return doc markdown success', async t => {
|
||||
user,
|
||||
});
|
||||
|
||||
const result = await docReader.getDocMarkdown(workspace.id, docSnapshot.id);
|
||||
const result = await docReader.getDocMarkdown(
|
||||
workspace.id,
|
||||
docSnapshot.id,
|
||||
false
|
||||
);
|
||||
t.snapshot(result);
|
||||
});
|
||||
|
||||
@@ -401,6 +405,10 @@ test('should read markdown return null when doc not exists', async t => {
|
||||
name: '',
|
||||
});
|
||||
|
||||
const result = await docReader.getDocMarkdown(workspace.id, randomUUID());
|
||||
const result = await docReader.getDocMarkdown(
|
||||
workspace.id,
|
||||
randomUUID(),
|
||||
false
|
||||
);
|
||||
t.is(result, null);
|
||||
});
|
||||
|
||||
@@ -67,7 +67,8 @@ export abstract class DocReader {
|
||||
|
||||
abstract getDocMarkdown(
|
||||
workspaceId: string,
|
||||
docId: string
|
||||
docId: string,
|
||||
aiEditable: boolean
|
||||
): Promise<DocMarkdown | null>;
|
||||
|
||||
abstract getDocDiff(
|
||||
@@ -184,13 +185,19 @@ export class DatabaseDocReader extends DocReader {
|
||||
|
||||
async getDocMarkdown(
|
||||
workspaceId: string,
|
||||
docId: string
|
||||
docId: string,
|
||||
aiEditable: boolean
|
||||
): Promise<DocMarkdown | null> {
|
||||
const doc = await this.workspace.getDoc(workspaceId, docId);
|
||||
if (!doc) {
|
||||
return null;
|
||||
}
|
||||
return parseDocToMarkdownFromDocSnapshot(workspaceId, docId, doc.bin);
|
||||
return parseDocToMarkdownFromDocSnapshot(
|
||||
workspaceId,
|
||||
docId,
|
||||
doc.bin,
|
||||
aiEditable
|
||||
);
|
||||
}
|
||||
|
||||
async getDocDiff(
|
||||
@@ -328,9 +335,10 @@ export class RpcDocReader extends DatabaseDocReader {
|
||||
|
||||
override async getDocMarkdown(
|
||||
workspaceId: string,
|
||||
docId: string
|
||||
docId: string,
|
||||
aiEditable: boolean
|
||||
): Promise<DocMarkdown | null> {
|
||||
const url = `${this.config.docService.endpoint}/rpc/workspaces/${workspaceId}/docs/${docId}/markdown`;
|
||||
const url = `${this.config.docService.endpoint}/rpc/workspaces/${workspaceId}/docs/${docId}/markdown?aiEditable=${aiEditable}`;
|
||||
const accessToken = this.crypto.sign(docId);
|
||||
try {
|
||||
const res = await this.fetch(accessToken, url, 'GET');
|
||||
@@ -349,7 +357,7 @@ export class RpcDocReader extends DatabaseDocReader {
|
||||
err
|
||||
);
|
||||
// fallback to database doc reader if the error is not user friendly, like network error
|
||||
return await super.getDocMarkdown(workspaceId, docId);
|
||||
return await super.getDocMarkdown(workspaceId, docId, aiEditable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user