Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat: support disable legacy cloud (#2006)

Himself65f6fb049ff2f8
diff --git a/apps/electron/scripts/generate-assets.mjs b/apps/electron/scripts/generate-assets.mjs
index 9c09f526a2..98c036a46d 100644
--- a/apps/electron/scripts/generate-assets.mjs
+++ b/apps/electron/scripts/generate-assets.mjs
@@ -34,6 +34,7 @@ if (process.platform === 'win32') {
$.prefix = '';
}
// step 1: build web (nextjs) dist
+process.env.ENABLE_LEGACY_PROVIDER = 'false';
cd(repoRootDir);
await $`yarn add`;
await $`yarn build`;
diff --git a/apps/web/.env.local.template b/apps/web/.env.local.template
index 7e6a0bf4f3..c4cbc43e06 100644
--- a/apps/web/.env.local.template
+++ b/apps/web/.env.local.template
@@ -17,6 +17,7 @@ EXPOSE_INTERNAL=1
ENABLE_DEBUG_PAGE=
ENABLE_SUBPAGE=
ENABLE_CHANGELOG=1
+ENABLE_LEGACY_PROVIDER=true
# Sentry
SENTRY_AUTH_TOKEN=
diff --git a/apps/web/preset.config.mjs b/apps/web/preset.config.mjs
index a617e45ab9..2a47a8ad7f 100644
--- a/apps/web/preset.config.mjs
+++ b/apps/web/preset.config.mjs
@@ -1,6 +1,9 @@
import 'dotenv/config';
const config = {
+ enableLegacyCloud: process.env.ENABLE_LEGACY_PROVIDER
+ ? process.env.ENABLE_LEGACY_PROVIDER === 'true'
+ : true,
enableBroadCastChannelProvider: Boolean(
process.env.ENABLE_BC_PROVIDER ?? '1'
),
diff --git a/apps/web/src/atoms/root.ts b/apps/web/src/atoms/root.ts
index d9be5caa44..5123975cd1 100644
--- a/apps/web/src/atoms/root.ts
+++ b/apps/web/src/atoms/root.ts
@@ -1,9 +1,11 @@
//#region async atoms that to load the real workspace data
import { DebugLogger } from '@affine/debug';
+import { config } from '@affine/env';
import {
rootCurrentWorkspaceIdAtom,
rootWorkspacesMetadataAtom,
} from '@affine/workspace/atom';
+import { WorkspaceFlavour } from '@affine/workspace/type';
import { assertExists } from '@blocksuite/store';
import { atom } from 'jotai';
@@ -19,9 +21,16 @@ export const workspacesAtom = atom<Promise<AllWorkspace[]>>(async get => {
const flavours: string[] = Object.values(WorkspacePlugins).map(
plugin => plugin.flavour
);
- const jotaiWorkspaces = get(rootWorkspacesMetadataAtom).filter(workspace =>
- flavours.includes(workspace.flavour)
- );
+ const jotaiWorkspaces = get(rootWorkspacesMetadataAtom)
+ .filter(
+ workspace => flavours.includes(workspace.flavour)
+ // TODO: remove this when we remove the legacy cloud
+ )
+ .filter(workspace =>
+ !config.enableLegacyCloud
+ ? workspace.flavour !== WorkspaceFlavour.AFFINE
+ : true
+ );
const workspaces = await Promise.all(
jotaiWorkspaces.map(workspace => {
const plugin =
diff --git a/apps/web/src/components/affine/workspace-setting-detail/panel/collaboration/index.tsx b/apps/web/src/components/affine/workspace-setting-detail/panel/collaboration/index.tsx
index 237f662c4b..fbe6491fb1 100644
--- a/apps/web/src/components/affine/workspace-setting-detail/panel/collaboration/index.tsx
+++ b/apps/web/src/components/affine/workspace-setting-detail/panel/collaboration/index.tsx
@@ -1,4 +1,5 @@
import { Button, IconButton, Menu, MenuItem, Wrapper } from '@affine/component';
+import { config } from '@affine/env';
import { useTranslation } from '@affine/i18n';
import { PermissionType } from '@affine/workspace/affine/api';
import type { AffineWorkspace, LocalWorkspace } from '@affine/workspace/type';
@@ -171,16 +172,18 @@ const LocalCollaborationPanel: React.FC<
return (
<>
<Wrapper marginBottom="42px">{t('Collaboration Description')}</Wrapper>
- <Button
- data-testid="local-workspace-enable-cloud-button"
- type="light"
- shape="circle"
- onClick={() => {
- setOpen(true);
- }}
- >
- {t('Enable AFFiNE Cloud')}
- </Button>
+ {config.enableLegacyCloud && (
+ <Button
+ data-testid="local-workspace-enable-cloud-button"
+ type="light"
+ shape="circle"
+ onClick={() => {
+ setOpen(true);
+ }}
+ >
+ {t('Enable AFFiNE Cloud')}
+ </Button>
+ )}
<TransformWorkspaceToAffineModal
open={open}
onClose={() => {
diff --git a/apps/web/src/components/affine/workspace-setting-detail/panel/publish/index.tsx b/apps/web/src/components/affine/workspace-setting-detail/panel/publish/index.tsx
index d0ccbe59ae..2e98b5aad4 100644
--- a/apps/web/src/components/affine/workspace-setting-detail/panel/publish/index.tsx
+++ b/apps/web/src/components/affine/workspace-setting-detail/panel/publish/index.tsx
@@ -5,6 +5,7 @@ import {
Input,
Wrapper,
} from '@affine/component';
+import { config } from '@affine/env';
import { useTranslation } from '@affine/i18n';
import type { AffineWorkspace, LocalWorkspace } from '@affine/workspace/type';
import { WorkspaceFlavour } from '@affine/workspace/type';
@@ -120,16 +121,18 @@ const PublishPanelLocal: React.FC<PublishPanelLocalProps> = ({
>
{t('Publishing')}
</Box>
- <Button
- data-testid="publish-enable-affine-cloud-button"
- type="light"
- shape="circle"
- onClick={() => {
- setOpen(true);
- }}
- >
- {t('Enable AFFiNE Cloud')}
- </Button>
+ {config.enableLegacyCloud && (
+ <Button
+ data-testid="publish-enable-affine-cloud-button"
+ type="light"
+ shape="circle"
+ onClick={() => {
+ setOpen(true);
+ }}
+ >
+ {t('Enable AFFiNE Cloud')}
+ </Button>
+ )}
<EnableAffineCloudModal
open={open}
onClose={() => {
diff --git a/apps/web/src/components/blocksuite/workspace-header/header-right-items/SyncUser.tsx b/apps/web/src/components/blocksuite/workspace-header/header-right-items/SyncUser.tsx
index 55ee14df47..f3175deb71 100644
--- a/apps/web/src/components/blocksuite/workspace-header/header-right-items/SyncUser.tsx
+++ b/apps/web/src/components/blocksuite/workspace-header/header-right-items/SyncUser.tsx
@@ -1,4 +1,5 @@
import { displayFlex, IconButton, styled, Tooltip } from '@affine/component';
+import { config } from '@affine/env';
import { useTranslation } from '@affine/i18n';
import {
getLoginStorage,
@@ -80,6 +81,10 @@ export const SyncUser = () => {
const { t } = useTranslation();
const transformWorkspace = useTransformWorkspace();
+ if (!config.enableLegacyCloud) {
+ return null;
+ }
+
if (status === 'offline') {
return (
<Tooltip
diff --git a/apps/web/src/components/pure/footer/index.tsx b/apps/web/src/components/pure/footer/index.tsx
index 404bf8aaf3..ff3362b956 100644
--- a/apps/web/src/components/pure/footer/index.tsx
+++ b/apps/web/src/components/pure/footer/index.tsx
@@ -1,6 +1,7 @@
import { FlexWrapper } from '@affine/component';
import { IconButton } from '@affine/component';
import { Tooltip } from '@affine/component';
+import { config } from '@affine/env';
import { useTranslation } from '@affine/i18n';
import type { AccessTokenMessage } from '@affine/workspace/affine/login';
import { CloudWorkspaceIcon, SignOutIcon } from '@blocksuite/icons';
@@ -20,6 +21,10 @@ export type FooterProps = {
export const Footer: React.FC<FooterProps> = ({ user, onLogin, onLogout }) => {
const { t } = useTranslation();
+ if (!config.enableLegacyCloud) {
+ return null;
+ }
+
return (
<StyledFooter data-testid="workspace-list-modal-footer">
{user && (
diff --git a/apps/web/src/plugins/affine/index.tsx b/apps/web/src/plugins/affine/index.tsx
index be2b23bb03..222d075533 100644
--- a/apps/web/src/plugins/affine/index.tsx
+++ b/apps/web/src/plugins/affine/index.tsx
@@ -1,4 +1,4 @@
-import { prefixUrl } from '@affine/env';
+import { config, prefixUrl } from '@affine/env';
import { initPage } from '@affine/env/blocksuite';
import { currentAffineUserAtom } from '@affine/workspace/affine/atom';
import {
@@ -78,6 +78,10 @@ export const AffinePlugin: WorkspacePlugin<WorkspaceFlavour.AFFINE> = {
loadPriority: LoadPriority.HIGH,
Events: {
'workspace:access': async () => {
+ if (!config.enableLegacyCloud) {
+ console.warn('Legacy cloud is disabled');
+ return;
+ }
const response = await affineAuth.generateToken(SignMethod.Google);
if (response) {
setLoginStorage(response);
@@ -88,6 +92,10 @@ export const AffinePlugin: WorkspacePlugin<WorkspaceFlavour.AFFINE> = {
}
},
'workspace:revoke': async () => {
+ if (!config.enableLegacyCloud) {
+ console.warn('Legacy cloud is disabled');
+ return;
+ }
rootStore.set(rootWorkspacesMetadataAtom, workspaces =>
workspaces.filter(
workspace => workspace.flavour !== WorkspaceFlavour.AFFINE
diff --git a/packages/env/src/config.ts b/packages/env/src/config.ts
index 779fb956b3..154e38c4ff 100644
--- a/packages/env/src/config.ts
+++ b/packages/env/src/config.ts
@@ -13,6 +13,7 @@ export const publicRuntimeConfigSchema = z.object({
editorVersion: z.string(),
enableBroadCastChannelProvider: z.boolean(),
enableDebugPage: z.boolean(),
+ enableLegacyCloud: z.boolean(),
});
export type PublicRuntimeConfig = z.infer<typeof publicRuntimeConfigSchema>;
diff --git a/scripts/vitest/next-config-mock.ts b/scripts/vitest/next-config-mock.ts
index ad6ae4039b..a80e7094ec 100644
--- a/scripts/vitest/next-config-mock.ts
+++ b/scripts/vitest/next-config-mock.ts
@@ -7,6 +7,7 @@ export default function getConfig() {
hash: 'UNKNOWN',
editorVersion: 'UNKNOWN',
serverAPI: 'http://127.0.0.1:3000/',
+ enableLegacyCloud: true,
enableBroadCastChannelProvider: true,
enableDebugPage: true,
},