@holochain-open-dev/file-storage 0.0.3 → 0.1.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/README.md +2 -2
- package/dist/definitions/file-storage-context.d.ts +1 -0
- package/dist/definitions/file-storage-context.js +9 -0
- package/dist/definitions/file-storage-context.js.map +1 -0
- package/dist/elements/file-storage-context.d.ts +7 -0
- package/dist/elements/file-storage-context.js +20 -0
- package/dist/elements/file-storage-context.js.map +1 -0
- package/dist/elements/show-image.d.ts +20 -7
- package/dist/elements/show-image.js +20 -14
- package/dist/elements/show-image.js.map +1 -1
- package/dist/elements/upload-files.d.ts +12 -3
- package/dist/elements/upload-files.js +19 -12
- package/dist/elements/upload-files.js.map +1 -1
- package/dist/file-storage-client.d.ts +9 -8
- package/dist/file-storage-client.js +18 -11
- package/dist/file-storage-client.js.map +1 -1
- package/dist/holochain-dropzone.d.ts +2 -2
- package/dist/holochain-dropzone.js +7 -8
- package/dist/holochain-dropzone.js.map +1 -1
- package/dist/mocks.d.ts +11 -0
- package/dist/mocks.js +25 -0
- package/dist/mocks.js.map +1 -0
- package/package.json +30 -46
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @holochain-open-dev/file-storage
|
|
2
2
|
|
|
3
|
-
Frontend module for the Holochain zome `
|
|
3
|
+
Frontend module for the Holochain zome pair `hc_zome_file_storage_integrity` and `hc_zome_file_storage_coordinator`.
|
|
4
4
|
|
|
5
5
|
This package includes types, a service and a collection of Custom Elements to build Holochain applications that automatically connect and interact with the `hc_zome_file_storage` zome.
|
|
6
6
|
|
|
@@ -8,4 +8,4 @@ By using [Custom Elements](https://developers.google.com/web/fundamentals/web-co
|
|
|
8
8
|
|
|
9
9
|
Read about how to include both the zome and this frontend module in your application here:
|
|
10
10
|
|
|
11
|
-
- https://holochain-open-dev.github.io/file-storage
|
|
11
|
+
- https://holochain-open-dev.github.io/file-storage
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { FileStorageContext } from '../elements/file-storage-context';
|
|
3
|
+
import { customElement } from 'lit/decorators.js';
|
|
4
|
+
let FSC = class FSC extends FileStorageContext {
|
|
5
|
+
};
|
|
6
|
+
FSC = __decorate([
|
|
7
|
+
customElement('file-storage-context')
|
|
8
|
+
], FSC);
|
|
9
|
+
//# sourceMappingURL=file-storage-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-storage-context.js","sourceRoot":"","sources":["../../src/definitions/file-storage-context.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,IAAM,GAAG,GAAT,MAAM,GAAI,SAAQ,kBAAkB;CAAI,CAAA;AAAlC,GAAG;IADR,aAAa,CAAC,sBAAsB,CAAC;GAChC,GAAG,CAA+B","sourcesContent":["import { FileStorageContext } from '../elements/file-storage-context';\nimport { customElement } from 'lit/decorators.js';\n\n@customElement('file-storage-context')\nclass FSC extends FileStorageContext { }\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LitElement } from "lit";
|
|
2
|
+
import { FileStorageClient } from "../file-storage-client";
|
|
3
|
+
export declare class FileStorageContext extends LitElement {
|
|
4
|
+
client: FileStorageClient;
|
|
5
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
6
|
+
static styles: import("lit").CSSResult;
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { css, html, LitElement } from "lit";
|
|
3
|
+
import { provide } from "@lit-labs/context";
|
|
4
|
+
import { property } from "lit/decorators.js";
|
|
5
|
+
import { fileStorageClientContext } from "../context";
|
|
6
|
+
export class FileStorageContext extends LitElement {
|
|
7
|
+
render() {
|
|
8
|
+
return html `<slot></slot>`;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
FileStorageContext.styles = css `
|
|
12
|
+
:host {
|
|
13
|
+
display: contents;
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
__decorate([
|
|
17
|
+
provide({ context: fileStorageClientContext }),
|
|
18
|
+
property({ type: Object })
|
|
19
|
+
], FileStorageContext.prototype, "client", void 0);
|
|
20
|
+
//# sourceMappingURL=file-storage-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-storage-context.js","sourceRoot":"","sources":["../../src/elements/file-storage-context.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAGtD,MAAM,OAAO,kBAAmB,SAAQ,UAAU;IAKhD,MAAM;QACJ,OAAO,IAAI,CAAA,eAAe,CAAC;IAC7B,CAAC;;AAEM,yBAAM,GAAG,GAAG,CAAA;;;;GAIlB,CAAC;AAVF;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,wBAAwB,EAAE,CAAC;IAC9C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kDACA","sourcesContent":["import { css, html, LitElement } from \"lit\";\nimport { provide } from \"@lit-labs/context\";\nimport { property } from \"lit/decorators.js\";\n\nimport { fileStorageClientContext } from \"../context\";\nimport { FileStorageClient } from \"../file-storage-client\";\n\nexport class FileStorageContext extends LitElement {\n @provide({ context: fileStorageClientContext })\n @property({ type: Object })\n client!: FileStorageClient;\n\n render() {\n return html`<slot></slot>`;\n }\n\n static styles = css`\n :host {\n display: contents;\n }\n `;\n}\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { LitElement } from
|
|
2
|
-
import {
|
|
3
|
-
import { EntryHash } from
|
|
4
|
-
import { Task } from
|
|
5
|
-
import { SlSkeleton } from
|
|
1
|
+
import { LitElement } from "lit";
|
|
2
|
+
import { DisplayError } from "@holochain-open-dev/elements";
|
|
3
|
+
import { EntryHash } from "@holochain/client";
|
|
4
|
+
import { Task } from "@lit-labs/task";
|
|
5
|
+
import { SlSkeleton } from "@scoped-elements/shoelace";
|
|
6
|
+
import { FileStorageClient } from "../file-storage-client";
|
|
6
7
|
declare const ShowImage_base: typeof LitElement & import("@open-wc/dedupe-mixin").Constructor<import("@open-wc/scoped-elements/types/src/types").ScopedElementsHost>;
|
|
7
8
|
/**
|
|
8
9
|
* @fires file-uploaded - Fired after having uploaded the file
|
|
@@ -10,15 +11,27 @@ declare const ShowImage_base: typeof LitElement & import("@open-wc/dedupe-mixin"
|
|
|
10
11
|
*/
|
|
11
12
|
export declare class ShowImage extends ShowImage_base {
|
|
12
13
|
/** Public attributes */
|
|
14
|
+
/**
|
|
15
|
+
* REQUIRED. The hash of the image to be rendered
|
|
16
|
+
*/
|
|
13
17
|
imageHash: EntryHash;
|
|
14
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
15
21
|
_client: FileStorageClient;
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
16
25
|
_renderImage: Task<Uint8Array[], [File, Uint8Array]>;
|
|
17
26
|
renderImage(file: File, data: Uint8Array): import("lit-html").TemplateResult<1>;
|
|
18
27
|
render(): unknown;
|
|
19
28
|
static get styles(): import("lit").CSSResult[];
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
20
32
|
static get scopedElements(): {
|
|
21
|
-
|
|
33
|
+
"sl-skeleton": typeof SlSkeleton;
|
|
34
|
+
"display-error": typeof DisplayError;
|
|
22
35
|
};
|
|
23
36
|
}
|
|
24
37
|
export {};
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import { css, html, LitElement } from
|
|
3
|
-
import { property } from
|
|
4
|
-
import { hashProperty } from
|
|
5
|
-
import { ScopedElementsMixin } from
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { fromUint8Array } from 'js-base64';
|
|
2
|
+
import { css, html, LitElement } from "lit";
|
|
3
|
+
import { property } from "lit/decorators.js";
|
|
4
|
+
import { DisplayError, hashProperty, sharedStyles, } from "@holochain-open-dev/elements";
|
|
5
|
+
import { ScopedElementsMixin } from "@open-wc/scoped-elements";
|
|
6
|
+
import { consume } from "@lit-labs/context";
|
|
7
|
+
import { Task } from "@lit-labs/task";
|
|
8
|
+
import { SlSkeleton } from "@scoped-elements/shoelace";
|
|
9
|
+
import { fromUint8Array } from "js-base64";
|
|
10
|
+
import { fileStorageClientContext } from "../context";
|
|
12
11
|
/**
|
|
13
12
|
* @fires file-uploaded - Fired after having uploaded the file
|
|
14
13
|
* @csspart dropzone - Style the dropzone itself
|
|
@@ -17,6 +16,9 @@ export class ShowImage extends ScopedElementsMixin(LitElement) {
|
|
|
17
16
|
constructor() {
|
|
18
17
|
/** Public attributes */
|
|
19
18
|
super(...arguments);
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
20
22
|
this._renderImage = new Task(this, async ([fileHash]) => {
|
|
21
23
|
const file = await this._client.downloadFile(fileHash);
|
|
22
24
|
const data = await file.arrayBuffer();
|
|
@@ -29,7 +31,8 @@ export class ShowImage extends ScopedElementsMixin(LitElement) {
|
|
|
29
31
|
render() {
|
|
30
32
|
return this._renderImage.render({
|
|
31
33
|
complete: ([f, d]) => this.renderImage(f, d),
|
|
32
|
-
pending: () => html `<sl-skeleton effect="pulse" style="flex: 1"></sl-skeleton
|
|
34
|
+
pending: () => html `<sl-skeleton effect="pulse" style="flex: 1"></sl-skeleton>`,
|
|
35
|
+
error: (e) => html `<display-error .error=${e.data.data}></display-error>`,
|
|
33
36
|
});
|
|
34
37
|
}
|
|
35
38
|
static get styles() {
|
|
@@ -43,14 +46,17 @@ export class ShowImage extends ScopedElementsMixin(LitElement) {
|
|
|
43
46
|
`,
|
|
44
47
|
];
|
|
45
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
46
52
|
static get scopedElements() {
|
|
47
|
-
return {
|
|
53
|
+
return { "sl-skeleton": SlSkeleton, "display-error": DisplayError };
|
|
48
54
|
}
|
|
49
55
|
}
|
|
50
56
|
__decorate([
|
|
51
|
-
property(hashProperty(
|
|
57
|
+
property(hashProperty("image-hash"))
|
|
52
58
|
], ShowImage.prototype, "imageHash", void 0);
|
|
53
59
|
__decorate([
|
|
54
|
-
|
|
60
|
+
consume({ context: fileStorageClientContext })
|
|
55
61
|
], ShowImage.prototype, "_client", void 0);
|
|
56
62
|
//# sourceMappingURL=show-image.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"show-image.js","sourceRoot":"","sources":["../../src/elements/show-image.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,
|
|
1
|
+
{"version":3,"file":"show-image.js","sourceRoot":"","sources":["../../src/elements/show-image.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,YAAY,GACb,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAm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AC;IACL,CAAC;IAED,MAAM,KAAK,MAAM;QACf,OAAO;YACL,YAAY;YACZ,GAAG,CAAA;;;;;OAKF;SACF,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,KAAK,cAAc;QACvB,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAAE,YAAY,EAAE,CAAC;IACtE,CAAC;CACF;AAxDuC;IAArC,QAAQ,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;4CAAuB;AAM5D;IADC,OAAO,CAAC,EAAE,OAAO,EAAE,wBAAwB,EAAE,CAAC;0CACnB","sourcesContent":["import { css, html, LitElement } from \"lit\";\nimport { property } from \"lit/decorators.js\";\nimport {\n DisplayError,\n hashProperty,\n sharedStyles,\n} from \"@holochain-open-dev/elements\";\nimport { ScopedElementsMixin } from \"@open-wc/scoped-elements\";\nimport { consume } from \"@lit-labs/context\";\n\nimport { EntryHash } from \"@holochain/client\";\nimport { Task } from \"@lit-labs/task\";\nimport { SlSkeleton } from \"@scoped-elements/shoelace\";\nimport { fromUint8Array } from \"js-base64\";\n\nimport { FileStorageClient } from \"../file-storage-client\";\nimport { fileStorageClientContext } from \"../context\";\n\n/**\n * @fires file-uploaded - Fired after having uploaded the file\n * @csspart dropzone - Style the dropzone itself\n */\nexport class ShowImage extends ScopedElementsMixin(LitElement) {\n /** Public attributes */\n\n /**\n * REQUIRED. The hash of the image to be rendered\n */\n @property(hashProperty(\"image-hash\")) imageHash!: EntryHash;\n\n /**\n * @internal\n */\n @consume({ context: fileStorageClientContext })\n _client!: FileStorageClient;\n\n /**\n * @internal\n */\n _renderImage = new Task(\n this,\n async ([fileHash]) => {\n const file = await this._client.downloadFile(fileHash);\n const data = await file.arrayBuffer();\n\n return [file, new Uint8Array(data)] as [File, Uint8Array];\n },\n () => [this.imageHash]\n );\n\n renderImage(file: File, data: Uint8Array) {\n return html`<img src=\"data:${file.type};base64,${fromUint8Array(\n data\n )}\" style=\"flex: 1\"></img>`;\n }\n\n render() {\n return this._renderImage.render({\n complete: ([f, d]) => this.renderImage(f, d),\n pending: () =>\n html`<sl-skeleton effect=\"pulse\" style=\"flex: 1\"></sl-skeleton>`,\n error: (e: any) =>\n html`<display-error .error=${e.data.data}></display-error>`,\n });\n }\n\n static get styles() {\n return [\n sharedStyles,\n css`\n :host {\n display: flex;\n flex: 1;\n }\n `,\n ];\n }\n\n /**\n * @internal\n */\n static get scopedElements() {\n return { \"sl-skeleton\": SlSkeleton, \"display-error\": DisplayError };\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LitElement } from
|
|
2
|
-
import { FileStorageClient } from
|
|
1
|
+
import { LitElement } from "lit";
|
|
2
|
+
import { FileStorageClient } from "../file-storage-client";
|
|
3
3
|
declare const UploadFiles_base: typeof LitElement & import("@open-wc/dedupe-mixin").Constructor<import("@open-wc/scoped-elements/types/src/types").ScopedElementsHost>;
|
|
4
4
|
/**
|
|
5
5
|
* @fires file-uploaded - Fired after having uploaded the file
|
|
@@ -7,9 +7,18 @@ declare const UploadFiles_base: typeof LitElement & import("@open-wc/dedupe-mixi
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class UploadFiles extends UploadFiles_base {
|
|
9
9
|
/** Public attributes */
|
|
10
|
+
/**
|
|
11
|
+
* Whether this element should allow only file to be uploaded
|
|
12
|
+
*/
|
|
10
13
|
oneFile: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* The type of files accepted by this element
|
|
16
|
+
* Learn how to use this here: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept
|
|
17
|
+
*/
|
|
11
18
|
acceptedFiles: string | undefined;
|
|
12
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
13
22
|
_client: FileStorageClient;
|
|
14
23
|
/** Private properties */
|
|
15
24
|
firstUpdated(): void;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import { css, html, LitElement } from
|
|
3
|
-
import { property } from
|
|
4
|
-
import { ScopedElementsMixin } from
|
|
5
|
-
import { DropzoneElement } from
|
|
6
|
-
import {
|
|
7
|
-
import { sharedStyles } from
|
|
8
|
-
import { HolochainDropzone } from
|
|
9
|
-
import { fileStorageClientContext } from
|
|
2
|
+
import { css, html, LitElement } from "lit";
|
|
3
|
+
import { property } from "lit/decorators.js";
|
|
4
|
+
import { ScopedElementsMixin } from "@open-wc/scoped-elements";
|
|
5
|
+
import { DropzoneElement } from "@scoped-elements/dropzone";
|
|
6
|
+
import { consume } from "@lit-labs/context";
|
|
7
|
+
import { sharedStyles } from "@holochain-open-dev/elements";
|
|
8
|
+
import { HolochainDropzone } from "../holochain-dropzone";
|
|
9
|
+
import { fileStorageClientContext } from "../context";
|
|
10
10
|
/**
|
|
11
11
|
* @fires file-uploaded - Fired after having uploaded the file
|
|
12
12
|
* @csspart dropzone - Style the dropzone itself
|
|
@@ -15,13 +15,20 @@ export class UploadFiles extends ScopedElementsMixin(LitElement) {
|
|
|
15
15
|
constructor() {
|
|
16
16
|
/** Public attributes */
|
|
17
17
|
super(...arguments);
|
|
18
|
+
/**
|
|
19
|
+
* Whether this element should allow only file to be uploaded
|
|
20
|
+
*/
|
|
18
21
|
this.oneFile = false;
|
|
22
|
+
/**
|
|
23
|
+
* The type of files accepted by this element
|
|
24
|
+
* Learn how to use this here: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept
|
|
25
|
+
*/
|
|
19
26
|
this.acceptedFiles = undefined;
|
|
20
27
|
}
|
|
21
28
|
/** Private properties */
|
|
22
29
|
firstUpdated() {
|
|
23
30
|
const client = this._client;
|
|
24
|
-
this.defineScopedElement(
|
|
31
|
+
this.defineScopedElement("drop-zone", class extends DropzoneElement {
|
|
25
32
|
buildDropzone(dropzoneElement, options) {
|
|
26
33
|
return new HolochainDropzone(dropzoneElement, client, options);
|
|
27
34
|
}
|
|
@@ -48,12 +55,12 @@ export class UploadFiles extends ScopedElementsMixin(LitElement) {
|
|
|
48
55
|
}
|
|
49
56
|
}
|
|
50
57
|
__decorate([
|
|
51
|
-
property({ type: Boolean, attribute:
|
|
58
|
+
property({ type: Boolean, attribute: "one-file" })
|
|
52
59
|
], UploadFiles.prototype, "oneFile", void 0);
|
|
53
60
|
__decorate([
|
|
54
|
-
property({ type: String, attribute:
|
|
61
|
+
property({ type: String, attribute: "accepted-files" })
|
|
55
62
|
], UploadFiles.prototype, "acceptedFiles", void 0);
|
|
56
63
|
__decorate([
|
|
57
|
-
|
|
64
|
+
consume({ context: fileStorageClientContext })
|
|
58
65
|
], UploadFiles.prototype, "_client", void 0);
|
|
59
66
|
//# sourceMappingURL=upload-files.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-files.js","sourceRoot":"","sources":["../../src/elements/upload-files.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"upload-files.js","sourceRoot":"","sources":["../../src/elements/upload-files.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAG5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAEtD;;;GAGG;AACH,MAAM,OAAO,WAAY,SAAQ,mBAAmB,CAAC,UAAU,CAAC;IAAhE;QACE,wBAAwB;;QAExB;;WAEG;QACiD,YAAO,GAAG,KAAK,CAAC;QAEpE;;;WAGG;QACsD,kBAAa,GAEtD,SAAS,CAAC;IA4C5B,CAAC;IApCC,yBAAyB;IAEzB,YAAY;QACV,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC;QAE5B,IAAI,CAAC,mBAAmB,CACtB,WAAW,EACX,KAAM,SAAQ,eAAe;YAC3B,aAAa,CAAC,eAA4B,EAAE,OAAwB;gBAClE,OAAO,IAAI,iBAAiB,CAAC,eAAe,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YACjE,CAAC;SACF,CACF,CAAC;IACJ,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAA;;mBAEI,IAAI,CAAC,OAAO;yBACN,IAAI,CAAC,aAAa;yBAClB,CAAC,CAAc,EAAE,EAAE,CAClC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;;KAEzC,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,MAAM;QACf,OAAO;YACL,YAAY;YACZ,GAAG,CAAA;;;;OAIF;SACF,CAAC;IACJ,CAAC;CACF;AApDqD;IAAnD,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;4CAAiB;AAMX;IAAxD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC;kDAE9B;AAM1B;IADC,OAAO,CAAC,EAAE,OAAO,EAAE,wBAAwB,EAAE,CAAC;4CACnB","sourcesContent":["import { css, html, LitElement } from \"lit\";\nimport { property } from \"lit/decorators.js\";\n\nimport { ScopedElementsMixin } from \"@open-wc/scoped-elements\";\nimport { DropzoneElement } from \"@scoped-elements/dropzone\";\nimport { consume } from \"@lit-labs/context\";\nimport { DropzoneOptions } from \"dropzone\";\nimport { sharedStyles } from \"@holochain-open-dev/elements\";\n\nimport { FileStorageClient } from \"../file-storage-client\";\nimport { HolochainDropzone } from \"../holochain-dropzone\";\nimport { fileStorageClientContext } from \"../context\";\n\n/**\n * @fires file-uploaded - Fired after having uploaded the file\n * @csspart dropzone - Style the dropzone itself\n */\nexport class UploadFiles extends ScopedElementsMixin(LitElement) {\n /** Public attributes */\n\n /**\n * Whether this element should allow only file to be uploaded\n */\n @property({ type: Boolean, attribute: \"one-file\" }) oneFile = false;\n\n /**\n * The type of files accepted by this element\n * Learn how to use this here: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept\n */\n @property({ type: String, attribute: \"accepted-files\" }) acceptedFiles:\n | string\n | undefined = undefined;\n\n /**\n * @internal\n */\n @consume({ context: fileStorageClientContext })\n _client!: FileStorageClient;\n\n /** Private properties */\n\n firstUpdated() {\n const client = this._client;\n\n this.defineScopedElement(\n \"drop-zone\",\n class extends DropzoneElement {\n buildDropzone(dropzoneElement: HTMLElement, options: DropzoneOptions) {\n return new HolochainDropzone(dropzoneElement, client, options);\n }\n }\n );\n }\n\n render() {\n return html`\n <drop-zone\n .oneFile=${this.oneFile}\n .acceptedFiles=${this.acceptedFiles}\n @file-uploaded=${(e: CustomEvent) =>\n (e.detail.hash = e.detail.file.hash)}\n ></drop-zone>\n `;\n }\n\n static get styles() {\n return [\n sharedStyles,\n css`\n :host {\n display: contents;\n }\n `,\n ];\n }\n}\n"]}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { EntryHash } from
|
|
3
|
-
import { FileMetadata } from
|
|
1
|
+
import type { AppAgentClient } from "@holochain/client";
|
|
2
|
+
import { EntryHash } from "@holochain/client";
|
|
3
|
+
import { FileMetadata } from "./types";
|
|
4
4
|
export declare class FileStorageClient {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
client: AppAgentClient;
|
|
6
|
+
roleName: string;
|
|
7
|
+
zomeName: string;
|
|
7
8
|
/**
|
|
8
|
-
* @param
|
|
9
|
-
* @param
|
|
9
|
+
* @param client connection to the holochain backend
|
|
10
|
+
* @param roleName
|
|
10
11
|
* @param zomeName the zome name of the file_storage zome in the given cell
|
|
11
12
|
*/
|
|
12
|
-
constructor(
|
|
13
|
+
constructor(client: AppAgentClient, roleName: string, zomeName?: string);
|
|
13
14
|
/**
|
|
14
15
|
* Upload a file to the file_storage zome, splitting it into chunks
|
|
15
16
|
*
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export class FileStorageClient {
|
|
2
2
|
/**
|
|
3
|
-
* @param
|
|
4
|
-
* @param
|
|
3
|
+
* @param client connection to the holochain backend
|
|
4
|
+
* @param roleName
|
|
5
5
|
* @param zomeName the zome name of the file_storage zome in the given cell
|
|
6
6
|
*/
|
|
7
|
-
constructor(
|
|
8
|
-
this.
|
|
7
|
+
constructor(client, roleName, zomeName = "file_storage") {
|
|
8
|
+
this.client = client;
|
|
9
|
+
this.roleName = roleName;
|
|
9
10
|
this.zomeName = zomeName;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
@@ -33,7 +34,7 @@ export class FileStorageClient {
|
|
|
33
34
|
last_modified: file.lastModified,
|
|
34
35
|
chunks_hashes: chunksHashes,
|
|
35
36
|
};
|
|
36
|
-
const hash = await this._callZome(
|
|
37
|
+
const hash = await this._callZome("create_file_metadata", fileToCreate);
|
|
37
38
|
return hash;
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
@@ -42,7 +43,7 @@ export class FileStorageClient {
|
|
|
42
43
|
*/
|
|
43
44
|
async downloadFile(fileHash) {
|
|
44
45
|
const metadata = await this.getFileMetadata(fileHash);
|
|
45
|
-
const fetchChunksPromises = metadata.chunks_hashes.map(hash => this.fetchChunk(hash));
|
|
46
|
+
const fetchChunksPromises = metadata.chunks_hashes.map((hash) => this.fetchChunk(hash));
|
|
46
47
|
const chunks = await Promise.all(fetchChunksPromises);
|
|
47
48
|
const file = new File(chunks, metadata.name, {
|
|
48
49
|
lastModified: metadata.last_modifed,
|
|
@@ -56,7 +57,7 @@ export class FileStorageClient {
|
|
|
56
57
|
* @param fileHash the hash of the file
|
|
57
58
|
*/
|
|
58
59
|
async getFileMetadata(fileHash) {
|
|
59
|
-
return await this._callZome(
|
|
60
|
+
return await this._callZome("get_file_metadata", fileHash);
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
62
63
|
* Fetch the chunk identified with the given hash
|
|
@@ -64,7 +65,7 @@ export class FileStorageClient {
|
|
|
64
65
|
* @param fileChunkHash
|
|
65
66
|
*/
|
|
66
67
|
async fetchChunk(fileChunkHash) {
|
|
67
|
-
const bytes = await this._callZome(
|
|
68
|
+
const bytes = await this._callZome("get_file_chunk", fileChunkHash);
|
|
68
69
|
return new Blob([new Uint8Array(bytes)]);
|
|
69
70
|
}
|
|
70
71
|
/** Private helpers */
|
|
@@ -80,10 +81,16 @@ export class FileStorageClient {
|
|
|
80
81
|
}
|
|
81
82
|
async _createChunk(chunk) {
|
|
82
83
|
const bytes = await chunk.arrayBuffer();
|
|
83
|
-
return this._callZome(
|
|
84
|
+
return this._callZome("create_file_chunk", new Uint8Array(bytes));
|
|
84
85
|
}
|
|
85
|
-
_callZome(
|
|
86
|
-
|
|
86
|
+
_callZome(fn_name, payload) {
|
|
87
|
+
const req = {
|
|
88
|
+
role_name: this.roleName,
|
|
89
|
+
zome_name: this.zomeName,
|
|
90
|
+
fn_name,
|
|
91
|
+
payload,
|
|
92
|
+
};
|
|
93
|
+
return this.client.callZome(req);
|
|
87
94
|
}
|
|
88
95
|
}
|
|
89
96
|
//# sourceMappingURL=file-storage-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-storage-client.js","sourceRoot":"","sources":["../src/file-storage-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file-storage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C,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;YACrD,MAAM,IAAI,SAAS,CAAC;YACpB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACpB;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,KAAK,CAAC,YAAY,CAAC,KAAW;QACpC,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,WAAW,EAAE,CAAC;QAExC,OAAO,IAAI,CAAC,SAAS,CAAC,mBAAmB,EAAE,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IACpE,CAAC;IAEO,SAAS,CAAC,OAAe,EAAE,OAAY;QAC7C,MAAM,GAAG,GAA4B;YACnC,SAAS,EAAE,IAAI,CAAC,QAAQ;YACxB,SAAS,EAAE,IAAI,CAAC,QAAQ;YACxB,OAAO;YACP,OAAO;SACR,CAAC;QACF,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;CACF","sourcesContent":["import type {\n AppAgentCallZomeRequest,\n AppAgentClient,\n} from \"@holochain/client\";\nimport { EntryHash } from \"@holochain/client\";\nimport { FileMetadata } from \"./types\";\n\nexport class FileStorageClient {\n /**\n * @param client connection to the holochain backend\n * @param roleName\n * @param zomeName the zome name of the file_storage zome in the given cell\n */\n constructor(\n public client: AppAgentClient,\n public roleName: string,\n public zomeName: string = \"file_storage\"\n ) {}\n\n /**\n * Upload a file to the file_storage zome, splitting it into chunks\n *\n * @param file file to split and upload\n * @param chunkSize chunk size to split the file, default 256 KB\n */\n async uploadFile(\n file: File,\n onProgress:\n | undefined\n | ((percentatgeProgress: number, bytesSent: number) => void) = undefined,\n chunkSize: number = 256 * 1024\n ): Promise<EntryHash> {\n const blobs = this._splitFile(file, chunkSize);\n const numberOfChunks = blobs.length;\n const bytesPerChunk = blobs[0].size;\n\n const chunksHashes: Array<EntryHash> = [];\n for (let i = 0; i < blobs.length; i++) {\n const chunkHash = await this._createChunk(blobs[i]);\n chunksHashes.push(chunkHash);\n if (onProgress) {\n onProgress(((i + 1) * 1.0) / numberOfChunks, bytesPerChunk * (i + 1));\n }\n }\n\n const fileToCreate = {\n name: file.name,\n size: file.size,\n file_type: file.type,\n last_modified: file.lastModified,\n chunks_hashes: chunksHashes,\n };\n const hash = await this._callZome(\"create_file_metadata\", fileToCreate);\n\n return hash;\n }\n\n /**\n * Downloads the whole file with the given hash\n * @param fileHash\n */\n async downloadFile(fileHash: EntryHash): Promise<File> {\n const metadata = await this.getFileMetadata(fileHash);\n\n const fetchChunksPromises = metadata.chunks_hashes.map((hash) =>\n this.fetchChunk(hash)\n );\n\n const chunks = await Promise.all(fetchChunksPromises);\n\n const file = new File(chunks, metadata.name, {\n lastModified: metadata.last_modifed,\n type: metadata.file_type,\n });\n\n return file;\n }\n\n /**\n * Gets only the metadata of the file with the given hash\n * This is specially useful if you want to fetch the chunks one by one\n * @param fileHash the hash of the file\n */\n async getFileMetadata(fileHash: EntryHash): Promise<FileMetadata> {\n return await this._callZome(\"get_file_metadata\", fileHash);\n }\n\n /**\n * Fetch the chunk identified with the given hash\n * This is useful if used with the chunk hashes received with `getFileMetadata`\n * @param fileChunkHash\n */\n async fetchChunk(fileChunkHash: EntryHash): Promise<Blob> {\n const bytes = await this._callZome(\"get_file_chunk\", fileChunkHash);\n\n return new Blob([new Uint8Array(bytes)]);\n }\n\n /** Private helpers */\n\n private _splitFile(file: File, chunkSize: number): Blob[] {\n let offset = 0;\n const chunks: Blob[] = [];\n\n while (file.size > offset) {\n const chunk = file.slice(offset, offset + chunkSize);\n offset += chunkSize;\n chunks.push(chunk);\n }\n\n return chunks;\n }\n\n private async _createChunk(chunk: Blob): Promise<EntryHash> {\n const bytes = await chunk.arrayBuffer();\n\n return this._callZome(\"create_file_chunk\", new Uint8Array(bytes));\n }\n\n private _callZome(fn_name: string, payload: any) {\n const req: AppAgentCallZomeRequest = {\n role_name: this.roleName,\n zome_name: this.zomeName,\n fn_name,\n payload,\n };\n return this.client.callZome(req);\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Dropzone, { DropzoneOptions } from
|
|
2
|
-
import { FileStorageClient } from
|
|
1
|
+
import Dropzone, { DropzoneOptions } from "dropzone";
|
|
2
|
+
import { FileStorageClient } from "./file-storage-client";
|
|
3
3
|
export declare class HolochainDropzone extends Dropzone {
|
|
4
4
|
fileStorageClient: FileStorageClient;
|
|
5
5
|
constructor(el: HTMLElement, fileStorageClient: FileStorageClient, options: DropzoneOptions);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import Dropzone from
|
|
1
|
+
import Dropzone from "dropzone";
|
|
2
2
|
export class HolochainDropzone extends Dropzone {
|
|
3
3
|
constructor(el, fileStorageClient, options) {
|
|
4
|
-
options.url =
|
|
4
|
+
options.url = "https://holochain.org/"; // just to bypass the check.
|
|
5
5
|
super(el, options);
|
|
6
6
|
this.fileStorageClient = fileStorageClient;
|
|
7
7
|
}
|
|
@@ -11,18 +11,17 @@ export class HolochainDropzone extends Dropzone {
|
|
|
11
11
|
async _uploadFilesToHolochain(dropzoneFiles) {
|
|
12
12
|
for (const file of dropzoneFiles) {
|
|
13
13
|
try {
|
|
14
|
-
this.emit(
|
|
14
|
+
this.emit("sending", file, undefined, undefined);
|
|
15
15
|
const hash = await this.fileStorageClient.uploadFile(file, (percentatge, bytesSent) => {
|
|
16
|
-
this.emit(
|
|
16
|
+
this.emit("uploadprogress", file, percentatge * 100, bytesSent);
|
|
17
17
|
});
|
|
18
|
-
this.emit(
|
|
19
|
-
// @ts-ignore
|
|
18
|
+
this.emit("success", file, undefined);
|
|
20
19
|
file.hash = hash;
|
|
21
|
-
this.emit(
|
|
20
|
+
this.emit("complete", file);
|
|
22
21
|
}
|
|
23
22
|
catch (e) {
|
|
24
23
|
console.error(e);
|
|
25
|
-
this.emit(
|
|
24
|
+
this.emit("error", file, e.data.data);
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"holochain-dropzone.js","sourceRoot":"","sources":["../src/holochain-dropzone.ts"],"names":[],"mappings":"AAAA,OAAO,QAA6B,MAAM,UAAU,CAAC;AAGrD,MAAM,OAAO,iBAAkB,SAAQ,QAAQ;IAE7C,YACE,EAAe,EACf,iBAAoC,EACpC,OAAwB;QAExB,OAAO,CAAC,GAAG,GAAG,wBAAwB,CAAC,CAAC,4BAA4B;QACpE,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QACnB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IAED,WAAW,CAAC,KAA8B;QACxC,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,uBAAuB,CAC3B,aAAsC;QAEtC,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE;YAChC,IAAI;gBACF,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;gBACjD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAClD,IAAI,EACJ,CAAC,WAAW,EAAE,SAAS,EAAE,EAAE;oBACzB,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,GAAG,EAAE,SAAS,CAAC,CAAC;gBAClE,CAAC,CACF,CAAC;gBACF,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"holochain-dropzone.js","sourceRoot":"","sources":["../src/holochain-dropzone.ts"],"names":[],"mappings":"AAAA,OAAO,QAA6B,MAAM,UAAU,CAAC;AAGrD,MAAM,OAAO,iBAAkB,SAAQ,QAAQ;IAE7C,YACE,EAAe,EACf,iBAAoC,EACpC,OAAwB;QAExB,OAAO,CAAC,GAAG,GAAG,wBAAwB,CAAC,CAAC,4BAA4B;QACpE,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QACnB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IAED,WAAW,CAAC,KAA8B;QACxC,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,uBAAuB,CAC3B,aAAsC;QAEtC,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE;YAChC,IAAI;gBACF,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;gBACjD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAClD,IAAI,EACJ,CAAC,WAAW,EAAE,SAAS,EAAE,EAAE;oBACzB,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,GAAG,EAAE,SAAS,CAAC,CAAC;gBAClE,CAAC,CACF,CAAC;gBACF,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;gBACrC,IAAY,CAAC,IAAI,GAAG,IAAI,CAAC;gBAC1B,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;aAC7B;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACjB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAG,CAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAChD;SACF;IACH,CAAC;CACF","sourcesContent":["import Dropzone, { DropzoneOptions } from \"dropzone\";\nimport { FileStorageClient } from \"./file-storage-client\";\n\nexport class HolochainDropzone extends Dropzone {\n fileStorageClient: FileStorageClient;\n constructor(\n el: HTMLElement,\n fileStorageClient: FileStorageClient,\n options: DropzoneOptions\n ) {\n options.url = \"https://holochain.org/\"; // just to bypass the check.\n super(el, options);\n this.fileStorageClient = fileStorageClient;\n }\n\n uploadFiles(files: Dropzone.DropzoneFile[]) {\n this._uploadFilesToHolochain(files);\n }\n\n async _uploadFilesToHolochain(\n dropzoneFiles: Dropzone.DropzoneFile[]\n ): Promise<void> {\n for (const file of dropzoneFiles) {\n try {\n this.emit(\"sending\", file, undefined, undefined);\n const hash = await this.fileStorageClient.uploadFile(\n file,\n (percentatge, bytesSent) => {\n this.emit(\"uploadprogress\", file, percentatge * 100, bytesSent);\n }\n );\n this.emit(\"success\", file, undefined);\n (file as any).hash = hash;\n this.emit(\"complete\", file);\n } catch (e) {\n console.error(e);\n this.emit(\"error\", file, (e as any).data.data);\n }\n }\n }\n}\n"]}
|
package/dist/mocks.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EntryHashMap, ZomeMock } from "@holochain-open-dev/utils";
|
|
2
|
+
import { HoloHash } from "@holochain/client";
|
|
3
|
+
import { FileMetadata } from "./types";
|
|
4
|
+
export declare class FileStorageZomeMock extends ZomeMock {
|
|
5
|
+
metadata: EntryHashMap<unknown>;
|
|
6
|
+
chunks: EntryHashMap<unknown>;
|
|
7
|
+
create_file_metadata(fileMetadata: FileMetadata): Uint8Array;
|
|
8
|
+
get_file_metadata(fileHash: HoloHash): unknown;
|
|
9
|
+
create_file_chunk(fileChunk: Uint8Array): Uint8Array;
|
|
10
|
+
get_file_chunk(fileChunkHash: HoloHash): unknown;
|
|
11
|
+
}
|
package/dist/mocks.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { EntryHashMap, ZomeMock, hash, HashType, } from "@holochain-open-dev/utils";
|
|
2
|
+
export class FileStorageZomeMock extends ZomeMock {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.metadata = new EntryHashMap();
|
|
6
|
+
this.chunks = new EntryHashMap();
|
|
7
|
+
}
|
|
8
|
+
create_file_metadata(fileMetadata) {
|
|
9
|
+
const newId = hash(fileMetadata, HashType.ENTRY);
|
|
10
|
+
this.metadata.set(newId, fileMetadata);
|
|
11
|
+
return newId;
|
|
12
|
+
}
|
|
13
|
+
get_file_metadata(fileHash) {
|
|
14
|
+
return this.metadata.get(fileHash);
|
|
15
|
+
}
|
|
16
|
+
create_file_chunk(fileChunk) {
|
|
17
|
+
const newId = hash(fileChunk, HashType.ENTRY);
|
|
18
|
+
this.chunks.set(newId, fileChunk);
|
|
19
|
+
return newId;
|
|
20
|
+
}
|
|
21
|
+
get_file_chunk(fileChunkHash) {
|
|
22
|
+
return this.chunks.get(fileChunkHash);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=mocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mocks.js","sourceRoot":"","sources":["../src/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,IAAI,EACJ,QAAQ,GACT,MAAM,2BAA2B,CAAC;AAInC,MAAM,OAAO,mBAAoB,SAAQ,QAAQ;IAAjD;;QACE,aAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;QAC9B,WAAM,GAAG,IAAI,YAAY,EAAE,CAAC;IAyB9B,CAAC;IAvBC,oBAAoB,CAAC,YAA0B;QAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;QAEjD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;QAEvC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,iBAAiB,CAAC,QAAkB;QAClC,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC;IAED,iBAAiB,CAAC,SAAqB;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;QAE9C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QAElC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,cAAc,CAAC,aAAuB;QACpC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["import {\n EntryHashMap,\n ZomeMock,\n hash,\n HashType,\n} from \"@holochain-open-dev/utils\";\nimport { HoloHash } from \"@holochain/client\";\nimport { FileMetadata } from \"./types\";\n\nexport class FileStorageZomeMock extends ZomeMock {\n metadata = new EntryHashMap();\n chunks = new EntryHashMap();\n\n create_file_metadata(fileMetadata: FileMetadata) {\n const newId = hash(fileMetadata, HashType.ENTRY);\n\n this.metadata.set(newId, fileMetadata);\n\n return newId;\n }\n\n get_file_metadata(fileHash: HoloHash) {\n return this.metadata.get(fileHash);\n }\n\n create_file_chunk(fileChunk: Uint8Array) {\n const newId = hash(fileChunk, HashType.ENTRY);\n\n this.chunks.set(newId, fileChunk);\n\n return newId;\n }\n\n get_file_chunk(fileChunkHash: HoloHash) {\n return this.chunks.get(fileChunkHash);\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,73 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holochain-open-dev/file-storage",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "File storage utilities to store files in holochain DHT",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "File storage utilities to store and retrieve files in a holochain DHT",
|
|
5
5
|
"author": "guillem.cordoba@gmail.com",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"module": "dist/index.js",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": "./dist/index.js",
|
|
11
|
+
"./file-storage-context": "./dist/definitions/file-storage-context.js",
|
|
11
12
|
"./upload-files": "./dist/definitions/upload-files.js",
|
|
13
|
+
"./mocks": "./dist/mocks.js",
|
|
12
14
|
"./show-image": "./dist/definitions/show-image.js"
|
|
13
15
|
},
|
|
14
|
-
"files": [
|
|
15
|
-
"dist"
|
|
16
|
-
],
|
|
16
|
+
"files": ["dist"],
|
|
17
17
|
"scripts": {
|
|
18
|
-
"start": "
|
|
19
|
-
"build": "tsc",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"format": "eslint --ext .ts,.html
|
|
18
|
+
"start": "vite --clearScreen false --port $UI_PORT",
|
|
19
|
+
"build": "npm run lint && tsc",
|
|
20
|
+
"lint": "eslint --ext .ts,.html src --ignore-path .gitignore",
|
|
21
|
+
"analyze": "cem analyze --litelement --exclude dist",
|
|
22
|
+
"format": "eslint --ext .ts,.html src --fix --ignore-path .gitignore"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@holochain/
|
|
26
|
-
"@holochain-open-dev/
|
|
27
|
-
"@
|
|
25
|
+
"@holochain-open-dev/elements": "^0.2.3",
|
|
26
|
+
"@holochain-open-dev/utils": "^0.10.2",
|
|
27
|
+
"@holochain/client": "^0.12.0",
|
|
28
|
+
"@lit-labs/context": "^0.2.0",
|
|
28
29
|
"@lit-labs/task": "^2.0.0",
|
|
29
30
|
"@open-wc/scoped-elements": "^2.1.0",
|
|
30
31
|
"@scoped-elements/dropzone": "^0.0.3",
|
|
31
32
|
"@scoped-elements/material-web": "^0.0.19",
|
|
32
|
-
"lit": "^2.
|
|
33
|
+
"lit": "^2.6.0"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@open-wc/
|
|
37
|
-
"@open-wc/eslint-config": "^4.3.0",
|
|
38
|
-
"@rollup/plugin-babel": "^5.3.0",
|
|
39
|
-
"@rollup/plugin-commonjs": "18.0.0",
|
|
40
|
-
"@rollup/plugin-node-resolve": "^13.0.4",
|
|
41
|
-
"@rollup/plugin-replace": "^3.0.0",
|
|
42
|
-
"@trivago/prettier-plugin-sort-imports": "^3.4.0",
|
|
36
|
+
"@custom-elements-manifest/analyzer": "^0.5.7",
|
|
37
|
+
"@open-wc/eslint-config": "^2.0.0",
|
|
43
38
|
"@types/dropzone": "^5.7.4",
|
|
44
|
-
"@
|
|
45
|
-
"@
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"concurrently": "^6.2.1",
|
|
53
|
-
"deepmerge": "^4.2.2",
|
|
54
|
-
"eslint": "^7.32.0",
|
|
55
|
-
"eslint-config-prettier": "^8.3.0",
|
|
56
|
-
"lint-staged": "^10.5.4",
|
|
57
|
-
"prettier": "^2.3.2",
|
|
58
|
-
"prettier-plugin-organize-imports": "^3.2.0",
|
|
39
|
+
"@types/lodash-es": "^4.17.5",
|
|
40
|
+
"@types/node": "14.11.1",
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^5.49.0",
|
|
42
|
+
"@typescript-eslint/parser": "^5.49.0",
|
|
43
|
+
"concurrently": "^5.1.0",
|
|
44
|
+
"eslint": "^7.1.0",
|
|
45
|
+
"eslint-config-prettier": "^6.11.0",
|
|
46
|
+
"prettier": "^2.0.4",
|
|
59
47
|
"rimraf": "^3.0.2",
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"typescript": "^4.9.0"
|
|
48
|
+
"tslib": "^2.0.0",
|
|
49
|
+
"typescript": "^4.9.0",
|
|
50
|
+
"vite": "^4.0.4",
|
|
51
|
+
"vite-plugin-checker": "^0.5.3"
|
|
65
52
|
},
|
|
66
53
|
"eslintConfig": {
|
|
67
|
-
"extends": [
|
|
68
|
-
"@open-wc/eslint-config",
|
|
69
|
-
"eslint-config-prettier"
|
|
70
|
-
]
|
|
54
|
+
"extends": ["@open-wc/eslint-config", "eslint-config-prettier"]
|
|
71
55
|
},
|
|
72
56
|
"prettier": {
|
|
73
57
|
"singleQuote": true,
|