feat(core): support share edgeless mode (#4856)

Close #3287

<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at d3fdf86</samp>

### Summary
📄🚀🔗

<!--
1.  📄 - This emoji represents the page and edgeless modes of sharing a page, as well as the GraphQL operations and types related to public pages.
2.  🚀 - This emoji represents the functionality of publishing and revoking public pages, as well as the confirmation modal and the notifications for the user.
3.  🔗 - This emoji represents the sharing URL and the query parameter for the share mode, as well as the hooks and functions that generate and use the URL.
-->
This pull request adds a feature to the frontend component of AFFiNE that allows the user to share a page in either `page` or `edgeless` mode, which affects the appearance and functionality of the page. It also adds the necessary GraphQL operations, types, and schema to support this feature in the backend, and updates the tests and the storybook stories accordingly.

*  Modify the `useIsSharedPage` hook to accept an optional `shareMode` argument and use the `getWorkspacePublicPagesQuery`, `publishPageMutation`, and `revokePublicPageMutation` from `@affine/graphql`
This commit is contained in:
JimmFly
2023-11-15 07:49:25 +00:00
committed by LongYinan
parent e7e617a791
commit ddd7cab414
39 changed files with 800 additions and 332 deletions

View File

@@ -10,10 +10,17 @@ const logger = new DebugLogger('affine:cloud');
const hashMap = new Map<string, ArrayBuffer>();
type DocPublishMode = 'edgeless' | 'page';
export type CloudDoc = {
arrayBuffer: ArrayBuffer;
publishMode: DocPublishMode;
};
export async function downloadBinaryFromCloud(
rootGuid: string,
pageGuid: string
): Promise<boolean | ArrayBuffer> {
): Promise<CloudDoc | boolean> {
if (hashMap.has(`${rootGuid}/${pageGuid}`)) {
return true;
}
@@ -25,17 +32,22 @@ export async function downloadBinaryFromCloud(
}
);
if (response.ok) {
const publishMode = (response.headers.get('publish-mode') ||
'page') as DocPublishMode;
const arrayBuffer = await response.arrayBuffer();
hashMap.set(`${rootGuid}/${pageGuid}`, arrayBuffer);
return arrayBuffer;
// return both arrayBuffer and publish mode
return { arrayBuffer, publishMode };
}
return false;
}
async function downloadBinary(rootGuid: string, doc: Doc) {
const buffer = await downloadBinaryFromCloud(rootGuid, doc.guid);
if (typeof buffer !== 'boolean') {
Y.applyUpdate(doc, new Uint8Array(buffer), 'affine-cloud');
const response = await downloadBinaryFromCloud(rootGuid, doc.guid);
if (typeof response !== 'boolean') {
const { arrayBuffer } = response;
Y.applyUpdate(doc, new Uint8Array(arrayBuffer), 'affine-cloud');
}
}