mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-12 15:46:29 +08:00
1.adjust export/import database;
This commit is contained in:
@@ -80,34 +80,20 @@ export const FileSystem = () => {
|
||||
|
||||
if (apiSupported && !selected) {
|
||||
return (
|
||||
<>
|
||||
<MuiSnackbar
|
||||
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
|
||||
open={error}
|
||||
message="Request File Permission failed, please check if you have permission"
|
||||
sx={{ marginTop: '3em' }}
|
||||
action={
|
||||
<IconButton
|
||||
aria-label="close"
|
||||
onClick={() => setError(false)}
|
||||
>
|
||||
<CloseIcon />
|
||||
</IconButton>
|
||||
}
|
||||
/>
|
||||
<StyledFileSystem
|
||||
onClick={async () => {
|
||||
try {
|
||||
await requestPermission('AFFiNE');
|
||||
onSelected();
|
||||
} catch (e) {
|
||||
onError();
|
||||
}
|
||||
}}
|
||||
>
|
||||
{t('Sync to Disk')}
|
||||
</StyledFileSystem>
|
||||
</>
|
||||
<MuiSnackbar
|
||||
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
|
||||
open={error}
|
||||
message="Request File Permission failed, please check if you have permission"
|
||||
sx={{ marginTop: '3em' }}
|
||||
action={
|
||||
<IconButton
|
||||
aria-label="close"
|
||||
onClick={() => setError(false)}
|
||||
>
|
||||
<CloseIcon />
|
||||
</IconButton>
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -70,9 +70,6 @@ export const LayoutHeader = () => {
|
||||
<EditorBoardSwitcher />
|
||||
</StyledContainerForEditorBoardSwitcher>
|
||||
</StyledHeaderRoot>
|
||||
<StyledUnstableTips>
|
||||
<StyledUnstableTipsText>{warningTips}</StyledUnstableTipsText>
|
||||
</StyledUnstableTips>
|
||||
</StyledContainerForHeaderRoot>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -2,8 +2,8 @@ import { useFlag } from '@toeverything/datasource/feature-flags';
|
||||
|
||||
export const useSettingFlags = () => {
|
||||
const booleanFullWidthChecked = useFlag('BooleanFullWidthChecked', false);
|
||||
const booleanExportWorkspace = useFlag('BooleanExportWorkspace', false);
|
||||
const booleanImportWorkspace = useFlag('BooleanImportWorkspace', false);
|
||||
const booleanExportWorkspace = useFlag('BooleanExportAffineDb', true);
|
||||
const booleanImportWorkspace = useFlag('BooleanImportAffineDb', true);
|
||||
const booleanExportHtml = useFlag('BooleanExportHtml', false);
|
||||
const booleanExportPdf = useFlag('BooleanExportPdf', false);
|
||||
const booleanExportMarkdown = useFlag('BooleanExportMarkdown', false);
|
||||
|
||||
@@ -145,12 +145,19 @@ export const useSettings = (): SettingItem[] => {
|
||||
type: 'separator',
|
||||
key: 'separator2',
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
name: t('Clear Workspace'),
|
||||
key: 'Clear Workspace',
|
||||
onClick: () => clearWorkspace(workspaceId),
|
||||
flag: 'booleanClearWorkspace',
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
name: t('Import Workspace'),
|
||||
key: 'Import Workspace',
|
||||
onClick: () => importWorkspace(workspaceId),
|
||||
flag: 'booleanImportWorkspace',
|
||||
flag: 'booleanClearWorkspace',
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
@@ -159,13 +166,6 @@ export const useSettings = (): SettingItem[] => {
|
||||
onClick: () => exportWorkspace(),
|
||||
flag: 'booleanExportWorkspace',
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
name: t('Clear Workspace'),
|
||||
key: 'Clear Workspace',
|
||||
onClick: () => clearWorkspace(workspaceId),
|
||||
flag: 'booleanClearWorkspace',
|
||||
},
|
||||
];
|
||||
|
||||
return filterSettings(settings, settingFlags);
|
||||
|
||||
@@ -6,8 +6,12 @@ export const importWorkspace = (workspaceId: string) => {
|
||||
window.client
|
||||
.inspector()
|
||||
.load()
|
||||
.then(() => {
|
||||
window.location.href = `/${workspaceId}/`;
|
||||
.then(status => {
|
||||
if (status) {
|
||||
if (window.confirm('Your currently open data will be lost.')) {
|
||||
window.location.href = `/${workspaceId}/`;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ async function _getCurrentToken() {
|
||||
|
||||
const _enabled = {
|
||||
demo: [],
|
||||
AFFiNE: ['sqlite'],
|
||||
AFFiNE: ['idb'],
|
||||
} as any;
|
||||
|
||||
async function _getBlockDatabase(
|
||||
|
||||
@@ -36,7 +36,7 @@ export class UserConfig extends ServiceBaseClass {
|
||||
}
|
||||
|
||||
const db = await this.database.getDatabase(workspace);
|
||||
const newPage = await db.get('page');
|
||||
const newPage = await db.get_named_block('start-page');
|
||||
|
||||
await this.get_dependency(PageTree).addPage(workspace, newPage.id);
|
||||
await this.addRecentPage(workspace, userId, newPage.id);
|
||||
|
||||
@@ -357,7 +357,7 @@ export class BlockClient<
|
||||
* @param name block name
|
||||
* @returns block instance
|
||||
*/
|
||||
private async get_named_block(
|
||||
public async get_named_block(
|
||||
name: string,
|
||||
options?: { workspace?: boolean }
|
||||
): Promise<BaseBlock<B, C>> {
|
||||
|
||||
@@ -324,53 +324,59 @@ export class YjsAdapter implements AsyncDatabaseAdapter<YjsContentOperation> {
|
||||
const binary = encodeStateAsUpdate(this._doc);
|
||||
saveAs(
|
||||
new Blob([binary]),
|
||||
`affine_workspace_${new Date().toDateString()}.apk`
|
||||
`affine_workspace_${new Date().toDateString()}.affine`
|
||||
);
|
||||
},
|
||||
load: async () => {
|
||||
const handles = await window.showOpenFilePicker({
|
||||
types: [
|
||||
{
|
||||
description: 'AFFiNE Package',
|
||||
accept: {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
'application/affine': ['.apk'],
|
||||
try {
|
||||
const handles = await window.showOpenFilePicker({
|
||||
types: [
|
||||
{
|
||||
description: 'AFFiNE Package',
|
||||
accept: {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
'application/affine': ['.affine'],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
const [file] = (await fromEvent(handles)) as File[];
|
||||
const binary = await file?.arrayBuffer();
|
||||
// await this._provider.idb.clearData();
|
||||
const doc = new Doc({ autoLoad: true, shouldLoad: true });
|
||||
let updated = 0;
|
||||
let isUpdated = false;
|
||||
doc.on('update', () => {
|
||||
isUpdated = true;
|
||||
updated += 1;
|
||||
});
|
||||
setInterval(() => {
|
||||
if (updated > 0) {
|
||||
updated -= 1;
|
||||
}
|
||||
}, 500);
|
||||
|
||||
const update_check = new Promise<void>(resolve => {
|
||||
const check = async () => {
|
||||
while (!isUpdated || updated > 0) {
|
||||
await sleep();
|
||||
],
|
||||
});
|
||||
const [file] = (await fromEvent(handles)) as File[];
|
||||
const binary = await file?.arrayBuffer();
|
||||
// await this._provider.idb.clearData();
|
||||
const doc = new Doc({ autoLoad: true, shouldLoad: true });
|
||||
let updated = 0;
|
||||
let isUpdated = false;
|
||||
doc.on('update', () => {
|
||||
isUpdated = true;
|
||||
updated += 1;
|
||||
});
|
||||
setInterval(() => {
|
||||
if (updated > 0) {
|
||||
updated -= 1;
|
||||
}
|
||||
resolve();
|
||||
};
|
||||
check();
|
||||
});
|
||||
// await new IndexedDBProvider(this._provider.idb.name, doc)
|
||||
// .whenSynced;
|
||||
if (binary) {
|
||||
applyUpdate(doc, new Uint8Array(binary));
|
||||
await update_check;
|
||||
}, 500);
|
||||
|
||||
const update_check = new Promise<void>(resolve => {
|
||||
const check = async () => {
|
||||
while (!isUpdated || updated > 0) {
|
||||
await sleep();
|
||||
}
|
||||
resolve();
|
||||
};
|
||||
check();
|
||||
});
|
||||
// await new IndexedDBProvider(this._provider.idb.name, doc)
|
||||
// .whenSynced;
|
||||
if (binary) {
|
||||
applyUpdate(doc, new Uint8Array(binary));
|
||||
await update_check;
|
||||
}
|
||||
console.log('load success');
|
||||
|
||||
return true;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
console.log('load success');
|
||||
},
|
||||
parse: () => this._doc.toJSON(),
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
|
||||
@@ -74,41 +74,21 @@ const _useUserAndSpacesForFreeLogin = () => {
|
||||
if (location.pathname.startsWith('/local')) {
|
||||
navigate('/local');
|
||||
} else {
|
||||
navigate('/demo');
|
||||
navigate(`/${BRAND_ID}`);
|
||||
}
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (localTrigger) {
|
||||
setUser({
|
||||
photo: '',
|
||||
id: BRAND_ID,
|
||||
username: BRAND_ID,
|
||||
nickname: BRAND_ID,
|
||||
email: '',
|
||||
});
|
||||
} else {
|
||||
if (location.pathname.startsWith('/local')) {
|
||||
setUser({
|
||||
photo: '',
|
||||
id: 'local',
|
||||
username: 'local',
|
||||
nickname: 'local',
|
||||
email: '',
|
||||
});
|
||||
} else {
|
||||
setUser({
|
||||
photo: '',
|
||||
id: 'demo',
|
||||
username: 'demo',
|
||||
nickname: 'demo',
|
||||
email: '',
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [localTrigger, location, setLoading, setUser]);
|
||||
setUser({
|
||||
photo: '',
|
||||
id: BRAND_ID,
|
||||
username: BRAND_ID,
|
||||
nickname: BRAND_ID,
|
||||
email: '',
|
||||
});
|
||||
}, [setUser]);
|
||||
|
||||
const currentSpaceId: string | undefined = useMemo(() => user?.id, [user]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user