mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-10 05:29:08 +08:00
fix: syncing images (#1501)
This commit is contained in:
@@ -14,7 +14,7 @@ import {
|
|||||||
LoadPriority,
|
LoadPriority,
|
||||||
RemWorkspaceFlavour,
|
RemWorkspaceFlavour,
|
||||||
} from '../../shared';
|
} from '../../shared';
|
||||||
import { apis } from '../../shared/apis';
|
import { apis, clientAuth } from '../../shared/apis';
|
||||||
import { createEmptyBlockSuiteWorkspace } from '../../utils';
|
import { createEmptyBlockSuiteWorkspace } from '../../utils';
|
||||||
import { WorkspacePlugin } from '..';
|
import { WorkspacePlugin } from '..';
|
||||||
import { fetcher, QueryKey } from './fetcher';
|
import { fetcher, QueryKey } from './fetcher';
|
||||||
@@ -68,6 +68,27 @@ export const AffinePlugin: WorkspacePlugin<RemWorkspaceFlavour.AFFINE> = {
|
|||||||
blockSuiteWorkspace.doc
|
blockSuiteWorkspace.doc
|
||||||
);
|
);
|
||||||
const { id } = await apis.createWorkspace(new Blob([binary.buffer]));
|
const { id } = await apis.createWorkspace(new Blob([binary.buffer]));
|
||||||
|
// fixme: syncing images
|
||||||
|
const newWorkspaceId = id;
|
||||||
|
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
const blobs = await blockSuiteWorkspace.blobs;
|
||||||
|
if (blobs) {
|
||||||
|
const ids = await blobs.blobs;
|
||||||
|
for (const id of ids) {
|
||||||
|
const url = await blobs.get(id);
|
||||||
|
if (url) {
|
||||||
|
const blob = await fetch(url).then(res => res.blob());
|
||||||
|
await clientAuth.put(`api/workspace/${newWorkspaceId}/blob`, {
|
||||||
|
body: blob,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': blob.type,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await mutate(matcher => matcher === QueryKey.getWorkspaces);
|
await mutate(matcher => matcher === QueryKey.getWorkspaces);
|
||||||
// refresh the local storage
|
// refresh the local storage
|
||||||
await AffinePlugin.CRUD.list();
|
await AffinePlugin.CRUD.list();
|
||||||
|
|||||||
@@ -22,5 +22,5 @@ if (typeof window === 'undefined') {
|
|||||||
|
|
||||||
const bareAuth = createBareClient(prefixUrl);
|
const bareAuth = createBareClient(prefixUrl);
|
||||||
const googleAuth = new GoogleAuth(bareAuth);
|
const googleAuth = new GoogleAuth(bareAuth);
|
||||||
const clientAuth = createAuthClient(bareAuth, googleAuth);
|
export const clientAuth = createAuthClient(bareAuth, googleAuth);
|
||||||
export const apis = getApis(bareAuth, clientAuth, googleAuth);
|
export const apis = getApis(bareAuth, clientAuth, googleAuth);
|
||||||
|
|||||||
Reference in New Issue
Block a user