@dxos/plugin-wnfs 0.8.4-main.c4373fc → 0.8.4-main.c85a9c8dae
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-EILNV5LV.mjs +74 -0
- package/dist/lib/browser/FileContainer-EILNV5LV.mjs.map +7 -0
- package/dist/lib/browser/blockstore-Q66HQJ4Q.mjs +191 -0
- package/dist/lib/browser/blockstore-Q66HQJ4Q.mjs.map +7 -0
- package/dist/lib/browser/chunk-BXGCJRL2.mjs +155 -0
- package/dist/lib/browser/chunk-BXGCJRL2.mjs.map +7 -0
- package/dist/lib/browser/chunk-HXVPBJ3A.mjs +56 -0
- package/dist/lib/browser/chunk-HXVPBJ3A.mjs.map +7 -0
- package/dist/lib/browser/{chunk-D6VTEQIE.mjs → chunk-UC4HMNZZ.mjs} +23 -13
- package/dist/lib/browser/chunk-UC4HMNZZ.mjs.map +7 -0
- package/dist/lib/browser/file-uploader-QL4DTOMM.mjs +35 -0
- package/dist/lib/browser/file-uploader-QL4DTOMM.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +85 -84
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/{markdown-5XD3I2NQ.mjs → markdown-AYCVG6TJ.mjs} +33 -41
- package/dist/lib/browser/markdown-AYCVG6TJ.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/operation-resolver-YYWUF6EY.mjs +99 -0
- package/dist/lib/browser/operation-resolver-YYWUF6EY.mjs.map +7 -0
- package/dist/lib/browser/react-surface-3LKVDPH7.mjs +60 -0
- package/dist/lib/browser/react-surface-3LKVDPH7.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +9 -6
- 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-resolver/index.d.ts +3 -0
- package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +5 -0
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.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/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/translations.d.ts +6 -3
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/File.d.ts +16 -0
- package/dist/types/src/types/File.d.ts.map +1 -0
- 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 +2 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +107 -46
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +43 -36
- package/src/WnfsPlugin.tsx +49 -68
- 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-resolver/index.ts +7 -0
- package/src/capabilities/operation-resolver/operation-resolver.ts +62 -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 +3 -3
- package/src/components/FilePreview.tsx +1 -1
- package/src/components/index.ts +1 -4
- package/src/containers/FileContainer/FileContainer.tsx +58 -0
- package/src/containers/FileContainer/index.ts +7 -0
- package/src/containers/index.ts +7 -0
- package/src/extensions/image.stories.tsx +4 -4
- package/src/extensions/image.tsx +6 -6
- package/src/helpers/load.ts +12 -7
- package/src/helpers/upload.ts +5 -2
- package/src/index.ts +1 -1
- package/src/meta.ts +8 -3
- package/src/translations.ts +6 -3
- package/src/types/File.ts +24 -0
- package/src/{capabilities → types}/capabilities.ts +3 -3
- package/src/types/index.ts +2 -1
- package/src/types/types.ts +54 -14
- package/dist/lib/browser/FileContainer-A4OJVMVS.mjs +0 -103
- package/dist/lib/browser/FileContainer-A4OJVMVS.mjs.map +0 -7
- package/dist/lib/browser/blockstore-HK4IYHJJ.mjs +0 -273
- package/dist/lib/browser/blockstore-HK4IYHJJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-D6VTEQIE.mjs.map +0 -7
- package/dist/lib/browser/chunk-FYRZOKHG.mjs +0 -13
- package/dist/lib/browser/chunk-FYRZOKHG.mjs.map +0 -7
- package/dist/lib/browser/chunk-PAIK4SJ3.mjs +0 -16
- package/dist/lib/browser/chunk-PAIK4SJ3.mjs.map +0 -7
- package/dist/lib/browser/chunk-QQB5IBX7.mjs +0 -64
- package/dist/lib/browser/chunk-QQB5IBX7.mjs.map +0 -7
- package/dist/lib/browser/chunk-Y5JMTQ74.mjs +0 -16
- package/dist/lib/browser/chunk-Y5JMTQ74.mjs.map +0 -7
- package/dist/lib/browser/file-uploader-5S37ZZCW.mjs +0 -30
- package/dist/lib/browser/file-uploader-5S37ZZCW.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-3KMIEDBO.mjs +0 -49
- package/dist/lib/browser/intent-resolver-3KMIEDBO.mjs.map +0 -7
- package/dist/lib/browser/markdown-5XD3I2NQ.mjs.map +0 -7
- package/dist/lib/browser/react-surface-5D7M3Y4W.mjs +0 -88
- package/dist/lib/browser/react-surface-5D7M3Y4W.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/types/file.d.ts +0 -16
- package/dist/types/src/types/file.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 -33
- package/src/capabilities/markdown.ts +0 -26
- package/src/capabilities/react-surface.tsx +0 -45
- package/src/components/FileContainer.tsx +0 -49
- package/src/types/file.ts +0 -17
|
@@ -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';
|
|
@@ -92,9 +92,9 @@ const DefaultStory = () => {
|
|
|
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
|
|
|
@@ -165,11 +165,11 @@ class WnfsImageWidget extends WidgetType {
|
|
|
165
165
|
super();
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
override eq(other: this)
|
|
169
|
-
return this._wnfsUrl ===
|
|
168
|
+
override eq(other: this) {
|
|
169
|
+
return this._wnfsUrl === other._wnfsUrl;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
override toDOM(view: EditorView)
|
|
172
|
+
override toDOM(view: EditorView) {
|
|
173
173
|
if (typeof this._url === 'string') {
|
|
174
174
|
return createImg(view, this._url);
|
|
175
175
|
}
|
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, (p) => {
|
|
34
|
+
delete p['wnfs_access_key'];
|
|
35
|
+
delete p['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, (p) => {
|
|
72
|
+
p.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, (p) => {
|
|
51
|
+
p.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,12 +2,17 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type Plugin } from '@dxos/app-framework';
|
|
6
|
+
import { trim } from '@dxos/util';
|
|
6
7
|
|
|
7
|
-
export const meta:
|
|
8
|
+
export const meta: Plugin.Meta = {
|
|
8
9
|
id: 'dxos.org/plugin/wnfs',
|
|
9
10
|
name: 'WNFS',
|
|
10
|
-
description:
|
|
11
|
+
description: trim`
|
|
12
|
+
Decentralized file storage using the Web Native File System protocol.
|
|
13
|
+
Store and sync files with end-to-end encryption across devices without central servers.
|
|
14
|
+
`,
|
|
11
15
|
icon: 'ph--file-cloud--regular',
|
|
16
|
+
iconHue: 'teal',
|
|
12
17
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-wnfs',
|
|
13
18
|
};
|
package/src/translations.ts
CHANGED
|
@@ -5,20 +5,23 @@
|
|
|
5
5
|
import { type Resource } from '@dxos/react-ui';
|
|
6
6
|
|
|
7
7
|
import { meta } from './meta';
|
|
8
|
-
import {
|
|
8
|
+
import { WnfsFile } from './types';
|
|
9
9
|
|
|
10
10
|
export const translations = [
|
|
11
11
|
{
|
|
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',
|
|
16
19
|
'rename object label': 'Rename file',
|
|
17
20
|
'delete object label': 'Delete file',
|
|
21
|
+
'object deleted label': 'File deleted',
|
|
18
22
|
},
|
|
19
23
|
[meta.id]: {
|
|
20
24
|
'plugin name': 'Files',
|
|
21
|
-
'delete object label': 'Delete',
|
|
22
25
|
'file input placeholder': 'Drop a file here, or click to select a file',
|
|
23
26
|
},
|
|
24
27
|
},
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { Obj, Type } from '@dxos/echo';
|
|
8
|
+
import { FormInputAnnotation } from '@dxos/echo/internal';
|
|
9
|
+
|
|
10
|
+
export const File = Schema.Struct({
|
|
11
|
+
name: Schema.String.pipe(Schema.optional),
|
|
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
|
+
}).pipe(
|
|
16
|
+
Type.object({
|
|
17
|
+
typename: 'dxos.org/type/File',
|
|
18
|
+
version: '0.1.0',
|
|
19
|
+
}),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export type File = Schema.Schema.Type<typeof File>;
|
|
23
|
+
|
|
24
|
+
export const make = (props: Obj.MakeProps<typeof File>) => Obj.make(File, props);
|
|
@@ -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,22 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { Capability } from '@dxos/app-framework';
|
|
8
|
+
import { FileInfoSchema } from '@dxos/app-toolkit';
|
|
9
|
+
import { Database } from '@dxos/echo';
|
|
10
|
+
import { Collection } from '@dxos/echo';
|
|
11
|
+
import { Operation } from '@dxos/operation';
|
|
8
12
|
import { SpaceSchema } from '@dxos/react-client/echo';
|
|
9
13
|
|
|
10
14
|
import { meta } from '../meta';
|
|
11
15
|
|
|
12
|
-
import
|
|
16
|
+
import * as File from './File';
|
|
13
17
|
|
|
14
18
|
export namespace WnfsAction {
|
|
15
|
-
export class Create extends Schema.TaggedClass<Create>()(`${meta.id}/action/create`, {
|
|
16
|
-
input: FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),
|
|
17
|
-
output: Schema.Struct({
|
|
18
|
-
object: FileType,
|
|
19
|
-
}),
|
|
20
|
-
}) {}
|
|
21
|
-
|
|
22
19
|
export const UploadAnnotationId = Symbol.for(`${meta.id}/annotation/upload`);
|
|
23
20
|
|
|
24
21
|
export const UploadFileSchema = Schema.Struct({
|
|
25
|
-
file: Schema.instanceOf(File).annotations({
|
|
22
|
+
file: Schema.instanceOf(File.File).annotations({
|
|
26
23
|
[UploadAnnotationId]: {
|
|
27
24
|
// Accept file types.
|
|
28
25
|
'image/*': ['.jpg', '.jpeg', '.png', '.gif'],
|
|
@@ -33,9 +30,52 @@ export namespace WnfsAction {
|
|
|
33
30
|
});
|
|
34
31
|
|
|
35
32
|
export type UploadFileForm = Schema.Schema.Type<typeof UploadFileSchema>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const WNFS_OPERATION = `${meta.id}/operation`;
|
|
36
|
+
|
|
37
|
+
export namespace WnfsOperation {
|
|
38
|
+
export const OnCreateSpace = Operation.make({
|
|
39
|
+
meta: { key: `${WNFS_OPERATION}/on-create-space`, name: 'On Create Space' },
|
|
40
|
+
services: [Capability.Service],
|
|
41
|
+
schema: {
|
|
42
|
+
input: Schema.Struct({
|
|
43
|
+
space: SpaceSchema,
|
|
44
|
+
rootCollection: Collection.Collection,
|
|
45
|
+
isDefault: Schema.optional(Schema.Boolean),
|
|
46
|
+
}),
|
|
47
|
+
output: Schema.Void,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
36
50
|
|
|
37
|
-
export
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
51
|
+
export const Create = Operation.make({
|
|
52
|
+
meta: { key: `${WNFS_OPERATION}/create`, name: 'Create WNFS File' },
|
|
53
|
+
services: [Capability.Service],
|
|
54
|
+
schema: {
|
|
55
|
+
input: FileInfoSchema.pick('name', 'type', 'cid').pipe(Schema.required),
|
|
56
|
+
output: Schema.Struct({
|
|
57
|
+
object: File.File,
|
|
58
|
+
}),
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export const Upload = Operation.make({
|
|
63
|
+
meta: { key: `${WNFS_OPERATION}/upload`, name: 'Upload File' },
|
|
64
|
+
services: [Capability.Service],
|
|
65
|
+
schema: {
|
|
66
|
+
input: Schema.extend(WnfsAction.UploadFileSchema, Schema.Struct({ db: Database.Database })),
|
|
67
|
+
output: Schema.required(FileInfoSchema),
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
export const CreateFile = Operation.make({
|
|
72
|
+
meta: { key: `${WNFS_OPERATION}/create-file`, name: 'Create File' },
|
|
73
|
+
services: [Capability.Service],
|
|
74
|
+
schema: {
|
|
75
|
+
input: Schema.extend(WnfsAction.UploadFileSchema, Schema.Struct({ db: Database.Database })),
|
|
76
|
+
output: Schema.Struct({
|
|
77
|
+
object: File.File,
|
|
78
|
+
}),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
41
81
|
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import "./chunk-Y5JMTQ74.mjs";
|
|
2
|
-
import {
|
|
3
|
-
filePath,
|
|
4
|
-
getBlobUrl,
|
|
5
|
-
loadWnfs,
|
|
6
|
-
wnfsUrl
|
|
7
|
-
} from "./chunk-D6VTEQIE.mjs";
|
|
8
|
-
import {
|
|
9
|
-
WnfsCapabilities
|
|
10
|
-
} from "./chunk-PAIK4SJ3.mjs";
|
|
11
|
-
import "./chunk-FYRZOKHG.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";
|
|
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("w-full h-full object-contain", classNames),
|
|
32
|
-
src: url
|
|
33
|
-
});
|
|
34
|
-
} else if (type.startsWith("video/")) {
|
|
35
|
-
return /* @__PURE__ */ React.createElement("video", {
|
|
36
|
-
className: mx("w-full h-full object-contain", classNames),
|
|
37
|
-
src: url,
|
|
38
|
-
controls: true
|
|
39
|
-
});
|
|
40
|
-
} else {
|
|
41
|
-
return /* @__PURE__ */ React.createElement("iframe", {
|
|
42
|
-
className: mx("w-full h-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-A4OJVMVS.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';\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 FileType } from '../types';\n\nimport { FilePreview } from './FilePreview';\n\nexport type FileContainerProps = {\n role: string;\n file: FileType;\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({ blockstore, instances, space });\n const path = filePath(file.cid.toString(), space);\n const url = await getBlobUrl({ wnfsUrl: wnfsUrl(path), blockstore, directory, forest, type: file.type });\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('w-full h-full object-contain', classNames)} src={url} />;\n } else if (type.startsWith('video/')) {\n return <video className={mx('w-full h-full object-contain', classNames)} src={url} controls />;\n } else {\n return <iframe className={mx('w-full h-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,gCAAgCJ,UAAAA;QAAaK,KAAKN;;IAC9E,WAAWD,KAAKG,WAAW,QAAA,GAAW;AACpC,aAAO,sBAAA,cAACK,SAAAA;QAAMH,WAAWC,GAAG,gCAAgCJ,UAAAA;QAAaK,KAAKN;QAAKQ,UAAAA;;IACrF,OAAO;AACL,aAAO,sBAAA,cAACC,UAAAA;QAAOL,WAAWC,GAAG,+BAA+BJ,UAAAA;QAAaK,KAAKN;;IAChF;;;;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;QAAEf;QAAYI;QAAWM;MAAM,CAAA;AAC5E,YAAMM,OAAOC,SAASlB,KAAKmB,IAAIC,SAAQ,GAAIT,KAAAA;AAC3C,YAAMU,MAAM,MAAMC,WAAW;QAAEC,SAASA,QAAQN,IAAAA;QAAOhB;QAAYa;QAAWC;QAAQS,MAAMxB,KAAKwB;MAAK,CAAA;AACtGhB,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
|
-
}
|