mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-21 00:07:01 +08:00
fix: temp workaround for missing blobs in export (#3347)
This commit is contained in:
@@ -1,30 +1,51 @@
|
|||||||
import { Button, toast } from '@affine/component';
|
import { Button, toast } from '@affine/component';
|
||||||
import { SettingRow } from '@affine/component/setting-components';
|
import { SettingRow } from '@affine/component/setting-components';
|
||||||
|
import { isDesktop } from '@affine/env/constant';
|
||||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
import type { FC } from 'react';
|
import { type FC, useCallback } from 'react';
|
||||||
|
|
||||||
import type { AffineOfficialWorkspace } from '../../../shared';
|
import type { AffineOfficialWorkspace } from '../../../shared';
|
||||||
|
|
||||||
|
async function syncBlobsToSqliteDb(workspace: AffineOfficialWorkspace) {
|
||||||
|
if (window.apis && isDesktop) {
|
||||||
|
const bs = workspace.blockSuiteWorkspace.blobs;
|
||||||
|
const blobsInDb = await window.apis.db.getBlobKeys(workspace.id);
|
||||||
|
const blobsInStorage = await bs.list();
|
||||||
|
const blobsToSync = blobsInStorage.filter(
|
||||||
|
blob => !blobsInDb.includes(blob)
|
||||||
|
);
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
blobsToSync.map(async blobKey => {
|
||||||
|
const blob = await bs.get(blobKey);
|
||||||
|
if (blob) {
|
||||||
|
const bin = new Uint8Array(await blob.arrayBuffer());
|
||||||
|
await window.apis.db.addBlob(workspace.id, blobKey, bin);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const ExportPanel: FC<{
|
export const ExportPanel: FC<{
|
||||||
workspace: AffineOfficialWorkspace;
|
workspace: AffineOfficialWorkspace;
|
||||||
}> = ({ workspace }) => {
|
}> = ({ workspace }) => {
|
||||||
const workspaceId = workspace.id;
|
const workspaceId = workspace.id;
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
|
const onExport = useCallback(async () => {
|
||||||
|
await syncBlobsToSqliteDb(workspace);
|
||||||
|
const result = await window.apis?.dialog.saveDBFileAs(workspaceId);
|
||||||
|
if (result?.error) {
|
||||||
|
// @ts-expect-error: result.error is dynamic
|
||||||
|
toast(t[result.error]());
|
||||||
|
} else if (!result?.canceled) {
|
||||||
|
toast(t['Export success']());
|
||||||
|
}
|
||||||
|
}, [t, workspace, workspaceId]);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SettingRow name={t['Export']()} desc={t['Export Description']()}>
|
<SettingRow name={t['Export']()} desc={t['Export Description']()}>
|
||||||
<Button
|
<Button data-testid="export-affine-backup" onClick={onExport}>
|
||||||
data-testid="export-affine-backup"
|
|
||||||
onClick={async () => {
|
|
||||||
const result = await window.apis?.dialog.saveDBFileAs(workspaceId);
|
|
||||||
if (result?.error) {
|
|
||||||
// @ts-expect-error: result.error is dynamic
|
|
||||||
toast(t[result.error]());
|
|
||||||
} else if (!result?.canceled) {
|
|
||||||
toast(t['Export success']());
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t['Export']()}
|
{t['Export']()}
|
||||||
</Button>
|
</Button>
|
||||||
</SettingRow>
|
</SettingRow>
|
||||||
|
|||||||
Reference in New Issue
Block a user