@dxos/plugin-wnfs 0.8.4-main.72ec0f3 → 0.8.4-main.7996785055
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/FileContainer-TFENLFD5.mjs +72 -0
- package/dist/lib/browser/FileContainer-TFENLFD5.mjs.map +7 -0
- package/dist/lib/browser/{blockstore-2JFU4NBU.mjs → blockstore-TUV5YIC5.mjs} +13 -13
- package/dist/lib/browser/blockstore-TUV5YIC5.mjs.map +7 -0
- package/dist/lib/browser/chunk-3I3QQNA3.mjs +84 -0
- package/dist/lib/browser/chunk-3I3QQNA3.mjs.map +7 -0
- package/dist/lib/browser/{chunk-D6VTEQIE.mjs → chunk-A7ETWNGC.mjs} +23 -13
- package/dist/lib/browser/chunk-A7ETWNGC.mjs.map +7 -0
- package/dist/lib/browser/chunk-CXWUR7YI.mjs +8 -0
- package/dist/lib/browser/chunk-CXWUR7YI.mjs.map +7 -0
- package/dist/lib/browser/chunk-HXGK35WW.mjs +65 -0
- package/dist/lib/browser/chunk-HXGK35WW.mjs.map +7 -0
- package/dist/lib/browser/chunk-QE7ZSOYG.mjs +69 -0
- package/dist/lib/browser/chunk-QE7ZSOYG.mjs.map +7 -0
- package/dist/lib/browser/create-WQ6CUUDN.mjs +24 -0
- package/dist/lib/browser/create-WQ6CUUDN.mjs.map +7 -0
- package/dist/lib/browser/create-file-NGKX6CFL.mjs +49 -0
- package/dist/lib/browser/create-file-NGKX6CFL.mjs.map +7 -0
- package/dist/lib/browser/file-uploader-THECEDM2.mjs +37 -0
- package/dist/lib/browser/file-uploader-THECEDM2.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +89 -81
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/{markdown-WYQDCVFQ.mjs → markdown-IEDBXCLX.mjs} +28 -25
- package/dist/lib/browser/markdown-IEDBXCLX.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/operation-handler-YAYDKG7R.mjs +16 -0
- package/dist/lib/browser/operation-handler-YAYDKG7R.mjs.map +7 -0
- package/dist/lib/browser/operations/index.mjs +12 -0
- package/dist/lib/browser/operations/index.mjs.map +7 -0
- package/dist/lib/browser/react-surface-UGRUPU56.mjs +60 -0
- package/dist/lib/browser/react-surface-UGRUPU56.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +4 -3
- package/dist/lib/browser/upload-42ZL2AE4.mjs +42 -0
- package/dist/lib/browser/upload-42ZL2AE4.mjs.map +7 -0
- package/dist/types/src/WnfsPlugin.d.ts +2 -1
- package/dist/types/src/WnfsPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/blockstore/blockstore.d.ts +5 -0
- package/dist/types/src/capabilities/blockstore/blockstore.d.ts.map +1 -0
- package/dist/types/src/capabilities/blockstore/index.d.ts +3 -0
- package/dist/types/src/capabilities/blockstore/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/file-uploader/file-uploader.d.ts +6 -0
- package/dist/types/src/capabilities/file-uploader/file-uploader.d.ts.map +1 -0
- package/dist/types/src/capabilities/file-uploader/index.d.ts +3 -0
- package/dist/types/src/capabilities/file-uploader/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +5 -6
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/markdown/index.d.ts +3 -0
- package/dist/types/src/capabilities/markdown/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/markdown/markdown.d.ts +5 -0
- package/dist/types/src/capabilities/markdown/markdown.d.ts.map +1 -0
- package/dist/types/src/capabilities/operation-handler/index.d.ts +4 -0
- package/dist/types/src/capabilities/operation-handler/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/operation-handler/operation-handler.d.ts +6 -0
- package/dist/types/src/capabilities/operation-handler/operation-handler.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
- package/dist/types/src/components/FileInput/FileInput.d.ts.map +1 -0
- package/dist/types/src/components/FileInput/index.d.ts +2 -0
- package/dist/types/src/components/FileInput/index.d.ts.map +1 -0
- package/dist/types/src/components/FilePreview/FilePreview.d.ts +16 -0
- package/dist/types/src/components/FilePreview/FilePreview.d.ts.map +1 -0
- package/dist/types/src/components/FilePreview/index.d.ts +2 -0
- package/dist/types/src/components/FilePreview/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/containers/FileContainer/FileContainer.d.ts +7 -0
- package/dist/types/src/containers/FileContainer/FileContainer.d.ts.map +1 -0
- package/dist/types/src/containers/FileContainer/index.d.ts +3 -0
- package/dist/types/src/containers/FileContainer/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +3 -0
- package/dist/types/src/containers/index.d.ts.map +1 -0
- package/dist/types/src/extensions/image.d.ts +1 -1
- package/dist/types/src/extensions/image.d.ts.map +1 -1
- package/dist/types/src/helpers/load.d.ts +1 -1
- package/dist/types/src/helpers/load.d.ts.map +1 -1
- package/dist/types/src/helpers/upload.d.ts +1 -1
- package/dist/types/src/helpers/upload.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/operations/create-file.d.ts +5 -0
- package/dist/types/src/operations/create-file.d.ts.map +1 -0
- package/dist/types/src/operations/create.d.ts +5 -0
- package/dist/types/src/operations/create.d.ts.map +1 -0
- package/dist/types/src/operations/definitions.d.ts +38 -0
- package/dist/types/src/operations/definitions.d.ts.map +1 -0
- package/dist/types/src/operations/index.d.ts +4 -0
- package/dist/types/src/operations/index.d.ts.map +1 -0
- package/dist/types/src/operations/upload.d.ts +5 -0
- package/dist/types/src/operations/upload.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +5 -1
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/File.d.ts +11 -11
- package/dist/types/src/types/File.d.ts.map +1 -1
- package/dist/types/src/{capabilities → types}/capabilities.d.ts +3 -2
- package/dist/types/src/types/capabilities.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -0
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +4 -50
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +51 -36
- package/src/WnfsPlugin.tsx +50 -71
- package/src/blockstore.ts +1 -1
- package/src/capabilities/blockstore/blockstore.ts +22 -0
- package/src/capabilities/blockstore/index.ts +7 -0
- package/src/capabilities/file-uploader/file-uploader.ts +34 -0
- package/src/capabilities/file-uploader/index.ts +7 -0
- package/src/capabilities/index.ts +5 -9
- package/src/capabilities/markdown/index.ts +7 -0
- package/src/capabilities/markdown/markdown.ts +33 -0
- package/src/capabilities/operation-handler/index.ts +11 -0
- package/src/capabilities/operation-handler/operation-handler.ts +16 -0
- package/src/capabilities/react-surface/index.ts +7 -0
- package/src/capabilities/react-surface/react-surface.tsx +51 -0
- package/src/components/{FileInput.tsx → FileInput/FileInput.tsx} +5 -5
- package/src/components/FileInput/index.ts +5 -0
- package/src/components/FilePreview/FilePreview.tsx +43 -0
- package/src/components/FilePreview/index.ts +5 -0
- package/src/components/index.ts +1 -4
- package/src/{components → containers/FileContainer}/FileContainer.tsx +13 -16
- package/src/containers/FileContainer/index.ts +7 -0
- package/src/containers/index.ts +7 -0
- package/src/extensions/image.stories.tsx +5 -5
- package/src/extensions/image.tsx +3 -3
- package/src/helpers/load.ts +12 -7
- package/src/helpers/upload.ts +5 -2
- package/src/index.ts +1 -1
- package/src/meta.ts +3 -3
- package/src/operations/create-file.ts +32 -0
- package/src/operations/create.ts +23 -0
- package/src/operations/definitions.ts +40 -0
- package/src/operations/index.ts +13 -0
- package/src/operations/upload.ts +30 -0
- package/src/translations.ts +5 -1
- package/src/types/File.ts +11 -7
- package/src/{capabilities → types}/capabilities.ts +3 -3
- package/src/types/index.ts +1 -0
- package/src/types/types.ts +2 -19
- package/dist/lib/browser/FileContainer-LLNI7WXR.mjs +0 -103
- package/dist/lib/browser/FileContainer-LLNI7WXR.mjs.map +0 -7
- package/dist/lib/browser/blockstore-2JFU4NBU.mjs.map +0 -7
- package/dist/lib/browser/chunk-CWMKN2F6.mjs +0 -71
- package/dist/lib/browser/chunk-CWMKN2F6.mjs.map +0 -7
- package/dist/lib/browser/chunk-D6VTEQIE.mjs.map +0 -7
- package/dist/lib/browser/chunk-F4QHZWQD.mjs +0 -16
- package/dist/lib/browser/chunk-F4QHZWQD.mjs.map +0 -7
- package/dist/lib/browser/chunk-OGPGLJCV.mjs +0 -25
- package/dist/lib/browser/chunk-OGPGLJCV.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZFPJA5F4.mjs +0 -16
- package/dist/lib/browser/chunk-ZFPJA5F4.mjs.map +0 -7
- package/dist/lib/browser/file-uploader-W6TJLAAK.mjs +0 -30
- package/dist/lib/browser/file-uploader-W6TJLAAK.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-FSW2EQF4.mjs +0 -48
- package/dist/lib/browser/intent-resolver-FSW2EQF4.mjs.map +0 -7
- package/dist/lib/browser/markdown-WYQDCVFQ.mjs.map +0 -7
- package/dist/lib/browser/react-surface-DMU47U3X.mjs +0 -88
- package/dist/lib/browser/react-surface-DMU47U3X.mjs.map +0 -7
- package/dist/types/src/capabilities/blockstore.d.ts +0 -4
- package/dist/types/src/capabilities/blockstore.d.ts.map +0 -1
- package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
- package/dist/types/src/capabilities/file-uploader.d.ts +0 -4
- package/dist/types/src/capabilities/file-uploader.d.ts.map +0 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/capabilities/markdown.d.ts +0 -4
- package/dist/types/src/capabilities/markdown.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface.d.ts +0 -4
- package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
- package/dist/types/src/components/FileContainer.d.ts +0 -9
- package/dist/types/src/components/FileContainer.d.ts.map +0 -1
- package/dist/types/src/components/FileInput.d.ts.map +0 -1
- package/dist/types/src/components/FilePreview.d.ts +0 -11
- package/dist/types/src/components/FilePreview.d.ts.map +0 -1
- package/src/capabilities/blockstore.ts +0 -19
- package/src/capabilities/file-uploader.ts +0 -27
- package/src/capabilities/intent-resolver.ts +0 -32
- package/src/capabilities/markdown.ts +0 -26
- package/src/capabilities/react-surface.tsx +0 -45
- package/src/components/FilePreview.tsx +0 -23
- /package/dist/types/src/components/{FileInput.d.ts → FileInput/FileInput.d.ts} +0 -0
|
@@ -11,14 +11,14 @@ import { useSpace } from '@dxos/react-client/echo';
|
|
|
11
11
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
12
12
|
import { useThemeContext } from '@dxos/react-ui';
|
|
13
13
|
import { withTheme } from '@dxos/react-ui/testing';
|
|
14
|
+
import { useTextEditor } from '@dxos/react-ui-editor';
|
|
14
15
|
import {
|
|
15
16
|
createBasicExtensions,
|
|
16
17
|
createMarkdownExtensions,
|
|
17
18
|
createThemeExtensions,
|
|
18
19
|
decorateMarkdown,
|
|
19
20
|
processEditorPayload,
|
|
20
|
-
|
|
21
|
-
} from '@dxos/react-ui-editor';
|
|
21
|
+
} from '@dxos/ui-editor';
|
|
22
22
|
|
|
23
23
|
import { create as createBlockstore } from '../blockstore';
|
|
24
24
|
import { upload } from '../helpers';
|
|
@@ -86,15 +86,15 @@ const DefaultStory = () => {
|
|
|
86
86
|
<div className='mb-2'>
|
|
87
87
|
<input type='file' accept='image/*' onChange={onFileChange} />
|
|
88
88
|
</div>
|
|
89
|
-
<div className='
|
|
89
|
+
<div className='w-[50rem]' ref={parentRef} {...focusAttributes} />
|
|
90
90
|
</>
|
|
91
91
|
);
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
const meta = {
|
|
95
|
-
title: 'plugins/plugin-wnfs/image',
|
|
95
|
+
title: 'plugins/plugin-wnfs/extensions/image',
|
|
96
96
|
render: DefaultStory,
|
|
97
|
-
decorators: [withTheme, withClientProvider({ createIdentity: true, createSpace: true })],
|
|
97
|
+
decorators: [withTheme(), withClientProvider({ createIdentity: true, createSpace: true })],
|
|
98
98
|
} satisfies Meta<typeof DefaultStory>;
|
|
99
99
|
|
|
100
100
|
export default meta;
|
package/src/extensions/image.tsx
CHANGED
|
@@ -11,12 +11,12 @@ import { createRoot } from 'react-dom/client';
|
|
|
11
11
|
|
|
12
12
|
import { type Space } from '@dxos/react-client/echo';
|
|
13
13
|
import { Status, ThemeProvider } from '@dxos/react-ui';
|
|
14
|
-
import { focusField } from '@dxos/
|
|
15
|
-
import { defaultTx } from '@dxos/
|
|
14
|
+
import { focusField } from '@dxos/ui-editor';
|
|
15
|
+
import { defaultTx } from '@dxos/ui-theme';
|
|
16
16
|
import { type MaybePromise } from '@dxos/util';
|
|
17
17
|
|
|
18
|
-
import { type WnfsCapabilities } from '../capabilities';
|
|
19
18
|
import { getBlobUrl, getPathFromUrl, loadWnfs } from '../helpers';
|
|
19
|
+
import { type WnfsCapabilities } from '../types';
|
|
20
20
|
|
|
21
21
|
const WAIT_UNTIL_LOADER = 1500;
|
|
22
22
|
|
package/src/helpers/load.ts
CHANGED
|
@@ -7,9 +7,10 @@ import { CID } from 'multiformats';
|
|
|
7
7
|
import * as Uint8Arrays from 'uint8arrays';
|
|
8
8
|
import { AccessKey, PrivateDirectory, PrivateForest, PrivateNode } from 'wnfs';
|
|
9
9
|
|
|
10
|
+
import { Obj } from '@dxos/echo';
|
|
10
11
|
import { type Space } from '@dxos/react-client/echo';
|
|
11
12
|
|
|
12
|
-
import { type WnfsCapabilities } from '../
|
|
13
|
+
import { type WnfsCapabilities } from '../types';
|
|
13
14
|
|
|
14
15
|
import { Rng, store } from './common';
|
|
15
16
|
|
|
@@ -29,8 +30,10 @@ export const loadWnfs = async ({
|
|
|
29
30
|
// TODO(wittjosiah): Remove.
|
|
30
31
|
// Delete old properties if they exist.
|
|
31
32
|
if (space.properties.wnfs_access_key !== undefined && space.properties.wnfs_private_forest_cid !== undefined) {
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
Obj.change(space.properties, (obj) => {
|
|
34
|
+
delete obj['wnfs_access_key'];
|
|
35
|
+
delete obj['wnfs_private_forest_cid'];
|
|
36
|
+
});
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
const cacheKey = space.properties.wnfs?.privateForestCid;
|
|
@@ -65,10 +68,12 @@ const createWnfsDir = async (blockstore: Blockstore, space: Space) => {
|
|
|
65
68
|
|
|
66
69
|
const cidBytes = await newForest.store(wnfsStore);
|
|
67
70
|
|
|
68
|
-
space.properties
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
Obj.change(space.properties, (obj) => {
|
|
72
|
+
obj.wnfs = {
|
|
73
|
+
accessKey: Uint8Arrays.toString(accessKeyRaw.toBytes(), 'base64'),
|
|
74
|
+
privateForestCid: CID.decode(cidBytes).toString(),
|
|
75
|
+
};
|
|
76
|
+
});
|
|
72
77
|
|
|
73
78
|
return {
|
|
74
79
|
directory: dir,
|
package/src/helpers/upload.ts
CHANGED
|
@@ -8,9 +8,10 @@ import * as Raw from 'multiformats/codecs/raw';
|
|
|
8
8
|
import { sha256 } from 'multiformats/hashes/sha2';
|
|
9
9
|
|
|
10
10
|
import type { Space } from '@dxos/client/echo';
|
|
11
|
+
import { Obj } from '@dxos/echo';
|
|
11
12
|
import { log } from '@dxos/log';
|
|
12
13
|
|
|
13
|
-
import { type WnfsCapabilities } from '../
|
|
14
|
+
import { type WnfsCapabilities } from '../types';
|
|
14
15
|
|
|
15
16
|
import { Rng, filePath, store } from './common';
|
|
16
17
|
import { loadWnfs } from './load';
|
|
@@ -46,7 +47,9 @@ export const upload = async ({
|
|
|
46
47
|
const cidBytes = await updatedForest.store(wnfsStore);
|
|
47
48
|
|
|
48
49
|
// Update the forest pointer on the associated space.
|
|
49
|
-
space.properties
|
|
50
|
+
Obj.change(space.properties, (obj) => {
|
|
51
|
+
obj.wnfs.privateForestCid = CID.decode(cidBytes).toString();
|
|
52
|
+
});
|
|
50
53
|
|
|
51
54
|
// Generate `wnfs://` URL & return the info.
|
|
52
55
|
const info = {
|
package/src/index.ts
CHANGED
package/src/meta.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type Plugin } from '@dxos/app-framework';
|
|
6
6
|
import { trim } from '@dxos/util';
|
|
7
7
|
|
|
8
|
-
export const meta:
|
|
9
|
-
id: 'dxos.
|
|
8
|
+
export const meta: Plugin.Meta = {
|
|
9
|
+
id: 'org.dxos.plugin.wnfs',
|
|
10
10
|
name: 'WNFS',
|
|
11
11
|
description: trim`
|
|
12
12
|
Decentralized file storage using the Web Native File System protocol.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { Capability } from '@dxos/app-framework';
|
|
8
|
+
import { invariant } from '@dxos/invariant';
|
|
9
|
+
import { Operation } from '@dxos/operation';
|
|
10
|
+
import { ClientCapabilities } from '@dxos/plugin-client';
|
|
11
|
+
|
|
12
|
+
import { upload } from '../helpers';
|
|
13
|
+
import { WnfsCapabilities, WnfsFile } from '../types';
|
|
14
|
+
|
|
15
|
+
import { CreateFile } from './definitions';
|
|
16
|
+
|
|
17
|
+
const handler: Operation.WithHandler<typeof CreateFile> = CreateFile.pipe(
|
|
18
|
+
Operation.withHandler(
|
|
19
|
+
Effect.fnUntraced(function* ({ file, db }) {
|
|
20
|
+
const client = yield* Capability.get(ClientCapabilities.Client);
|
|
21
|
+
const blockstore = yield* Capability.get(WnfsCapabilities.Blockstore);
|
|
22
|
+
const space = client.spaces.get(db.spaceId);
|
|
23
|
+
invariant(space, 'Space not found');
|
|
24
|
+
const info = yield* Effect.promise(() => upload({ file, blockstore, space }));
|
|
25
|
+
return {
|
|
26
|
+
object: WnfsFile.make({ name: info.name, type: info.type, cid: info.cid }),
|
|
27
|
+
};
|
|
28
|
+
}),
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export default handler;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { Operation } from '@dxos/operation';
|
|
8
|
+
|
|
9
|
+
import { WnfsFile } from '../types';
|
|
10
|
+
|
|
11
|
+
import { Create } from './definitions';
|
|
12
|
+
|
|
13
|
+
const handler: Operation.WithHandler<typeof Create> = Create.pipe(
|
|
14
|
+
Operation.withHandler(
|
|
15
|
+
Effect.fnUntraced(function* ({ name, type, cid }) {
|
|
16
|
+
return {
|
|
17
|
+
object: WnfsFile.make({ name, type, cid }),
|
|
18
|
+
};
|
|
19
|
+
}),
|
|
20
|
+
),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export default handler;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { Capability } from '@dxos/app-framework';
|
|
8
|
+
import { FileInfoSchema } from '@dxos/app-toolkit';
|
|
9
|
+
import { Database } from '@dxos/echo';
|
|
10
|
+
import { Operation } from '@dxos/operation';
|
|
11
|
+
|
|
12
|
+
import { meta } from '../meta';
|
|
13
|
+
import { WnfsFile, WnfsAction } from '../types';
|
|
14
|
+
|
|
15
|
+
const WNFS_OPERATION = `${meta.id}.operation`;
|
|
16
|
+
|
|
17
|
+
export const Create = Operation.make({
|
|
18
|
+
meta: { key: `${WNFS_OPERATION}.create`, name: 'Create WNFS File' },
|
|
19
|
+
services: [Capability.Service],
|
|
20
|
+
input: FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),
|
|
21
|
+
output: Schema.Struct({
|
|
22
|
+
object: WnfsFile.File,
|
|
23
|
+
}),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const Upload = Operation.make({
|
|
27
|
+
meta: { key: `${WNFS_OPERATION}.upload`, name: 'Upload File' },
|
|
28
|
+
services: [Capability.Service],
|
|
29
|
+
input: Schema.extend(WnfsAction.UploadFileSchema, Schema.Struct({ db: Database.Database })),
|
|
30
|
+
output: Schema.required(FileInfoSchema),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const CreateFile = Operation.make({
|
|
34
|
+
meta: { key: `${WNFS_OPERATION}.create-file`, name: 'Create File' },
|
|
35
|
+
services: [Capability.Service],
|
|
36
|
+
input: Schema.extend(WnfsAction.UploadFileSchema, Schema.Struct({ db: Database.Database })),
|
|
37
|
+
output: Schema.Struct({
|
|
38
|
+
object: WnfsFile.File,
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { OperationHandlerSet } from '@dxos/operation';
|
|
6
|
+
|
|
7
|
+
export * as WnfsOperation from './definitions';
|
|
8
|
+
|
|
9
|
+
export const WnfsOperationHandlerSet = OperationHandlerSet.lazy(
|
|
10
|
+
() => import('./create'),
|
|
11
|
+
() => import('./create-file'),
|
|
12
|
+
() => import('./upload'),
|
|
13
|
+
);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import { Capability } from '@dxos/app-framework';
|
|
8
|
+
import { invariant } from '@dxos/invariant';
|
|
9
|
+
import { Operation } from '@dxos/operation';
|
|
10
|
+
import { ClientCapabilities } from '@dxos/plugin-client';
|
|
11
|
+
|
|
12
|
+
import { upload } from '../helpers';
|
|
13
|
+
import { WnfsCapabilities } from '../types';
|
|
14
|
+
|
|
15
|
+
import { Upload } from './definitions';
|
|
16
|
+
|
|
17
|
+
const handler: Operation.WithHandler<typeof Upload> = Upload.pipe(
|
|
18
|
+
Operation.withHandler(
|
|
19
|
+
Effect.fnUntraced(function* ({ file, db }) {
|
|
20
|
+
const client = yield* Capability.get(ClientCapabilities.Client);
|
|
21
|
+
const blockstore = yield* Capability.get(WnfsCapabilities.Blockstore);
|
|
22
|
+
const space = client.spaces.get(db.spaceId);
|
|
23
|
+
invariant(space, 'Space not found');
|
|
24
|
+
const info = yield* Effect.promise(() => upload({ file, blockstore, space }));
|
|
25
|
+
return info;
|
|
26
|
+
}),
|
|
27
|
+
),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export default handler;
|
package/src/translations.ts
CHANGED
|
@@ -12,13 +12,17 @@ export const translations = [
|
|
|
12
12
|
'en-US': {
|
|
13
13
|
[WnfsFile.File.typename]: {
|
|
14
14
|
'typename label': 'File',
|
|
15
|
+
'typename label_zero': 'Files',
|
|
16
|
+
'typename label_one': 'File',
|
|
17
|
+
'typename label_other': 'Files',
|
|
15
18
|
'object name placeholder': 'New file',
|
|
19
|
+
'add object label': 'Add file',
|
|
16
20
|
'rename object label': 'Rename file',
|
|
17
21
|
'delete object label': 'Delete file',
|
|
22
|
+
'object deleted label': 'File deleted',
|
|
18
23
|
},
|
|
19
24
|
[meta.id]: {
|
|
20
25
|
'plugin name': 'Files',
|
|
21
|
-
'delete object label': 'Delete',
|
|
22
26
|
'file input placeholder': 'Drop a file here, or click to select a file',
|
|
23
27
|
},
|
|
24
28
|
},
|
package/src/types/File.ts
CHANGED
|
@@ -4,19 +4,23 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import { Obj, Type } from '@dxos/echo';
|
|
8
|
-
import {
|
|
7
|
+
import { Annotation, Obj, Type } from '@dxos/echo';
|
|
8
|
+
import { FormInputAnnotation } from '@dxos/echo/internal';
|
|
9
9
|
|
|
10
10
|
export const File = Schema.Struct({
|
|
11
11
|
name: Schema.String.pipe(Schema.optional),
|
|
12
|
-
type: Schema.String.pipe(
|
|
13
|
-
cid: Schema.String.pipe(
|
|
14
|
-
timestamp: Schema.String.pipe(
|
|
12
|
+
type: Schema.String.pipe(FormInputAnnotation.set(false)),
|
|
13
|
+
cid: Schema.String.pipe(FormInputAnnotation.set(false)),
|
|
14
|
+
timestamp: Schema.String.pipe(FormInputAnnotation.set(false), Schema.optional),
|
|
15
15
|
}).pipe(
|
|
16
|
-
Type.
|
|
17
|
-
typename: 'dxos.
|
|
16
|
+
Type.object({
|
|
17
|
+
typename: 'org.dxos.type.file',
|
|
18
18
|
version: '0.1.0',
|
|
19
19
|
}),
|
|
20
|
+
Annotation.IconAnnotation.set({
|
|
21
|
+
icon: 'ph--file--regular',
|
|
22
|
+
hue: 'teal',
|
|
23
|
+
}),
|
|
20
24
|
);
|
|
21
25
|
|
|
22
26
|
export type File = Schema.Schema.Type<typeof File>;
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
import { type Blockstore } from 'interface-blockstore';
|
|
6
6
|
import { type PrivateDirectory, type PrivateForest } from 'wnfs';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { Capability } from '@dxos/app-framework';
|
|
9
9
|
import { type SpaceId } from '@dxos/keys';
|
|
10
10
|
|
|
11
11
|
import { meta } from '../meta';
|
|
12
12
|
|
|
13
13
|
export namespace WnfsCapabilities {
|
|
14
|
-
export const Blockstore =
|
|
14
|
+
export const Blockstore = Capability.make<Blockstore>(`${meta.id}.capability.blockstore`);
|
|
15
15
|
|
|
16
16
|
export type Instances = Record<SpaceId, { directory: PrivateDirectory; forest: PrivateForest }>;
|
|
17
|
-
export const Instances =
|
|
17
|
+
export const Instances = Capability.make<Instances>(`${meta.id}.capability.instances`);
|
|
18
18
|
}
|
package/src/types/index.ts
CHANGED
package/src/types/types.ts
CHANGED
|
@@ -4,25 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import { FileInfoSchema } from '@dxos/app-framework';
|
|
8
|
-
import { SpaceSchema } from '@dxos/react-client/echo';
|
|
9
|
-
|
|
10
7
|
import { meta } from '../meta';
|
|
11
8
|
|
|
12
|
-
import * as File from './File';
|
|
13
|
-
|
|
14
9
|
export namespace WnfsAction {
|
|
15
|
-
export
|
|
16
|
-
input: FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),
|
|
17
|
-
output: Schema.Struct({
|
|
18
|
-
object: File.File,
|
|
19
|
-
}),
|
|
20
|
-
}) {}
|
|
21
|
-
|
|
22
|
-
export const UploadAnnotationId = Symbol.for(`${meta.id}/annotation/upload`);
|
|
10
|
+
export const UploadAnnotationId = Symbol.for(`${meta.id}.annotation.upload`);
|
|
23
11
|
|
|
24
12
|
export const UploadFileSchema = Schema.Struct({
|
|
25
|
-
file: Schema.instanceOf(File
|
|
13
|
+
file: Schema.instanceOf(File).annotations({
|
|
26
14
|
[UploadAnnotationId]: {
|
|
27
15
|
// Accept file types.
|
|
28
16
|
'image/*': ['.jpg', '.jpeg', '.png', '.gif'],
|
|
@@ -33,9 +21,4 @@ export namespace WnfsAction {
|
|
|
33
21
|
});
|
|
34
22
|
|
|
35
23
|
export type UploadFileForm = Schema.Schema.Type<typeof UploadFileSchema>;
|
|
36
|
-
|
|
37
|
-
export class Upload extends Schema.TaggedClass<Upload>()(`${meta.id}/action/upload`, {
|
|
38
|
-
input: Schema.extend(UploadFileSchema, Schema.Struct({ space: SpaceSchema })),
|
|
39
|
-
output: Schema.required(FileInfoSchema),
|
|
40
|
-
}) {}
|
|
41
24
|
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import "./chunk-ZFPJA5F4.mjs";
|
|
2
|
-
import {
|
|
3
|
-
filePath,
|
|
4
|
-
getBlobUrl,
|
|
5
|
-
loadWnfs,
|
|
6
|
-
wnfsUrl
|
|
7
|
-
} from "./chunk-D6VTEQIE.mjs";
|
|
8
|
-
import {
|
|
9
|
-
WnfsCapabilities
|
|
10
|
-
} from "./chunk-F4QHZWQD.mjs";
|
|
11
|
-
import "./chunk-OGPGLJCV.mjs";
|
|
12
|
-
|
|
13
|
-
// src/components/FileContainer.tsx
|
|
14
|
-
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
15
|
-
import React2, { useState } from "react";
|
|
16
|
-
import { useCapability } from "@dxos/app-framework/react";
|
|
17
|
-
import { invariant } from "@dxos/invariant";
|
|
18
|
-
import { getSpace } from "@dxos/react-client/echo";
|
|
19
|
-
import { useAsyncEffect } from "@dxos/react-ui";
|
|
20
|
-
import { StackItem } from "@dxos/react-ui-stack";
|
|
21
|
-
|
|
22
|
-
// src/components/FilePreview.tsx
|
|
23
|
-
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
24
|
-
import React from "react";
|
|
25
|
-
import { mx } from "@dxos/react-ui-theme";
|
|
26
|
-
var FilePreview = ({ type, url, classNames }) => {
|
|
27
|
-
var _effect = _useSignals();
|
|
28
|
-
try {
|
|
29
|
-
if (type.startsWith("image/")) {
|
|
30
|
-
return /* @__PURE__ */ React.createElement("img", {
|
|
31
|
-
className: mx("is-full bs-full object-contain", classNames),
|
|
32
|
-
src: url
|
|
33
|
-
});
|
|
34
|
-
} else if (type.startsWith("video/")) {
|
|
35
|
-
return /* @__PURE__ */ React.createElement("video", {
|
|
36
|
-
className: mx("is-full bs-full object-contain", classNames),
|
|
37
|
-
src: url,
|
|
38
|
-
controls: true
|
|
39
|
-
});
|
|
40
|
-
} else {
|
|
41
|
-
return /* @__PURE__ */ React.createElement("iframe", {
|
|
42
|
-
className: mx("is-full bs-full overflow-auto", classNames),
|
|
43
|
-
src: url
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
} finally {
|
|
47
|
-
_effect.f();
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// src/components/FileContainer.tsx
|
|
52
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-wnfs/src/components/FileContainer.tsx";
|
|
53
|
-
var FileContainer = ({ file }) => {
|
|
54
|
-
var _effect = _useSignals2();
|
|
55
|
-
try {
|
|
56
|
-
const blockstore = useCapability(WnfsCapabilities.Blockstore);
|
|
57
|
-
const instances = useCapability(WnfsCapabilities.Instances);
|
|
58
|
-
const [blobUrl, setBlobUrl] = useState();
|
|
59
|
-
useAsyncEffect(async () => {
|
|
60
|
-
const space = getSpace(file);
|
|
61
|
-
invariant(space, void 0, {
|
|
62
|
-
F: __dxlog_file,
|
|
63
|
-
L: 31,
|
|
64
|
-
S: void 0,
|
|
65
|
-
A: [
|
|
66
|
-
"space",
|
|
67
|
-
""
|
|
68
|
-
]
|
|
69
|
-
});
|
|
70
|
-
const { directory, forest } = await loadWnfs({
|
|
71
|
-
blockstore,
|
|
72
|
-
instances,
|
|
73
|
-
space
|
|
74
|
-
});
|
|
75
|
-
const path = filePath(file.cid.toString(), space);
|
|
76
|
-
const url = await getBlobUrl({
|
|
77
|
-
wnfsUrl: wnfsUrl(path),
|
|
78
|
-
blockstore,
|
|
79
|
-
directory,
|
|
80
|
-
forest,
|
|
81
|
-
type: file.type
|
|
82
|
-
});
|
|
83
|
-
setBlobUrl(url);
|
|
84
|
-
}, [
|
|
85
|
-
file
|
|
86
|
-
]);
|
|
87
|
-
if (!blobUrl) {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
return /* @__PURE__ */ React2.createElement(StackItem.Content, null, /* @__PURE__ */ React2.createElement(FilePreview, {
|
|
91
|
-
type: file.type,
|
|
92
|
-
url: blobUrl
|
|
93
|
-
}));
|
|
94
|
-
} finally {
|
|
95
|
-
_effect.f();
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
var FileContainer_default = FileContainer;
|
|
99
|
-
export {
|
|
100
|
-
FileContainer,
|
|
101
|
-
FileContainer_default as default
|
|
102
|
-
};
|
|
103
|
-
//# sourceMappingURL=FileContainer-LLNI7WXR.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/FileContainer.tsx", "../../../src/components/FilePreview.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { useState } from 'react';\n\nimport { useCapability } from '@dxos/app-framework/react';\nimport { invariant } from '@dxos/invariant';\nimport { getSpace } from '@dxos/react-client/echo';\nimport { useAsyncEffect } from '@dxos/react-ui';\nimport { StackItem } from '@dxos/react-ui-stack';\n\nimport { WnfsCapabilities } from '../capabilities';\nimport { filePath, getBlobUrl, loadWnfs, wnfsUrl } from '../helpers';\nimport { type WnfsFile } from '../types';\n\nimport { FilePreview } from './FilePreview';\n\nexport type FileContainerProps = {\n role: string;\n file: WnfsFile.File;\n};\n\nexport const FileContainer = ({ file }: FileContainerProps) => {\n const blockstore = useCapability(WnfsCapabilities.Blockstore);\n const instances = useCapability(WnfsCapabilities.Instances);\n const [blobUrl, setBlobUrl] = useState<string>();\n\n useAsyncEffect(async () => {\n const space = getSpace(file);\n invariant(space);\n const { directory, forest } = await loadWnfs({\n blockstore,\n instances,\n space,\n });\n const path = filePath(file.cid.toString(), space);\n const url = await getBlobUrl({\n wnfsUrl: wnfsUrl(path),\n blockstore,\n directory,\n forest,\n type: file.type,\n });\n setBlobUrl(url);\n }, [file]);\n\n if (!blobUrl) {\n return null;\n }\n\n return (\n <StackItem.Content>\n <FilePreview type={file.type} url={blobUrl} />\n </StackItem.Content>\n );\n};\n\nexport default FileContainer;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport { mx } from '@dxos/react-ui-theme';\n\nexport type FilePreviewProps = ThemedClassName<{ type: string; url: string }>;\n\n/**\n * File/content preview iframe.\n */\nexport const FilePreview = ({ type, url, classNames }: FilePreviewProps) => {\n if (type.startsWith('image/')) {\n return <img className={mx('is-full bs-full object-contain', classNames)} src={url} />;\n } else if (type.startsWith('video/')) {\n return <video className={mx('is-full bs-full object-contain', classNames)} src={url} controls />;\n } else {\n return <iframe className={mx('is-full bs-full overflow-auto', classNames)} src={url} />;\n }\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;AAIA,OAAOA,UAASC,gBAAgB;AAEhC,SAASC,qBAAqB;AAC9B,SAASC,iBAAiB;AAC1B,SAASC,gBAAgB;AACzB,SAASC,sBAAsB;AAC/B,SAASC,iBAAiB;;;;ACN1B,OAAOC,WAAW;AAGlB,SAASC,UAAU;AAOZ,IAAMC,cAAc,CAAC,EAAEC,MAAMC,KAAKC,WAAU,MAAoB;;;AACrE,QAAIF,KAAKG,WAAW,QAAA,GAAW;AAC7B,aAAO,sBAAA,cAACC,OAAAA;QAAIC,WAAWC,GAAG,kCAAkCJ,UAAAA;QAAaK,KAAKN;;IAChF,WAAWD,KAAKG,WAAW,QAAA,GAAW;AACpC,aAAO,sBAAA,cAACK,SAAAA;QAAMH,WAAWC,GAAG,kCAAkCJ,UAAAA;QAAaK,KAAKN;QAAKQ,UAAAA;;IACvF,OAAO;AACL,aAAO,sBAAA,cAACC,UAAAA;QAAOL,WAAWC,GAAG,iCAAiCJ,UAAAA;QAAaK,KAAKN;;IAClF;;;;AACF;;;;ADCO,IAAMU,gBAAgB,CAAC,EAAEC,KAAI,MAAsB;;;AACxD,UAAMC,aAAaC,cAAcC,iBAAiBC,UAAU;AAC5D,UAAMC,YAAYH,cAAcC,iBAAiBG,SAAS;AAC1D,UAAM,CAACC,SAASC,UAAAA,IAAcC,SAAAA;AAE9BC,mBAAe,YAAA;AACb,YAAMC,QAAQC,SAASZ,IAAAA;AACvBa,gBAAUF,OAAAA,QAAAA;;;;;;;;;AACV,YAAM,EAAEG,WAAWC,OAAM,IAAK,MAAMC,SAAS;QAC3Cf;QACAI;QACAM;MACF,CAAA;AACA,YAAMM,OAAOC,SAASlB,KAAKmB,IAAIC,SAAQ,GAAIT,KAAAA;AAC3C,YAAMU,MAAM,MAAMC,WAAW;QAC3BC,SAASA,QAAQN,IAAAA;QACjBhB;QACAa;QACAC;QACAS,MAAMxB,KAAKwB;MACb,CAAA;AACAhB,iBAAWa,GAAAA;IACb,GAAG;MAACrB;KAAK;AAET,QAAI,CAACO,SAAS;AACZ,aAAO;IACT;AAEA,WACE,gBAAAkB,OAAA,cAACC,UAAUC,SAAO,MAChB,gBAAAF,OAAA,cAACG,aAAAA;MAAYJ,MAAMxB,KAAKwB;MAAMH,KAAKd;;;;;AAGzC;AAEA,IAAA,wBAAeR;",
|
|
6
|
-
"names": ["React", "useState", "useCapability", "invariant", "getSpace", "useAsyncEffect", "StackItem", "React", "mx", "FilePreview", "type", "url", "classNames", "startsWith", "img", "className", "mx", "src", "video", "controls", "iframe", "FileContainer", "file", "blockstore", "useCapability", "WnfsCapabilities", "Blockstore", "instances", "Instances", "blobUrl", "setBlobUrl", "useState", "useAsyncEffect", "space", "getSpace", "invariant", "directory", "forest", "loadWnfs", "path", "filePath", "cid", "toString", "url", "getBlobUrl", "wnfsUrl", "type", "React", "StackItem", "Content", "FilePreview"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/blockstore.ts", "../../../src/blockstore.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type PluginContext, contributes } from '@dxos/app-framework';\nimport { ClientCapabilities } from '@dxos/plugin-client';\n\nimport * as Blockstore from '../blockstore';\n\nimport { WnfsCapabilities } from './capabilities';\n\nexport default async (context: PluginContext) => {\n const client = context.getCapability(ClientCapabilities.Client);\n const apiHost = client.config.values.runtime?.services?.edge?.url || 'http://localhost:8787';\n const blockstore = Blockstore.create(apiHost);\n await blockstore.open();\n\n return contributes(WnfsCapabilities.Blockstore, blockstore);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { CarWriter } from '@ipld/car';\nimport type { Block } from '@ipld/car/reader';\nimport { BaseBlockstore } from 'blockstore-core';\nimport { IDBBlockstore } from 'blockstore-idb';\nimport debounce from 'debounce';\nimport * as IDB from 'idb-keyval';\nimport all from 'it-all';\nimport { CID } from 'multiformats';\nimport * as Uint8Arrays from 'uint8arrays';\n\nimport { storeName } from './helpers';\n\nexport const create = (apiHost?: string) => {\n return new MixedBlockstore(apiHost);\n};\n\n/**\n * A blockstore that communicates with the DXOS blob service,\n * and which uses an indexedDB blockstore as a client cache.\n */\nexport class MixedBlockstore extends BaseBlockstore {\n readonly #apiHost: string | undefined;\n readonly #localStore: IDBBlockstore;\n\n #isConnected: boolean;\n #flushQueue: () => void;\n #queue: string[];\n\n constructor(apiHost?: string) {\n super();\n\n this.#apiHost = apiHost ? apiHost.replace(/\\/?$/, '') : undefined;\n this.#localStore = new IDBBlockstore(storeName());\n this.#isConnected = navigator.onLine;\n this.#queue = [];\n\n this.#flushQueue = debounce(this.#flushQueueInt, 5000);\n }\n\n async open(): Promise<void> {\n await this.#localStore.open();\n await this.#restoreQueue();\n\n window.addEventListener('offline', async () => {\n this.#isConnected = false;\n });\n\n window.addEventListener('online', async () => {\n this.#isConnected = true;\n this.#flushQueue();\n });\n }\n\n url(apiHost: string, cid?: CID): string {\n const path = cid ? cid.toString() : '';\n return `${apiHost}/api/file${path.length ? '/' + path : ''}`;\n }\n\n // BLOCKSTORE IMPLEMENTATION\n\n override async delete(key: CID): Promise<void> {\n await this.#localStore.delete(key);\n\n if (this.#isConnected && this.#apiHost) {\n await fetch(this.url(this.#apiHost, key), {\n method: 'DELETE',\n });\n }\n }\n\n override async get(key: CID): Promise<Uint8Array> {\n if (await this.#localStore.has(key)) {\n return await this.#localStore.get(key);\n }\n\n if (this.#isConnected && this.#apiHost) {\n const block = await fetch(this.url(this.#apiHost, key), {\n method: 'GET',\n })\n .then((r) => r.arrayBuffer())\n .then((r) => new Uint8Array(r));\n\n // Make sure it is cached locally\n await this.#localStore.put(key, block);\n\n return block;\n }\n\n return await this.#localStore.get(key);\n }\n\n override async has(key: CID): Promise<boolean> {\n if (await this.#localStore.has(key)) {\n return true;\n }\n\n if (this.#isConnected && this.#apiHost) {\n return await fetch(this.url(this.#apiHost, key), {\n method: 'HEAD',\n }).then((r) => r.ok);\n }\n\n return false;\n }\n\n override async put(key: CID, val: Uint8Array): Promise<CID> {\n await this.#localStore.put(key, val);\n\n await this.#addToQueue(key);\n this.#flushQueue();\n\n return key;\n }\n\n async destroy(): Promise<void> {\n await this.#localStore.destroy();\n }\n\n // REMOTE\n\n async putRemote(key: CID, val: Uint8Array): Promise<void> {\n if (this.#apiHost) {\n await fetch(this.url(this.#apiHost, key), {\n method: 'POST',\n body: val as Uint8Array<ArrayBuffer>,\n });\n }\n }\n\n async putCarRemote(car: Uint8Array): Promise<void> {\n if (this.#apiHost) {\n await fetch(this.url(this.#apiHost), {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/vnd.ipld.car',\n },\n body: car as Uint8Array<ArrayBuffer>,\n });\n }\n }\n\n // QUEUE\n\n readonly queueCacheName = `${storeName()}/state/queue`;\n\n async #addToQueue(key: CID): Promise<void> {\n await this.#saveQueue([...this.#queue, key.toString()]);\n }\n\n async #flushQueueInt(): Promise<void> {\n if (!this.#isConnected || !this.#apiHost) {\n return;\n }\n\n const keys = [...this.#queue];\n if (keys.length === 0) {\n return;\n }\n\n // Collect blocks\n const blocks = await Promise.all(\n keys.map(async (key) => {\n const cid = CID.parse(key);\n const bytes = await this.#localStore.get(cid);\n return { cid, bytes };\n }),\n );\n\n // Create & submit CAR\n const car = await this.#createCar(blocks);\n await this.putCarRemote(car);\n\n // Adjust queue\n const queue = [...this.#queue].filter((k) => {\n if (keys.includes(k)) {\n return false;\n }\n\n return true;\n });\n\n await this.#saveQueue(queue);\n }\n\n async #restoreQueue(): Promise<void> {\n const fromCache = await IDB.get(this.queueCacheName);\n if (fromCache && Array.isArray(fromCache)) {\n this.#queue = fromCache;\n this.#flushQueue();\n }\n }\n\n async #saveQueue(items: string[]): Promise<void> {\n const arr = [...items];\n this.#queue = arr;\n await IDB.set(this.queueCacheName, arr);\n }\n\n // 🛠️\n\n async #createCar(blocks: Block[]): Promise<Uint8Array> {\n const { writer, out } = CarWriter.create();\n const outPromise = all(out);\n\n await Promise.all(\n blocks.map((block) => {\n return writer.put(block);\n }),\n );\n\n await writer.close();\n return Uint8Arrays.concat(await outPromise);\n }\n}\n"],
|
|
5
|
-
"mappings": "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",
|
|
6
|
-
"names": ["contributes", "ClientCapabilities", "CarWriter", "BaseBlockstore", "IDBBlockstore", "debounce", "IDB", "all", "CID", "Uint8Arrays", "create", "apiHost", "MixedBlockstore", "BaseBlockstore", "replace", "undefined", "IDBBlockstore", "storeName", "navigator", "onLine", "debounce", "open", "window", "addEventListener", "url", "cid", "path", "toString", "length", "delete", "key", "fetch", "method", "get", "has", "block", "then", "r", "arrayBuffer", "Uint8Array", "put", "ok", "val", "destroy", "putRemote", "body", "putCarRemote", "car", "headers", "queueCacheName", "keys", "blocks", "Promise", "all", "map", "CID", "parse", "bytes", "queue", "filter", "k", "includes", "fromCache", "Array", "isArray", "items", "arr", "set", "writer", "out", "CarWriter", "outPromise", "close", "concat", "context", "client", "getCapability", "ClientCapabilities", "Client", "apiHost", "config", "values", "runtime", "services", "edge", "url", "blockstore", "create", "open", "contributes", "WnfsCapabilities", "Blockstore"]
|
|
7
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__export,
|
|
3
|
-
meta
|
|
4
|
-
} from "./chunk-OGPGLJCV.mjs";
|
|
5
|
-
|
|
6
|
-
// src/types/File.ts
|
|
7
|
-
var File_exports = {};
|
|
8
|
-
__export(File_exports, {
|
|
9
|
-
File: () => File,
|
|
10
|
-
make: () => make
|
|
11
|
-
});
|
|
12
|
-
import * as Schema from "effect/Schema";
|
|
13
|
-
import { Obj, Type } from "@dxos/echo";
|
|
14
|
-
import { FormAnnotation } from "@dxos/echo/internal";
|
|
15
|
-
var File = Schema.Struct({
|
|
16
|
-
name: Schema.String.pipe(Schema.optional),
|
|
17
|
-
type: Schema.String.pipe(FormAnnotation.set(false)),
|
|
18
|
-
cid: Schema.String.pipe(FormAnnotation.set(false)),
|
|
19
|
-
timestamp: Schema.String.pipe(FormAnnotation.set(false), Schema.optional)
|
|
20
|
-
}).pipe(Type.Obj({
|
|
21
|
-
typename: "dxos.org/type/File",
|
|
22
|
-
version: "0.1.0"
|
|
23
|
-
}));
|
|
24
|
-
var make = (props) => Obj.make(File, props);
|
|
25
|
-
|
|
26
|
-
// src/types/types.ts
|
|
27
|
-
import * as Schema2 from "effect/Schema";
|
|
28
|
-
import { FileInfoSchema } from "@dxos/app-framework";
|
|
29
|
-
import { SpaceSchema } from "@dxos/react-client/echo";
|
|
30
|
-
(function(WnfsAction2) {
|
|
31
|
-
class Create extends Schema2.TaggedClass()(`${meta.id}/action/create`, {
|
|
32
|
-
input: FileInfoSchema.pick("name", "type", "cid").pipe(Schema2.required),
|
|
33
|
-
output: Schema2.Struct({
|
|
34
|
-
object: File
|
|
35
|
-
})
|
|
36
|
-
}) {
|
|
37
|
-
}
|
|
38
|
-
WnfsAction2.Create = Create;
|
|
39
|
-
WnfsAction2.UploadAnnotationId = Symbol.for(`${meta.id}/annotation/upload`);
|
|
40
|
-
WnfsAction2.UploadFileSchema = Schema2.Struct({
|
|
41
|
-
file: Schema2.instanceOf(File).annotations({
|
|
42
|
-
[WnfsAction2.UploadAnnotationId]: {
|
|
43
|
-
// Accept file types.
|
|
44
|
-
"image/*": [
|
|
45
|
-
".jpg",
|
|
46
|
-
".jpeg",
|
|
47
|
-
".png",
|
|
48
|
-
".gif"
|
|
49
|
-
],
|
|
50
|
-
"application/pdf": [
|
|
51
|
-
".pdf"
|
|
52
|
-
]
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
});
|
|
56
|
-
class Upload extends Schema2.TaggedClass()(`${meta.id}/action/upload`, {
|
|
57
|
-
input: Schema2.extend(WnfsAction2.UploadFileSchema, Schema2.Struct({
|
|
58
|
-
space: SpaceSchema
|
|
59
|
-
})),
|
|
60
|
-
output: Schema2.required(FileInfoSchema)
|
|
61
|
-
}) {
|
|
62
|
-
}
|
|
63
|
-
WnfsAction2.Upload = Upload;
|
|
64
|
-
})(WnfsAction || (WnfsAction = {}));
|
|
65
|
-
var WnfsAction;
|
|
66
|
-
|
|
67
|
-
export {
|
|
68
|
-
File_exports,
|
|
69
|
-
WnfsAction
|
|
70
|
-
};
|
|
71
|
-
//# sourceMappingURL=chunk-CWMKN2F6.mjs.map
|