@dxos/react-client 2.29.2-dev.f64f2a6f → 2.30.0
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/.rush/temp/package-deps_build.json +6 -9
- package/.rush/temp/package-deps_build:test.json +6 -9
- package/.rush/temp/package-deps_prerelease.json +6 -9
- package/.rush/temp/shrinkwrap-deps.json +1 -73
- package/dist/src/hooks/index.d.ts +0 -1
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +0 -1
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/invitations/useHaloInvitations.d.ts.map +1 -1
- package/dist/src/hooks/invitations/useHaloInvitations.js.map +1 -1
- package/dist/src/hooks/invitations/useInvitations.d.ts.map +1 -1
- package/dist/src/hooks/invitations/useInvitations.js.map +1 -1
- package/dist/src/hooks/invitations/usePartyInvitations.d.ts.map +1 -1
- package/dist/src/hooks/invitations/usePartyInvitations.js +2 -1
- package/dist/src/hooks/invitations/usePartyInvitations.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/out/book/esbuild-server-book.js +13588 -39323
- package/package.json +23 -24
- package/src/hooks/index.ts +0 -1
- package/src/hooks/invitations/useHaloInvitations.ts +2 -2
- package/src/hooks/invitations/useInvitations.ts +0 -1
- package/src/hooks/invitations/usePartyInvitations.ts +2 -1
- package/dist/src/hooks/ipfs/index.d.ts +0 -3
- package/dist/src/hooks/ipfs/index.d.ts.map +0 -1
- package/dist/src/hooks/ipfs/index.js +0 -18
- package/dist/src/hooks/ipfs/index.js.map +0 -1
- package/dist/src/hooks/ipfs/useIpfsClient.d.ts +0 -17
- package/dist/src/hooks/ipfs/useIpfsClient.d.ts.map +0 -1
- package/dist/src/hooks/ipfs/useIpfsClient.js +0 -41
- package/dist/src/hooks/ipfs/useIpfsClient.js.map +0 -1
- package/dist/src/hooks/ipfs/useIpfsFiles.d.ts +0 -19
- package/dist/src/hooks/ipfs/useIpfsFiles.d.ts.map +0 -1
- package/dist/src/hooks/ipfs/useIpfsFiles.js +0 -48
- package/dist/src/hooks/ipfs/useIpfsFiles.js.map +0 -1
- package/dxos-react-client-2.29.2-dev.f64f2a6f.tgz +0 -0
- package/src/hooks/ipfs/index.ts +0 -6
- package/src/hooks/ipfs/useIpfsClient.ts +0 -36
- package/src/hooks/ipfs/useIpfsFiles.ts +0 -59
package/package.json
CHANGED
|
@@ -1,39 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-client",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.30.0",
|
|
4
4
|
"description": "React client API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "DXOS.org",
|
|
7
7
|
"main": "dist/src/index.js",
|
|
8
8
|
"types": "dist/src/index.d.ts",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"book": "toolchain book",
|
|
11
|
-
"build": "toolchain build",
|
|
12
|
-
"build:book": "toolchain build:book",
|
|
13
|
-
"build:test": "toolchain build:test",
|
|
14
|
-
"lint": "toolchain lint",
|
|
15
|
-
"test": "toolchain test"
|
|
16
|
-
},
|
|
17
9
|
"dependencies": {
|
|
18
|
-
"@dxos/async": "
|
|
19
|
-
"@dxos/bot-factory-client": "
|
|
20
|
-
"@dxos/client": "
|
|
21
|
-
"@dxos/config": "
|
|
22
|
-
"@dxos/credentials": "
|
|
23
|
-
"@dxos/crypto": "
|
|
24
|
-
"@dxos/debug": "
|
|
25
|
-
"@dxos/echo-db": "
|
|
26
|
-
"@dxos/network-manager": "
|
|
27
|
-
"@dxos/util": "
|
|
10
|
+
"@dxos/async": "2.30.0",
|
|
11
|
+
"@dxos/bot-factory-client": "2.30.0",
|
|
12
|
+
"@dxos/client": "2.30.0",
|
|
13
|
+
"@dxos/config": "2.30.0",
|
|
14
|
+
"@dxos/credentials": "2.30.0",
|
|
15
|
+
"@dxos/crypto": "2.30.0",
|
|
16
|
+
"@dxos/debug": "2.30.0",
|
|
17
|
+
"@dxos/echo-db": "2.30.0",
|
|
18
|
+
"@dxos/network-manager": "2.30.0",
|
|
19
|
+
"@dxos/util": "2.30.0",
|
|
28
20
|
"assert": "^2.0.0",
|
|
29
21
|
"debug": "^4.3.3",
|
|
30
|
-
"ipfs-http-client": "~56.0.1",
|
|
31
22
|
"use-subscription": "^1.4.1"
|
|
32
23
|
},
|
|
33
24
|
"devDependencies": {
|
|
34
25
|
"@dxos/esbuild-plugins": "~2.28.7",
|
|
35
26
|
"@dxos/eslint-plugin": "~1.0.27",
|
|
36
|
-
"@dxos/protocols-toolchain": "
|
|
27
|
+
"@dxos/protocols-toolchain": "2.30.0",
|
|
37
28
|
"@mui/material": "^5.4.2",
|
|
38
29
|
"@testing-library/react": "^11.0.4",
|
|
39
30
|
"@testing-library/react-hooks": "5.1.2",
|
|
@@ -48,7 +39,6 @@
|
|
|
48
39
|
"expect": "~27.0.2",
|
|
49
40
|
"fork-ts-checker-webpack-plugin": "~6.2.5",
|
|
50
41
|
"level-js": "^5.0.2",
|
|
51
|
-
"node-fetch": "^2.6.0",
|
|
52
42
|
"react": "^17.0.2",
|
|
53
43
|
"react-dom": "^17.0.2",
|
|
54
44
|
"react-test-renderer": "^17.0.2",
|
|
@@ -64,5 +54,14 @@
|
|
|
64
54
|
"jsdom": true,
|
|
65
55
|
"forceCloseTests": true,
|
|
66
56
|
"testingFramework": "mocha"
|
|
67
|
-
}
|
|
68
|
-
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"book": "toolchain book",
|
|
60
|
+
"build": "toolchain build",
|
|
61
|
+
"build:book": "toolchain build:book",
|
|
62
|
+
"build:test": "toolchain build:test",
|
|
63
|
+
"lint": "toolchain lint",
|
|
64
|
+
"test": "toolchain test"
|
|
65
|
+
},
|
|
66
|
+
"readme": "# @dxos/react-client\n\nA react implementation of the DXOS Client APIs.\n\n## Install\n\n```bash\ngit clone git@github.com:dxos/protocols.git\ncd protocols\nrush update\nrush build\n\ncd packages/sdk/demos\nrushx book\n```\n\n## Usage\n\nThe snippet below illustrates a self-contained DXOS application that uses providers to create the client and instantiate a user profile.\n\n```javascript\nimport { useClient, ClientProvider, ProfileInitializer } from '@dxos/react-client';\nimport React from 'react';\nimport ReactDOM from 'react-dom';\n\nconst App = () => {\n const client = useClient();\n\n return (\n <pre>{JSON.stringify(client.info())}</pre>\n );\n};\n\nconst Root = () => (\n <ClientProvider>\n <ProfileInitializer>\n <App />\n </ProfileInitializer>\n </ClientProvider>\n);\n\nReactDOM.render(<Root/>, document.getElementById('root'));\n```\n\n## Storybooks\n\nThe [HALO Invitation Story](./stories/halo-invitations.stories.tsx) demonstrates multiple clients (devices) joining the same HALO.\n\nhttps://user-images.githubusercontent.com/3523355/137532718-a21f1f27-9854-4c0b-831a-e9ff92feac49.mov\n\nThe [Party Invitation Story](./stories/party-invitations.stories.tsx) demonstrates multiple clients creating and sharing parties.\n\nhttps://user-images.githubusercontent.com/3523355/137532717-e77395dc-96f9-4e4b-8f67-e6bd026a3abe.mov\n\n\n## Contributing\n\nPRs accepted.\n\n## License\n\nAGPL-3.0 © DXOS\n"
|
|
67
|
+
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Client } from '@dxos/client';
|
|
5
|
+
import { Client, HaloProxy } from '@dxos/client';
|
|
6
6
|
|
|
7
7
|
import { useInvitations } from './useInvitations';
|
|
8
8
|
|
|
9
9
|
export const useHaloInvitations = (client: Client) => {
|
|
10
|
-
return useInvitations(client.halo.invitationProxy);
|
|
10
|
+
return useInvitations((client.halo as HaloProxy).invitationProxy);
|
|
11
11
|
};
|
|
@@ -11,7 +11,6 @@ export const useInvitations = (invitationProxy: InvitationProxy | undefined) =>
|
|
|
11
11
|
|
|
12
12
|
useEffect(() => {
|
|
13
13
|
setInvitations(invitationProxy?.activeInvitations ?? []);
|
|
14
|
-
|
|
15
14
|
return invitationProxy?.invitationsUpdate.on(() => {
|
|
16
15
|
setInvitations([...invitationProxy.activeInvitations]);
|
|
17
16
|
});
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { PartyProxy } from '@dxos/client';
|
|
5
6
|
import { PublicKey } from '@dxos/crypto';
|
|
6
7
|
|
|
7
8
|
import { useParty } from '../echo-queries';
|
|
@@ -9,5 +10,5 @@ import { useInvitations } from './useInvitations';
|
|
|
9
10
|
|
|
10
11
|
export const usePartyInvitations = (partyKey?: PublicKey) => {
|
|
11
12
|
const party = useParty(partyKey);
|
|
12
|
-
return useInvitations(party?.invitationProxy);
|
|
13
|
+
return useInvitations((party as PartyProxy)?.invitationProxy);
|
|
13
14
|
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/ipfs/index.ts"],"names":[],"mappings":"AAIA,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// Copyright 2022 DXOS.org
|
|
4
|
-
//
|
|
5
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
8
|
-
}) : (function(o, m, k, k2) {
|
|
9
|
-
if (k2 === undefined) k2 = k;
|
|
10
|
-
o[k2] = m[k];
|
|
11
|
-
}));
|
|
12
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
13
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
14
|
-
};
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
__exportStar(require("./useIpfsClient"), exports);
|
|
17
|
-
__exportStar(require("./useIpfsFiles"), exports);
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/hooks/ipfs/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;AAEF,kDAAgC;AAChC,iDAA+B"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { CID } from 'ipfs-http-client';
|
|
2
|
-
/**
|
|
3
|
-
* Return URL to IPFS resource on local gateway.
|
|
4
|
-
* @param gateway
|
|
5
|
-
* @param cid
|
|
6
|
-
* @param filename
|
|
7
|
-
*/
|
|
8
|
-
export declare const getIpfsUrl: (gateway: string, cid: CID, filename?: string | undefined) => string;
|
|
9
|
-
/**
|
|
10
|
-
* https://www.npmjs.com/package/ipfs-http-client#example
|
|
11
|
-
* NOTE: We need to run our own servers to enable CORS.
|
|
12
|
-
* Ports
|
|
13
|
-
* - 8001 Gateway
|
|
14
|
-
* - 5001 API
|
|
15
|
-
*/
|
|
16
|
-
export declare const useIpfsClient: (url?: string | undefined) => import("ipfs-http-client/types/src/types").IPFSHTTPClient | undefined;
|
|
17
|
-
//# sourceMappingURL=useIpfsClient.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useIpfsClient.d.ts","sourceRoot":"","sources":["../../../../src/hooks/ipfs/useIpfsClient.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,GAAG,EAAU,MAAM,kBAAkB,CAAC;AAI/C;;;;;GAKG;AACH,eAAO,MAAM,UAAU,YAAa,MAAM,OAAO,GAAG,0CAGnD,CAAC;AAEF;;;;;;GAMG;AAEH,eAAO,MAAM,aAAa,qGAQzB,CAAC"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// Copyright 2022 DXOS.org
|
|
4
|
-
//
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.useIpfsClient = exports.getIpfsUrl = void 0;
|
|
10
|
-
const ipfs_http_client_1 = require("ipfs-http-client");
|
|
11
|
-
const path_1 = __importDefault(require("path"));
|
|
12
|
-
const react_1 = require("react");
|
|
13
|
-
/**
|
|
14
|
-
* Return URL to IPFS resource on local gateway.
|
|
15
|
-
* @param gateway
|
|
16
|
-
* @param cid
|
|
17
|
-
* @param filename
|
|
18
|
-
*/
|
|
19
|
-
const getIpfsUrl = (gateway, cid, filename) => {
|
|
20
|
-
const args = filename ? [`filename=${encodeURI(filename)}`] : [];
|
|
21
|
-
return path_1.default.join(gateway, String(cid), '?', args.join('&'));
|
|
22
|
-
};
|
|
23
|
-
exports.getIpfsUrl = getIpfsUrl;
|
|
24
|
-
/**
|
|
25
|
-
* https://www.npmjs.com/package/ipfs-http-client#example
|
|
26
|
-
* NOTE: We need to run our own servers to enable CORS.
|
|
27
|
-
* Ports
|
|
28
|
-
* - 8001 Gateway
|
|
29
|
-
* - 5001 API
|
|
30
|
-
*/
|
|
31
|
-
// TODO(kaplanski): Factor out IPFS related functionality to its own package.
|
|
32
|
-
const useIpfsClient = (url) => {
|
|
33
|
-
return (0, react_1.useMemo)(() => {
|
|
34
|
-
if (!url) {
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
return (0, ipfs_http_client_1.create)({ url });
|
|
38
|
-
}, [url]);
|
|
39
|
-
};
|
|
40
|
-
exports.useIpfsClient = useIpfsClient;
|
|
41
|
-
//# sourceMappingURL=useIpfsClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useIpfsClient.js","sourceRoot":"","sources":["../../../../src/hooks/ipfs/useIpfsClient.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAEF,uDAA+C;AAC/C,gDAAwB;AACxB,iCAAgC;AAEhC;;;;;GAKG;AACI,MAAM,UAAU,GAAG,CAAC,OAAe,EAAE,GAAQ,EAAE,QAAiB,EAAE,EAAE;IACzE,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,YAAY,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACjE,OAAO,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC9D,CAAC,CAAC;AAHW,QAAA,UAAU,cAGrB;AAEF;;;;;;GAMG;AACH,6EAA6E;AACtE,MAAM,aAAa,GAAG,CAAC,GAAY,EAAE,EAAE;IAC5C,OAAO,IAAA,eAAO,EAAC,GAAG,EAAE;QAClB,IAAI,CAAC,GAAG,EAAE;YACR,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,IAAA,yBAAM,EAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACzB,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;AACZ,CAAC,CAAC;AARW,QAAA,aAAa,iBAQxB"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { CID, IPFSHTTPClient } from 'ipfs-http-client';
|
|
2
|
-
import { Party } from '@dxos/client';
|
|
3
|
-
export declare type IPFSFile = {
|
|
4
|
-
filename?: string;
|
|
5
|
-
cid: CID;
|
|
6
|
-
size?: number;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Returns a list of mapped IPFS files.
|
|
10
|
-
* @param party
|
|
11
|
-
* @param type
|
|
12
|
-
*/
|
|
13
|
-
export declare const useIpfsFiles: (party: Party | undefined, type: string) => IPFSFile[];
|
|
14
|
-
export declare const uploadFilesToIpfs: (ipfsClient: IPFSHTTPClient, files: File[], onError?: ((error: Error) => void) | undefined) => Promise<({
|
|
15
|
-
cid: string;
|
|
16
|
-
size: number;
|
|
17
|
-
filename: string;
|
|
18
|
-
} | undefined)[]>;
|
|
19
|
-
//# sourceMappingURL=useIpfsFiles.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useIpfsFiles.d.ts","sourceRoot":"","sources":["../../../../src/hooks/ipfs/useIpfsFiles.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGvD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAIrC,oBAAY,QAAQ,GAAG;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,GAAG,EAAE,GAAG,CAAA;IACR,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,UAAW,KAAK,GAAG,SAAS,QAAQ,MAAM,eAYlE,CAAC;AAGF,eAAO,MAAM,iBAAiB,eAChB,cAAc,SACnB,IAAI,EAAE,qBACK,KAAK,KAAK,IAAI;;;;iBAkBjC,CAAC"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// Copyright 2022 DXOS.org
|
|
4
|
-
//
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.uploadFilesToIpfs = exports.useIpfsFiles = void 0;
|
|
7
|
-
const react_1 = require("react");
|
|
8
|
-
const echo_selections_1 = require("../echo-selections");
|
|
9
|
-
/**
|
|
10
|
-
* Returns a list of mapped IPFS files.
|
|
11
|
-
* @param party
|
|
12
|
-
* @param type
|
|
13
|
-
*/
|
|
14
|
-
const useIpfsFiles = (party, type) => {
|
|
15
|
-
var _a;
|
|
16
|
-
// TODO(burdon): Schema definitions for types?
|
|
17
|
-
// TODO(burdon): Use reducer to do mapping?
|
|
18
|
-
const items = (0, echo_selections_1.useSelection)(party === null || party === void 0 ? void 0 : party.select().filter({ type }));
|
|
19
|
-
const files = (_a = (0, react_1.useMemo)(() => items === null || items === void 0 ? void 0 : items.map(item => ({
|
|
20
|
-
filename: item.model.getProperty('filename'),
|
|
21
|
-
cid: item.model.getProperty('cid'),
|
|
22
|
-
size: item.model.getProperty('size')
|
|
23
|
-
})), [items])) !== null && _a !== void 0 ? _a : [];
|
|
24
|
-
return files;
|
|
25
|
-
};
|
|
26
|
-
exports.useIpfsFiles = useIpfsFiles;
|
|
27
|
-
// TODO(wittjosiah): This is not returning IPFSFiles.
|
|
28
|
-
const uploadFilesToIpfs = async (ipfsClient, files, onError) => {
|
|
29
|
-
return await Promise.all(files.map(async (file) => {
|
|
30
|
-
// https://docs.ipfs.io/reference/js/api
|
|
31
|
-
// https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-http-client
|
|
32
|
-
try {
|
|
33
|
-
const { cid, path, size } = await ipfsClient.add(file);
|
|
34
|
-
await ipfsClient.pin.add(cid);
|
|
35
|
-
// TODO(kaplanski): path is CID v0. cid is CID v1. Current default is v0, but will be updated to v1 in the future. We'll need to update to support v1.
|
|
36
|
-
return {
|
|
37
|
-
cid: path,
|
|
38
|
-
size,
|
|
39
|
-
filename: file.name
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
catch (err) {
|
|
43
|
-
onError === null || onError === void 0 ? void 0 : onError(err instanceof Error ? err : new Error(err)); // TODO(burdon): Generalize.
|
|
44
|
-
}
|
|
45
|
-
}));
|
|
46
|
-
};
|
|
47
|
-
exports.uploadFilesToIpfs = uploadFilesToIpfs;
|
|
48
|
-
//# sourceMappingURL=useIpfsFiles.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useIpfsFiles.js","sourceRoot":"","sources":["../../../../src/hooks/ipfs/useIpfsFiles.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;AAGF,iCAAgC;AAIhC,wDAAkD;AAQlD;;;;GAIG;AACI,MAAM,YAAY,GAAG,CAAC,KAAwB,EAAE,IAAY,EAAE,EAAE;;IACrE,8CAA8C;IAC9C,2CAA2C;IAC3C,MAAM,KAAK,GAAG,IAAA,8BAAY,EAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAAM,GAAG,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAE7D,MAAM,KAAK,GAAe,MAAA,IAAA,eAAO,EAAC,GAAG,EAAE,CAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC1D,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,UAAU,CAAC;QAC5C,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC;QAClC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC;KACrC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,mCAAI,EAAE,CAAC;IAEpB,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAZW,QAAA,YAAY,gBAYvB;AAEF,qDAAqD;AAC9C,MAAM,iBAAiB,GAAG,KAAK,EACpC,UAA0B,EAC1B,KAAa,EACb,OAAgC,EAChC,EAAE;IACF,OAAO,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QAChD,wCAAwC;QACxC,wEAAwE;QACxE,IAAI;YACF,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACvD,MAAM,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC9B,sJAAsJ;YACtJ,OAAO;gBACL,GAAG,EAAE,IAAI;gBACT,IAAI;gBACJ,QAAQ,EAAE,IAAI,CAAC,IAAI;aACpB,CAAC;SACH;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,GAAa,CAAC,CAAC,CAAC,CAAC,4BAA4B;SAC/F;IACH,CAAC,CAAC,CAAC,CAAC;AACN,CAAC,CAAC;AArBW,QAAA,iBAAiB,qBAqB5B"}
|
|
Binary file
|
package/src/hooks/ipfs/index.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2022 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { CID, create } from 'ipfs-http-client';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
import { useMemo } from 'react';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Return URL to IPFS resource on local gateway.
|
|
11
|
-
* @param gateway
|
|
12
|
-
* @param cid
|
|
13
|
-
* @param filename
|
|
14
|
-
*/
|
|
15
|
-
export const getIpfsUrl = (gateway: string, cid: CID, filename?: string) => {
|
|
16
|
-
const args = filename ? [`filename=${encodeURI(filename)}`] : [];
|
|
17
|
-
return path.join(gateway, String(cid), '?', args.join('&'));
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* https://www.npmjs.com/package/ipfs-http-client#example
|
|
22
|
-
* NOTE: We need to run our own servers to enable CORS.
|
|
23
|
-
* Ports
|
|
24
|
-
* - 8001 Gateway
|
|
25
|
-
* - 5001 API
|
|
26
|
-
*/
|
|
27
|
-
// TODO(kaplanski): Factor out IPFS related functionality to its own package.
|
|
28
|
-
export const useIpfsClient = (url?: string) => {
|
|
29
|
-
return useMemo(() => {
|
|
30
|
-
if (!url) {
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return create({ url });
|
|
35
|
-
}, [url]);
|
|
36
|
-
};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2022 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { CID, IPFSHTTPClient } from 'ipfs-http-client';
|
|
6
|
-
import { useMemo } from 'react';
|
|
7
|
-
|
|
8
|
-
import { Party } from '@dxos/client';
|
|
9
|
-
|
|
10
|
-
import { useSelection } from '../echo-selections';
|
|
11
|
-
|
|
12
|
-
export type IPFSFile = {
|
|
13
|
-
filename?: string
|
|
14
|
-
cid: CID
|
|
15
|
-
size?: number
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Returns a list of mapped IPFS files.
|
|
20
|
-
* @param party
|
|
21
|
-
* @param type
|
|
22
|
-
*/
|
|
23
|
-
export const useIpfsFiles = (party: Party | undefined, type: string) => {
|
|
24
|
-
// TODO(burdon): Schema definitions for types?
|
|
25
|
-
// TODO(burdon): Use reducer to do mapping?
|
|
26
|
-
const items = useSelection(party?.select().filter({ type }));
|
|
27
|
-
|
|
28
|
-
const files: IPFSFile[] = useMemo(() => items?.map(item => ({
|
|
29
|
-
filename: item.model.getProperty('filename'),
|
|
30
|
-
cid: item.model.getProperty('cid'),
|
|
31
|
-
size: item.model.getProperty('size')
|
|
32
|
-
})), [items]) ?? [];
|
|
33
|
-
|
|
34
|
-
return files;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// TODO(wittjosiah): This is not returning IPFSFiles.
|
|
38
|
-
export const uploadFilesToIpfs = async (
|
|
39
|
-
ipfsClient: IPFSHTTPClient,
|
|
40
|
-
files: File[],
|
|
41
|
-
onError?: (error: Error) => void
|
|
42
|
-
) => {
|
|
43
|
-
return await Promise.all(files.map(async (file) => {
|
|
44
|
-
// https://docs.ipfs.io/reference/js/api
|
|
45
|
-
// https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-http-client
|
|
46
|
-
try {
|
|
47
|
-
const { cid, path, size } = await ipfsClient.add(file);
|
|
48
|
-
await ipfsClient.pin.add(cid);
|
|
49
|
-
// TODO(kaplanski): path is CID v0. cid is CID v1. Current default is v0, but will be updated to v1 in the future. We'll need to update to support v1.
|
|
50
|
-
return {
|
|
51
|
-
cid: path,
|
|
52
|
-
size,
|
|
53
|
-
filename: file.name
|
|
54
|
-
};
|
|
55
|
-
} catch (err) {
|
|
56
|
-
onError?.(err instanceof Error ? err : new Error(err as string)); // TODO(burdon): Generalize.
|
|
57
|
-
}
|
|
58
|
-
}));
|
|
59
|
-
};
|