feat(server): synthetic root doc (#14794)

This commit is contained in:
DarkSky
2026-04-06 17:16:34 +08:00
committed by GitHub
parent 64149d909a
commit 193ec14ad3
35 changed files with 1784 additions and 409 deletions
@@ -10,8 +10,12 @@ import { HttpConnection } from './http';
interface CloudDocStorageOptions extends DocStorageOptions {
serverBaseUrl: string;
publicRootDocId?: string;
}
const isShareModePrivateSystemDoc = (docId: string) =>
docId.startsWith('db$') || docId.startsWith('userdata$');
export class StaticCloudDocStorage extends DocStorageBase<CloudDocStorageOptions> {
static readonly identifier = 'StaticCloudDocStorage';
@@ -46,15 +50,26 @@ export class StaticCloudDocStorage extends DocStorageBase<CloudDocStorageOptions
docId: string
): Promise<DocRecord | null> {
try {
const arrayBuffer = await this.connection.fetchArrayBuffer(
`/api/workspaces/${this.spaceId}/docs/${docId}`,
{
priority: 'high',
headers: {
Accept: 'application/octet-stream', // this is necessary for ios native fetch to return arraybuffer
},
}
);
if (
this.options.publicRootDocId &&
docId !== this.spaceId &&
isShareModePrivateSystemDoc(docId)
) {
return null;
}
const path =
docId === this.spaceId && this.options.publicRootDocId
? `/api/workspaces/${this.spaceId}/public-docs/${this.options.publicRootDocId}/root-doc`
: this.options.publicRootDocId
? `/api/workspaces/${this.spaceId}/public-docs/${docId}`
: `/api/workspaces/${this.spaceId}/docs/${docId}`;
const arrayBuffer = await this.connection.fetchArrayBuffer(path, {
priority: 'high',
headers: {
Accept: 'application/octet-stream', // this is necessary for ios native fetch to return arraybuffer
},
});
if (!arrayBuffer) {
return null;
}