fix: syncing images (#1501)

This commit is contained in:
Himself65
2023-03-10 02:21:12 -06:00
committed by GitHub
parent b20be2a747
commit eb0d6ee08e
2 changed files with 23 additions and 2 deletions

View File

@@ -14,7 +14,7 @@ import {
LoadPriority,
RemWorkspaceFlavour,
} from '../../shared';
import { apis } from '../../shared/apis';
import { apis, clientAuth } from '../../shared/apis';
import { createEmptyBlockSuiteWorkspace } from '../../utils';
import { WorkspacePlugin } from '..';
import { fetcher, QueryKey } from './fetcher';
@@ -68,6 +68,27 @@ export const AffinePlugin: WorkspacePlugin<RemWorkspaceFlavour.AFFINE> = {
blockSuiteWorkspace.doc
);
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);
// refresh the local storage
await AffinePlugin.CRUD.list();

View File

@@ -22,5 +22,5 @@ if (typeof window === 'undefined') {
const bareAuth = createBareClient(prefixUrl);
const googleAuth = new GoogleAuth(bareAuth);
const clientAuth = createAuthClient(bareAuth, googleAuth);
export const clientAuth = createAuthClient(bareAuth, googleAuth);
export const apis = getApis(bareAuth, clientAuth, googleAuth);