feat: local command

This commit is contained in:
DarkSky
2022-07-22 18:08:30 +08:00
parent 0871fbda07
commit 9361ad8e61
9 changed files with 43 additions and 23 deletions

1
.env.local Normal file
View File

@@ -0,0 +1 @@
NX_LOCAL=true

View File

@@ -1 +0,0 @@
NX_FREE_LOGIN=true

View File

@@ -84,9 +84,9 @@ const Title = styled('div')<{ size: PreviewSize }>(({ size }) => {
const ScopedEditorWrapper = styled('div')<{ size: PreviewSize }>(({ size }) => {
return {
width: '750px',
width: '940px',
height: '750px',
transform: 'scale(32%) translate(-102%, -104%)',
transform: 'scale(25%) translate(-145%, -145%)',
// eslint-disable-next-line @typescript-eslint/naming-convention
'&>:first-child': {
margin: 'auto',

View File

@@ -136,7 +136,6 @@ const SourceViewContainer = styled('div')<{
borderRadius: theme.affine.shape.borderRadius,
background: isSelected ? 'rgba(152, 172, 189, 0.1)' : 'transparent',
padding: '8px',
// border:
iframe: {
width: '100%',
height: '100%',
@@ -171,6 +170,7 @@ export const SourceView: FC<Props> = props => {
<SourceViewContainer
isSelected={isSelected}
scene={SCENE_CONFIG.REFLINK}
style={{ padding: '0' }}
>
<MemoBlockPreview
block={block}

View File

@@ -1,5 +1,5 @@
const _regex =
/^(https?:\/\/(localhost:4200|(nightly|app)\.affine\.pro|.*?\.ligo-virgo\.pages\.dev)\/\w{28}\/)?(affine\w{16})$/;
/^(https?:\/\/(localhost:4200|(nightly|app)\.affine\.pro|.*?\.ligo-virgo\.pages\.dev)\/\w{28}\/)?(affine\w{16})(\/whiteboard)?$/;
export const isAffineUrl = (url?: string) => {
if (!url) return false;

View File

@@ -24,16 +24,16 @@ const waitLoading = async (key: string) => {
};
async function _getCurrentToken() {
if (process.env['NX_FREE_LOGIN']) {
return 'NX_FREE_LOGIN';
}
const token = await getAuth().currentUser?.getIdToken();
if (token) return token;
return new Promise<string>(resolve => {
getAuth().onIdTokenChanged((user: User | null) => {
if (user) resolve(user.getIdToken());
if (!process.env['NX_LOCAL']) {
const token = await getAuth().currentUser?.getIdToken();
if (token) return token;
return new Promise<string>(resolve => {
getAuth().onIdTokenChanged((user: User | null) => {
if (user) resolve(user.getIdToken());
});
});
});
}
return undefined;
}
async function _getBlockDatabase(

View File

@@ -16,6 +16,7 @@ import {
transact,
encodeStateAsUpdate,
applyUpdate,
snapshot,
} from 'yjs';
import { WebsocketProvider } from '@toeverything/datasource/jwt-rpc';
@@ -62,7 +63,7 @@ async function _initWebsocketProvider(
params?: YjsInitOptions['params']
): Promise<[Awareness, WebsocketProvider | undefined]> {
const awareness = new Awareness(doc);
if (token && !process.env['NX_FREE_LOGIN']) {
if (token) {
const ws = new WebsocketProvider(token, url, room, doc, {
awareness,
params,
@@ -129,10 +130,13 @@ async function _initYjsDatabase(
binaries
).whenSynced;
const gateKeeperData = doc.getMap<YMap<string>>('gatekeeper');
const gatekeeper = new GateKeeper(
userId,
doc.getMap('creators'),
doc.getMap('common')
gateKeeperData.get('creators') ||
gateKeeperData.set('creators', new YMap()),
gateKeeperData.get('common') || gateKeeperData.set('common', new YMap())
);
_yjsDatabaseInstance.set(workspace, {
@@ -206,8 +210,11 @@ export class YjsAdapter implements AsyncDatabaseAdapter<YjsContentOperation> {
this.#awareness = providers.awareness;
this.#gatekeeper = providers.gatekeeper;
this.#blocks = this.#doc.getMap('blocks');
this.#block_updated = this.#doc.getMap('block_updated');
const blocks = this.#doc.getMap<YMap<any>>('blocks');
this.#blocks =
blocks.get('content') || blocks.set('content', new YMap());
this.#block_updated =
blocks.get('updated') || blocks.set('updated', new YMap());
this.#block_caches = new LRUCache({ max: 1024, ttl: 1000 * 60 * 10 });
this.#binaries = new YjsRemoteBinaries(
providers.binariesIdb.doc.getMap(),
@@ -381,6 +388,18 @@ export class YjsAdapter implements AsyncDatabaseAdapter<YjsContentOperation> {
this.#blocks.clear();
this.#block_updated.clear();
this.#gatekeeper.clear();
this.#doc.getMap('blocks').clear();
this.#doc.getMap('gatekeeper').clear();
},
// eslint-disable-next-line @typescript-eslint/naming-convention
clear_old: () => {
this.#doc.getMap('block_updated').clear();
this.#doc.getMap('blocks').clear();
this.#doc.getMap('common').clear();
this.#doc.getMap('creators').clear();
},
snapshot: () => {
return snapshot(this.#doc);
},
};
}

View File

@@ -63,7 +63,7 @@ const _useUserAndSpace = () => {
};
const _useUserAndSpacesForFreeLogin = () => {
const [loading] = useAtom(_loadingAtom);
const [loading, setLoading] = useAtom(_loadingAtom);
useEffect(() => setLoading(false), []);
const BRAND_ID = 'AFFiNE';
@@ -78,6 +78,6 @@ const _useUserAndSpacesForFreeLogin = () => {
loading,
};
};
export const useUserAndSpaces = process.env['NX_FREE_LOGIN']
export const useUserAndSpaces = process.env['NX_LOCAL']
? _useUserAndSpacesForFreeLogin
: _useUserAndSpace;

View File

@@ -4,10 +4,11 @@
"license": "MIT",
"author": "AFFiNE <developer@affine.pro>",
"scripts": {
"start": "nx serve ligo-virgo",
"start:free": "env-cmd -f .free.env nx serve ligo-virgo",
"start": "env-cmd -f .env.local nx serve ligo-virgo",
"start:affine": "nx serve ligo-virgo",
"start:keck": "nx serve keck",
"build": "nx build ligo-virgo",
"build:local": "env-cmd -f .env.local nx build ligo-virgo",
"build:keck": "nx build keck",
"build:analytic": "cross-env BUNDLE_ANALYZER=true nx build --skip-nx-cache",
"test": "nx run-many --target test --all",