mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-24 04:27:27 +08:00
feat: support disable legacy cloud (#2006)
This commit is contained in:
@@ -34,6 +34,7 @@ if (process.platform === 'win32') {
|
|||||||
$.prefix = '';
|
$.prefix = '';
|
||||||
}
|
}
|
||||||
// step 1: build web (nextjs) dist
|
// step 1: build web (nextjs) dist
|
||||||
|
process.env.ENABLE_LEGACY_PROVIDER = 'false';
|
||||||
cd(repoRootDir);
|
cd(repoRootDir);
|
||||||
await $`yarn add`;
|
await $`yarn add`;
|
||||||
await $`yarn build`;
|
await $`yarn build`;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ EXPOSE_INTERNAL=1
|
|||||||
ENABLE_DEBUG_PAGE=
|
ENABLE_DEBUG_PAGE=
|
||||||
ENABLE_SUBPAGE=
|
ENABLE_SUBPAGE=
|
||||||
ENABLE_CHANGELOG=1
|
ENABLE_CHANGELOG=1
|
||||||
|
ENABLE_LEGACY_PROVIDER=true
|
||||||
|
|
||||||
# Sentry
|
# Sentry
|
||||||
SENTRY_AUTH_TOKEN=
|
SENTRY_AUTH_TOKEN=
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
|
enableLegacyCloud: process.env.ENABLE_LEGACY_PROVIDER
|
||||||
|
? process.env.ENABLE_LEGACY_PROVIDER === 'true'
|
||||||
|
: true,
|
||||||
enableBroadCastChannelProvider: Boolean(
|
enableBroadCastChannelProvider: Boolean(
|
||||||
process.env.ENABLE_BC_PROVIDER ?? '1'
|
process.env.ENABLE_BC_PROVIDER ?? '1'
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
//#region async atoms that to load the real workspace data
|
//#region async atoms that to load the real workspace data
|
||||||
import { DebugLogger } from '@affine/debug';
|
import { DebugLogger } from '@affine/debug';
|
||||||
|
import { config } from '@affine/env';
|
||||||
import {
|
import {
|
||||||
rootCurrentWorkspaceIdAtom,
|
rootCurrentWorkspaceIdAtom,
|
||||||
rootWorkspacesMetadataAtom,
|
rootWorkspacesMetadataAtom,
|
||||||
} from '@affine/workspace/atom';
|
} from '@affine/workspace/atom';
|
||||||
|
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||||
import { assertExists } from '@blocksuite/store';
|
import { assertExists } from '@blocksuite/store';
|
||||||
import { atom } from 'jotai';
|
import { atom } from 'jotai';
|
||||||
|
|
||||||
@@ -19,9 +21,16 @@ export const workspacesAtom = atom<Promise<AllWorkspace[]>>(async get => {
|
|||||||
const flavours: string[] = Object.values(WorkspacePlugins).map(
|
const flavours: string[] = Object.values(WorkspacePlugins).map(
|
||||||
plugin => plugin.flavour
|
plugin => plugin.flavour
|
||||||
);
|
);
|
||||||
const jotaiWorkspaces = get(rootWorkspacesMetadataAtom).filter(workspace =>
|
const jotaiWorkspaces = get(rootWorkspacesMetadataAtom)
|
||||||
flavours.includes(workspace.flavour)
|
.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(
|
const workspaces = await Promise.all(
|
||||||
jotaiWorkspaces.map(workspace => {
|
jotaiWorkspaces.map(workspace => {
|
||||||
const plugin =
|
const plugin =
|
||||||
|
|||||||
+13
-10
@@ -1,4 +1,5 @@
|
|||||||
import { Button, IconButton, Menu, MenuItem, Wrapper } from '@affine/component';
|
import { Button, IconButton, Menu, MenuItem, Wrapper } from '@affine/component';
|
||||||
|
import { config } from '@affine/env';
|
||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
import { PermissionType } from '@affine/workspace/affine/api';
|
import { PermissionType } from '@affine/workspace/affine/api';
|
||||||
import type { AffineWorkspace, LocalWorkspace } from '@affine/workspace/type';
|
import type { AffineWorkspace, LocalWorkspace } from '@affine/workspace/type';
|
||||||
@@ -171,16 +172,18 @@ const LocalCollaborationPanel: React.FC<
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Wrapper marginBottom="42px">{t('Collaboration Description')}</Wrapper>
|
<Wrapper marginBottom="42px">{t('Collaboration Description')}</Wrapper>
|
||||||
<Button
|
{config.enableLegacyCloud && (
|
||||||
data-testid="local-workspace-enable-cloud-button"
|
<Button
|
||||||
type="light"
|
data-testid="local-workspace-enable-cloud-button"
|
||||||
shape="circle"
|
type="light"
|
||||||
onClick={() => {
|
shape="circle"
|
||||||
setOpen(true);
|
onClick={() => {
|
||||||
}}
|
setOpen(true);
|
||||||
>
|
}}
|
||||||
{t('Enable AFFiNE Cloud')}
|
>
|
||||||
</Button>
|
{t('Enable AFFiNE Cloud')}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
<TransformWorkspaceToAffineModal
|
<TransformWorkspaceToAffineModal
|
||||||
open={open}
|
open={open}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
Input,
|
Input,
|
||||||
Wrapper,
|
Wrapper,
|
||||||
} from '@affine/component';
|
} from '@affine/component';
|
||||||
|
import { config } from '@affine/env';
|
||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
import type { AffineWorkspace, LocalWorkspace } from '@affine/workspace/type';
|
import type { AffineWorkspace, LocalWorkspace } from '@affine/workspace/type';
|
||||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||||
@@ -120,16 +121,18 @@ const PublishPanelLocal: React.FC<PublishPanelLocalProps> = ({
|
|||||||
>
|
>
|
||||||
{t('Publishing')}
|
{t('Publishing')}
|
||||||
</Box>
|
</Box>
|
||||||
<Button
|
{config.enableLegacyCloud && (
|
||||||
data-testid="publish-enable-affine-cloud-button"
|
<Button
|
||||||
type="light"
|
data-testid="publish-enable-affine-cloud-button"
|
||||||
shape="circle"
|
type="light"
|
||||||
onClick={() => {
|
shape="circle"
|
||||||
setOpen(true);
|
onClick={() => {
|
||||||
}}
|
setOpen(true);
|
||||||
>
|
}}
|
||||||
{t('Enable AFFiNE Cloud')}
|
>
|
||||||
</Button>
|
{t('Enable AFFiNE Cloud')}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
<EnableAffineCloudModal
|
<EnableAffineCloudModal
|
||||||
open={open}
|
open={open}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { displayFlex, IconButton, styled, Tooltip } from '@affine/component';
|
import { displayFlex, IconButton, styled, Tooltip } from '@affine/component';
|
||||||
|
import { config } from '@affine/env';
|
||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
import {
|
import {
|
||||||
getLoginStorage,
|
getLoginStorage,
|
||||||
@@ -80,6 +81,10 @@ export const SyncUser = () => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const transformWorkspace = useTransformWorkspace();
|
const transformWorkspace = useTransformWorkspace();
|
||||||
|
|
||||||
|
if (!config.enableLegacyCloud) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (status === 'offline') {
|
if (status === 'offline') {
|
||||||
return (
|
return (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { FlexWrapper } from '@affine/component';
|
import { FlexWrapper } from '@affine/component';
|
||||||
import { IconButton } from '@affine/component';
|
import { IconButton } from '@affine/component';
|
||||||
import { Tooltip } from '@affine/component';
|
import { Tooltip } from '@affine/component';
|
||||||
|
import { config } from '@affine/env';
|
||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
import type { AccessTokenMessage } from '@affine/workspace/affine/login';
|
import type { AccessTokenMessage } from '@affine/workspace/affine/login';
|
||||||
import { CloudWorkspaceIcon, SignOutIcon } from '@blocksuite/icons';
|
import { CloudWorkspaceIcon, SignOutIcon } from '@blocksuite/icons';
|
||||||
@@ -20,6 +21,10 @@ export type FooterProps = {
|
|||||||
export const Footer: React.FC<FooterProps> = ({ user, onLogin, onLogout }) => {
|
export const Footer: React.FC<FooterProps> = ({ user, onLogin, onLogout }) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
if (!config.enableLegacyCloud) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledFooter data-testid="workspace-list-modal-footer">
|
<StyledFooter data-testid="workspace-list-modal-footer">
|
||||||
{user && (
|
{user && (
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { prefixUrl } from '@affine/env';
|
import { config, prefixUrl } from '@affine/env';
|
||||||
import { initPage } from '@affine/env/blocksuite';
|
import { initPage } from '@affine/env/blocksuite';
|
||||||
import { currentAffineUserAtom } from '@affine/workspace/affine/atom';
|
import { currentAffineUserAtom } from '@affine/workspace/affine/atom';
|
||||||
import {
|
import {
|
||||||
@@ -78,6 +78,10 @@ export const AffinePlugin: WorkspacePlugin<WorkspaceFlavour.AFFINE> = {
|
|||||||
loadPriority: LoadPriority.HIGH,
|
loadPriority: LoadPriority.HIGH,
|
||||||
Events: {
|
Events: {
|
||||||
'workspace:access': async () => {
|
'workspace:access': async () => {
|
||||||
|
if (!config.enableLegacyCloud) {
|
||||||
|
console.warn('Legacy cloud is disabled');
|
||||||
|
return;
|
||||||
|
}
|
||||||
const response = await affineAuth.generateToken(SignMethod.Google);
|
const response = await affineAuth.generateToken(SignMethod.Google);
|
||||||
if (response) {
|
if (response) {
|
||||||
setLoginStorage(response);
|
setLoginStorage(response);
|
||||||
@@ -88,6 +92,10 @@ export const AffinePlugin: WorkspacePlugin<WorkspaceFlavour.AFFINE> = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
'workspace:revoke': async () => {
|
'workspace:revoke': async () => {
|
||||||
|
if (!config.enableLegacyCloud) {
|
||||||
|
console.warn('Legacy cloud is disabled');
|
||||||
|
return;
|
||||||
|
}
|
||||||
rootStore.set(rootWorkspacesMetadataAtom, workspaces =>
|
rootStore.set(rootWorkspacesMetadataAtom, workspaces =>
|
||||||
workspaces.filter(
|
workspaces.filter(
|
||||||
workspace => workspace.flavour !== WorkspaceFlavour.AFFINE
|
workspace => workspace.flavour !== WorkspaceFlavour.AFFINE
|
||||||
|
|||||||
Vendored
+1
@@ -13,6 +13,7 @@ export const publicRuntimeConfigSchema = z.object({
|
|||||||
editorVersion: z.string(),
|
editorVersion: z.string(),
|
||||||
enableBroadCastChannelProvider: z.boolean(),
|
enableBroadCastChannelProvider: z.boolean(),
|
||||||
enableDebugPage: z.boolean(),
|
enableDebugPage: z.boolean(),
|
||||||
|
enableLegacyCloud: z.boolean(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type PublicRuntimeConfig = z.infer<typeof publicRuntimeConfigSchema>;
|
export type PublicRuntimeConfig = z.infer<typeof publicRuntimeConfigSchema>;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export default function getConfig() {
|
|||||||
hash: 'UNKNOWN',
|
hash: 'UNKNOWN',
|
||||||
editorVersion: 'UNKNOWN',
|
editorVersion: 'UNKNOWN',
|
||||||
serverAPI: 'http://127.0.0.1:3000/',
|
serverAPI: 'http://127.0.0.1:3000/',
|
||||||
|
enableLegacyCloud: true,
|
||||||
enableBroadCastChannelProvider: true,
|
enableBroadCastChannelProvider: true,
|
||||||
enableDebugPage: true,
|
enableDebugPage: true,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user