mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-23 20:18:42 +08:00
@@ -47,9 +47,14 @@ export class DocRpcController {
|
|||||||
@Get('/workspaces/:workspaceId/docs/:docId/markdown')
|
@Get('/workspaces/:workspaceId/docs/:docId/markdown')
|
||||||
async getDocMarkdown(
|
async getDocMarkdown(
|
||||||
@Param('workspaceId') workspaceId: string,
|
@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) {
|
if (!result) {
|
||||||
throw new NotFound('Doc not found');
|
throw new NotFound('Doc not found');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -269,7 +269,11 @@ test('should return doc markdown success', async t => {
|
|||||||
user,
|
user,
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await docReader.getDocMarkdown(workspace.id, docSnapshot.id);
|
const result = await docReader.getDocMarkdown(
|
||||||
|
workspace.id,
|
||||||
|
docSnapshot.id,
|
||||||
|
false
|
||||||
|
);
|
||||||
t.snapshot(result);
|
t.snapshot(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -279,6 +283,10 @@ test('should read markdown return null when doc not exists', async t => {
|
|||||||
name: '',
|
name: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await docReader.getDocMarkdown(workspace.id, randomUUID());
|
const result = await docReader.getDocMarkdown(
|
||||||
|
workspace.id,
|
||||||
|
randomUUID(),
|
||||||
|
false
|
||||||
|
);
|
||||||
t.is(result, null);
|
t.is(result, null);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -389,7 +389,11 @@ test('should return doc markdown success', async t => {
|
|||||||
user,
|
user,
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await docReader.getDocMarkdown(workspace.id, docSnapshot.id);
|
const result = await docReader.getDocMarkdown(
|
||||||
|
workspace.id,
|
||||||
|
docSnapshot.id,
|
||||||
|
false
|
||||||
|
);
|
||||||
t.snapshot(result);
|
t.snapshot(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -401,6 +405,10 @@ test('should read markdown return null when doc not exists', async t => {
|
|||||||
name: '',
|
name: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await docReader.getDocMarkdown(workspace.id, randomUUID());
|
const result = await docReader.getDocMarkdown(
|
||||||
|
workspace.id,
|
||||||
|
randomUUID(),
|
||||||
|
false
|
||||||
|
);
|
||||||
t.is(result, null);
|
t.is(result, null);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -67,7 +67,8 @@ export abstract class DocReader {
|
|||||||
|
|
||||||
abstract getDocMarkdown(
|
abstract getDocMarkdown(
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
docId: string
|
docId: string,
|
||||||
|
aiEditable: boolean
|
||||||
): Promise<DocMarkdown | null>;
|
): Promise<DocMarkdown | null>;
|
||||||
|
|
||||||
abstract getDocDiff(
|
abstract getDocDiff(
|
||||||
@@ -184,13 +185,19 @@ export class DatabaseDocReader extends DocReader {
|
|||||||
|
|
||||||
async getDocMarkdown(
|
async getDocMarkdown(
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
docId: string
|
docId: string,
|
||||||
|
aiEditable: boolean
|
||||||
): Promise<DocMarkdown | null> {
|
): Promise<DocMarkdown | null> {
|
||||||
const doc = await this.workspace.getDoc(workspaceId, docId);
|
const doc = await this.workspace.getDoc(workspaceId, docId);
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return parseDocToMarkdownFromDocSnapshot(workspaceId, docId, doc.bin);
|
return parseDocToMarkdownFromDocSnapshot(
|
||||||
|
workspaceId,
|
||||||
|
docId,
|
||||||
|
doc.bin,
|
||||||
|
aiEditable
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDocDiff(
|
async getDocDiff(
|
||||||
@@ -328,9 +335,10 @@ export class RpcDocReader extends DatabaseDocReader {
|
|||||||
|
|
||||||
override async getDocMarkdown(
|
override async getDocMarkdown(
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
docId: string
|
docId: string,
|
||||||
|
aiEditable: boolean
|
||||||
): Promise<DocMarkdown | null> {
|
): 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);
|
const accessToken = this.crypto.sign(docId);
|
||||||
try {
|
try {
|
||||||
const res = await this.fetch(accessToken, url, 'GET');
|
const res = await this.fetch(accessToken, url, 'GET');
|
||||||
@@ -349,7 +357,7 @@ export class RpcDocReader extends DatabaseDocReader {
|
|||||||
err
|
err
|
||||||
);
|
);
|
||||||
// fallback to database doc reader if the error is not user friendly, like network error
|
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ export const buildContentGetter = (ac: AccessController, doc: DocReader) => {
|
|||||||
.doc(docId)
|
.doc(docId)
|
||||||
.can('Doc.Read');
|
.can('Doc.Read');
|
||||||
if (!canAccess) return undefined;
|
if (!canAccess) return undefined;
|
||||||
const content = await doc.getFullDocContent(options.workspace, docId);
|
const content = await doc.getDocMarkdown(options.workspace, docId, true);
|
||||||
return content?.summary.trim() || undefined;
|
return content?.markdown.trim() || undefined;
|
||||||
};
|
};
|
||||||
return getDocContent;
|
return getDocContent;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -47,7 +47,11 @@ export const buildDocContentGetter = (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = await docReader.getDocMarkdown(options.workspace, docId);
|
const content = await docReader.getDocMarkdown(
|
||||||
|
options.workspace,
|
||||||
|
docId,
|
||||||
|
true
|
||||||
|
);
|
||||||
if (!content) {
|
if (!content) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user