mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 08:36:22 +08:00
feat: init affine blob storage (#2045)
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { getLoginStorage } from '@affine/workspace/affine/login';
|
||||
import { rootStore } from '@affine/workspace/atom';
|
||||
import type { AffineWorkspace } from '@affine/workspace/type';
|
||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
@@ -66,9 +65,10 @@ export const fetcher = async (
|
||||
return workspaces.map(workspace => {
|
||||
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(
|
||||
workspace.id,
|
||||
(k: string) =>
|
||||
// fixme: token could be expired
|
||||
({ api: '/api/workspace', token: getLoginStorage()?.token }[k])
|
||||
WorkspaceFlavour.AFFINE,
|
||||
{
|
||||
workspaceApis: affineApis,
|
||||
}
|
||||
);
|
||||
const remWorkspace: AffineWorkspace = {
|
||||
...workspace,
|
||||
|
||||
@@ -51,12 +51,10 @@ const getPersistenceAllWorkspace = () => {
|
||||
...items.map((item: z.infer<typeof schema>) => {
|
||||
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(
|
||||
item.id,
|
||||
(k: string) =>
|
||||
// fixme: token could be expired
|
||||
({
|
||||
api: prefixUrl + 'api/workspace',
|
||||
token: getLoginStorage()?.token,
|
||||
}[k])
|
||||
WorkspaceFlavour.AFFINE,
|
||||
{
|
||||
workspaceApis: affineApis,
|
||||
}
|
||||
);
|
||||
const affineWorkspace: AffineWorkspace = {
|
||||
...item,
|
||||
@@ -116,19 +114,15 @@ export const AffinePlugin: WorkspacePlugin<WorkspaceFlavour.AFFINE> = {
|
||||
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 affineApis.uploadBlob(
|
||||
newWorkspaceId,
|
||||
await blob.arrayBuffer(),
|
||||
blob.type
|
||||
);
|
||||
}
|
||||
const blobManager = blockSuiteWorkspace.blobs;
|
||||
for (const id of await blobManager.list()) {
|
||||
const blob = await blobManager.get(id);
|
||||
if (blob) {
|
||||
await affineApis.uploadBlob(
|
||||
newWorkspaceId,
|
||||
await blob.arrayBuffer(),
|
||||
blob.type
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,9 +176,10 @@ export const AffinePlugin: WorkspacePlugin<WorkspaceFlavour.AFFINE> = {
|
||||
return workspaces.map(workspace => {
|
||||
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(
|
||||
workspace.id,
|
||||
(k: string) =>
|
||||
// fixme: token could be expired
|
||||
({ api: '/api/workspace', token: getLoginStorage()?.token }[k])
|
||||
WorkspaceFlavour.AFFINE,
|
||||
{
|
||||
workspaceApis: affineApis,
|
||||
}
|
||||
);
|
||||
const dump = workspaces.map(workspace => {
|
||||
return {
|
||||
|
||||
@@ -29,7 +29,7 @@ export const LocalPlugin: WorkspacePlugin<WorkspaceFlavour.LOCAL> = {
|
||||
'app:init': () => {
|
||||
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(
|
||||
nanoid(),
|
||||
(_: string) => undefined
|
||||
WorkspaceFlavour.LOCAL
|
||||
);
|
||||
blockSuiteWorkspace.meta.setName(DEFAULT_WORKSPACE_NAME);
|
||||
const page = blockSuiteWorkspace.createPage(DEFAULT_HELLO_WORLD_PAGE_ID);
|
||||
|
||||
Reference in New Issue
Block a user