@holochain-open-dev/file-storage 0.0.1 → 0.0.3

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/context.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import { Context } from '@holochain-open-dev/context';
2
- import { FileStorageService } from './services/file-storage.service';
3
- export declare const fileStorageServiceContext: Context<FileStorageService>;
1
+ import { FileStorageClient } from './file-storage-client';
2
+ export declare const fileStorageClientContext: {
3
+ __context__: FileStorageClient;
4
+ };
package/dist/context.js CHANGED
@@ -1,3 +1,3 @@
1
- import { createContext } from '@holochain-open-dev/context';
2
- export const fileStorageServiceContext = createContext('hc_zome_file_storage/file-storage-servce');
1
+ import { createContext } from '@lit-labs/context';
2
+ export const fileStorageClientContext = createContext('hc_zome_file_storage/file-storage-client');
3
3
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAW,MAAM,6BAA6B,CAAC;AAGrE,MAAM,CAAC,MAAM,yBAAyB,GACpC,aAAa,CAAC,0CAA0C,CAAC,CAAC","sourcesContent":["import { createContext, Context } from '@holochain-open-dev/context';\nimport { FileStorageService } from './services/file-storage.service';\n\nexport const fileStorageServiceContext: Context<FileStorageService> =\n createContext('hc_zome_file_storage/file-storage-servce');\n"]}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,MAAM,CAAC,MAAM,wBAAwB,GACnC,aAAa,CAAoB,0CAA0C,CAAC,CAAC","sourcesContent":["import { createContext } from '@lit-labs/context';\nimport { FileStorageClient } from './file-storage-client';\n\nexport const fileStorageClientContext =\n createContext<FileStorageClient>('hc_zome_file_storage/file-storage-client');\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { __decorate } from "tslib";
2
+ import { ShowImage } from '../elements/show-image';
3
+ import { customElement } from 'lit/decorators.js';
4
+ let SI = class SI extends ShowImage {
5
+ };
6
+ SI = __decorate([
7
+ customElement('show-image')
8
+ ], SI);
9
+ //# sourceMappingURL=show-image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"show-image.js","sourceRoot":"","sources":["../../src/definitions/show-image.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,IAAM,EAAE,GAAR,MAAM,EAAG,SAAQ,SAAS;CAAI,CAAA;AAAxB,EAAE;IADP,aAAa,CAAC,YAAY,CAAC;GACtB,EAAE,CAAsB","sourcesContent":["import { ShowImage } from '../elements/show-image';\nimport { customElement } from 'lit/decorators.js';\n\n@customElement('show-image')\nclass SI extends ShowImage { }"]}
@@ -0,0 +1,24 @@
1
+ import { LitElement } from 'lit';
2
+ import { FileStorageClient } from '../file-storage-client';
3
+ import { EntryHash } from '@holochain/client';
4
+ import { Task } from '@lit-labs/task';
5
+ import { SlSkeleton } from '@scoped-elements/shoelace';
6
+ declare const ShowImage_base: typeof LitElement & import("@open-wc/dedupe-mixin").Constructor<import("@open-wc/scoped-elements/types/src/types").ScopedElementsHost>;
7
+ /**
8
+ * @fires file-uploaded - Fired after having uploaded the file
9
+ * @csspart dropzone - Style the dropzone itself
10
+ */
11
+ export declare class ShowImage extends ShowImage_base {
12
+ /** Public attributes */
13
+ imageHash: EntryHash;
14
+ /** Dependencies */
15
+ _client: FileStorageClient;
16
+ _renderImage: Task<Uint8Array[], [File, Uint8Array]>;
17
+ renderImage(file: File, data: Uint8Array): import("lit-html").TemplateResult<1>;
18
+ render(): unknown;
19
+ static get styles(): import("lit").CSSResult[];
20
+ static get scopedElements(): {
21
+ 'sl-skeleton': typeof SlSkeleton;
22
+ };
23
+ }
24
+ export {};
@@ -0,0 +1,56 @@
1
+ import { __decorate } from "tslib";
2
+ import { css, html, LitElement } from 'lit';
3
+ import { property } from 'lit/decorators.js';
4
+ import { hashProperty } from '@holochain-open-dev/elements';
5
+ import { ScopedElementsMixin } from '@open-wc/scoped-elements';
6
+ import { contextProvided } from '@lit-labs/context';
7
+ import { sharedStyles } from '../shared-styles';
8
+ import { fileStorageClientContext } from '../context';
9
+ import { Task } from '@lit-labs/task';
10
+ import { SlSkeleton } from '@scoped-elements/shoelace';
11
+ import { fromUint8Array } from 'js-base64';
12
+ /**
13
+ * @fires file-uploaded - Fired after having uploaded the file
14
+ * @csspart dropzone - Style the dropzone itself
15
+ */
16
+ export class ShowImage extends ScopedElementsMixin(LitElement) {
17
+ constructor() {
18
+ /** Public attributes */
19
+ super(...arguments);
20
+ this._renderImage = new Task(this, async ([fileHash]) => {
21
+ const file = await this._client.downloadFile(fileHash);
22
+ const data = await file.arrayBuffer();
23
+ return [file, new Uint8Array(data)];
24
+ }, () => [this.imageHash]);
25
+ }
26
+ renderImage(file, data) {
27
+ return html `<img src="data:${file.type};base64,${fromUint8Array(data)}" style="flex: 1"></img>`;
28
+ }
29
+ render() {
30
+ return this._renderImage.render({
31
+ complete: ([f, d]) => this.renderImage(f, d),
32
+ pending: () => html `<sl-skeleton effect="pulse" style="flex: 1"></sl-skeleton>`
33
+ });
34
+ }
35
+ static get styles() {
36
+ return [
37
+ sharedStyles,
38
+ css `
39
+ :host {
40
+ display: flex;
41
+ flex: 1;
42
+ }
43
+ `,
44
+ ];
45
+ }
46
+ static get scopedElements() {
47
+ return { 'sl-skeleton': SlSkeleton };
48
+ }
49
+ }
50
+ __decorate([
51
+ property(hashProperty('image-hash'))
52
+ ], ShowImage.prototype, "imageHash", void 0);
53
+ __decorate([
54
+ contextProvided({ context: fileStorageClientContext })
55
+ ], ShowImage.prototype, "_client", void 0);
56
+ //# sourceMappingURL=show-image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"show-image.js","sourceRoot":"","sources":["../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O,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;YAC9B,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC;YAC5C,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAA,4DAA4D;SAChF,CAAC,CAAC;IACL,CAAC;IAED,MAAM,KAAK,MAAM;QACf,OAAO;YACL,YAAY;YACZ,GAAG,CAAA;;;;;OAKF;SACF,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,cAAc;QACvB,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,CAAA;IACtC,CAAC;CACF;AAxCuC;IAArC,QAAQ,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;4CAAuB;AAK5D;IADC,eAAe,CAAC,EAAE,OAAO,EAAE,wBAAwB,EAAE,CAAC;0CAC3B","sourcesContent":["import { css, html, LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { hashProperty } from '@holochain-open-dev/elements';\nimport { ScopedElementsMixin } from '@open-wc/scoped-elements';\nimport { contextProvided } from '@lit-labs/context';\n\nimport { FileStorageClient } from '../file-storage-client';\nimport { sharedStyles } from '../shared-styles';\nimport { fileStorageClientContext } from '../context';\nimport { EntryHash } from '@holochain/client';\nimport { Task } from '@lit-labs/task';\nimport { SlSkeleton } from '@scoped-elements/shoelace'\nimport { fromUint8Array } from 'js-base64'\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 @property(hashProperty('image-hash')) imageHash!: EntryHash;\n\n /** Dependencies */\n\n @contextProvided({ context: fileStorageClientContext })\n _client!: FileStorageClient;\n\n _renderImage = new Task(this, 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 }, () => [this.imageHash]);\n\n renderImage(file: File, data: Uint8Array) {\n return html`<img src=\"data:${file.type};base64,${fromUint8Array(data)}\" style=\"flex: 1\"></img>`;\n }\n\n render() {\n return this._renderImage.render({\n complete: ([f, d]) => this.renderImage(f, d),\n pending: () => html`<sl-skeleton effect=\"pulse\" style=\"flex: 1\"></sl-skeleton>`\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 static get scopedElements() {\n return { 'sl-skeleton': SlSkeleton }\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { LitElement } from 'lit';
2
- import { FileStorageService } from '../services/file-storage.service';
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
@@ -10,7 +10,7 @@ export declare class UploadFiles extends UploadFiles_base {
10
10
  oneFile: boolean;
11
11
  acceptedFiles: string | undefined;
12
12
  /** Dependencies */
13
- _service: FileStorageService;
13
+ _client: FileStorageClient;
14
14
  /** Private properties */
15
15
  firstUpdated(): void;
16
16
  render(): import("lit-html").TemplateResult<1>;
@@ -3,10 +3,10 @@ import { css, html, LitElement } from 'lit';
3
3
  import { property } from 'lit/decorators.js';
4
4
  import { ScopedElementsMixin } from '@open-wc/scoped-elements';
5
5
  import { DropzoneElement } from '@scoped-elements/dropzone';
6
- import { contextProvided } from '@holochain-open-dev/context';
7
- import { sharedStyles } from '../sharedStyles';
6
+ import { contextProvided } from '@lit-labs/context';
7
+ import { sharedStyles } from '../shared-styles';
8
8
  import { HolochainDropzone } from '../holochain-dropzone';
9
- import { fileStorageServiceContext } from '../context';
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
@@ -20,10 +20,10 @@ export class UploadFiles extends ScopedElementsMixin(LitElement) {
20
20
  }
21
21
  /** Private properties */
22
22
  firstUpdated() {
23
- const service = this._service;
23
+ const client = this._client;
24
24
  this.defineScopedElement('drop-zone', class extends DropzoneElement {
25
25
  buildDropzone(dropzoneElement, options) {
26
- return new HolochainDropzone(dropzoneElement, service, options);
26
+ return new HolochainDropzone(dropzoneElement, client, options);
27
27
  }
28
28
  });
29
29
  }
@@ -54,6 +54,6 @@ __decorate([
54
54
  property({ type: String, attribute: 'accepted-files' })
55
55
  ], UploadFiles.prototype, "acceptedFiles", void 0);
56
56
  __decorate([
57
- contextProvided({ context: fileStorageServiceContext })
58
- ], UploadFiles.prototype, "_service", void 0);
57
+ contextProvided({ context: fileStorageClientContext })
58
+ ], UploadFiles.prototype, "_client", void 0);
59
59
  //# 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,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAI9D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD;;;GAGG;AACH,MAAM,OAAO,WAAY,SAAQ,mBAAmB,CAAC,UAAU,CAAC;IAAhE;QACE,wBAAwB;;QAE4B,YAAO,GAAG,KAAK,CAAC;QACX,kBAAa,GAEtD,SAAS,CAAC;IA4C5B,CAAC;IArCC,yBAAyB;IAEzB,YAAY;QACV,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC;QAE9B,IAAI,CAAC,mBAAmB,CACtB,WAAW,EACX,KAAM,SAAQ,eAAe;YAC3B,aAAa,CAAC,eAA4B,EAAE,OAAwB;gBAClE,OAAO,IAAI,iBAAiB,CAAC,eAAe,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YAClE,CAAC;SACF,CACF,CAAC;IAEJ,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;AA/CqD;IAAnD,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;4CAAiB;AACX;IAAxD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC;kDAE9B;AAK1B;IADC,eAAe,CAAC,EAAE,OAAO,EAAE,yBAAyB,EAAE,CAAC;6CAC1B","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 { contextProvided } from '@holochain-open-dev/context';\nimport { DropzoneOptions } from 'dropzone';\n\nimport { FileStorageService } from '../services/file-storage.service';\nimport { sharedStyles } from '../sharedStyles';\nimport { HolochainDropzone } from '../holochain-dropzone';\nimport { fileStorageServiceContext } 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 @property({ type: Boolean, attribute: 'one-file' }) oneFile = false;\n @property({ type: String, attribute: 'accepted-files' }) acceptedFiles:\n | string\n | undefined = undefined;\n\n /** Dependencies */\n\n @contextProvided({ context: fileStorageServiceContext })\n _service!: FileStorageService;\n\n /** Private properties */\n\n firstUpdated() {\n const service = this._service;\n\n this.defineScopedElement(\n 'drop-zone',\n class extends DropzoneElement {\n buildDropzone(dropzoneElement: HTMLElement, options: DropzoneOptions) {\n return new HolochainDropzone(dropzoneElement, service, options);\n }\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
+ {"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,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIpD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,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;;QAE4B,YAAO,GAAG,KAAK,CAAC;QACX,kBAAa,GAEtD,SAAS,CAAC;IA4C5B,CAAC;IArCC,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;IAEJ,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAA;;mBAEI,IAAI,CAAC,OAAO;yBACN,IAAI,CAAC,aAAa;yBAClB,CAAC,CAAc,EAAE,EAAE,CACpC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;;KAEvC,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,MAAM;QACf,OAAO;YACL,YAAY;YACZ,GAAG,CAAA;;;;OAIF;SACF,CAAC;IACJ,CAAC;CACF;AA/CqD;IAAnD,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;4CAAiB;AACX;IAAxD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC;kDAE9B;AAK1B;IADC,eAAe,CAAC,EAAE,OAAO,EAAE,wBAAwB,EAAE,CAAC;4CAC3B","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 { contextProvided } from '@lit-labs/context';\nimport { DropzoneOptions } from 'dropzone';\n\nimport { FileStorageClient } from '../file-storage-client';\nimport { sharedStyles } from '../shared-styles';\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 @property({ type: Boolean, attribute: 'one-file' }) oneFile = false;\n @property({ type: String, attribute: 'accepted-files' }) acceptedFiles:\n | string\n | undefined = undefined;\n\n /** Dependencies */\n\n @contextProvided({ 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\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,6 +1,7 @@
1
1
  import type { CellClient } from '@holochain-open-dev/cell-client';
2
- import { FileMetadata } from '../types';
3
- export declare class FileStorageService {
2
+ import { EntryHash } from '@holochain/client';
3
+ import { FileMetadata } from './types';
4
+ export declare class FileStorageClient {
4
5
  protected cellClient: CellClient;
5
6
  protected zomeName: string;
6
7
  /**
@@ -15,24 +16,24 @@ export declare class FileStorageService {
15
16
  * @param file file to split and upload
16
17
  * @param chunkSize chunk size to split the file, default 256 KB
17
18
  */
18
- uploadFile(file: File, onProgress?: undefined | ((percentatgeProgress: number, bytesSent: number) => void), chunkSize?: number): Promise<string>;
19
+ uploadFile(file: File, onProgress?: undefined | ((percentatgeProgress: number, bytesSent: number) => void), chunkSize?: number): Promise<EntryHash>;
19
20
  /**
20
21
  * Downloads the whole file with the given hash
21
22
  * @param fileHash
22
23
  */
23
- downloadFile(fileHash: string): Promise<File>;
24
+ downloadFile(fileHash: EntryHash): Promise<File>;
24
25
  /**
25
26
  * Gets only the metadata of the file with the given hash
26
27
  * This is specially useful if you want to fetch the chunks one by one
27
28
  * @param fileHash the hash of the file
28
29
  */
29
- getFileMetadata(fileHash: string): Promise<FileMetadata>;
30
+ getFileMetadata(fileHash: EntryHash): Promise<FileMetadata>;
30
31
  /**
31
32
  * Fetch the chunk identified with the given hash
32
33
  * This is useful if used with the chunk hashes received with `getFileMetadata`
33
34
  * @param fileChunkHash
34
35
  */
35
- fetchChunk(fileChunkHash: string): Promise<Blob>;
36
+ fetchChunk(fileChunkHash: EntryHash): Promise<Blob>;
36
37
  /** Private helpers */
37
38
  private _splitFile;
38
39
  private _createChunk;
@@ -1,4 +1,4 @@
1
- export class FileStorageService {
1
+ export class FileStorageClient {
2
2
  /**
3
3
  * @param appWebsocket connection to the holochain backend
4
4
  * @param cellId the cell to which to upload the file
@@ -29,9 +29,9 @@ export class FileStorageService {
29
29
  const fileToCreate = {
30
30
  name: file.name,
31
31
  size: file.size,
32
- fileType: file.type,
33
- lastModified: file.lastModified,
34
- chunksHashes,
32
+ file_type: file.type,
33
+ last_modified: file.lastModified,
34
+ chunks_hashes: chunksHashes,
35
35
  };
36
36
  const hash = await this._callZome('create_file_metadata', fileToCreate);
37
37
  return hash;
@@ -42,11 +42,11 @@ export class FileStorageService {
42
42
  */
43
43
  async downloadFile(fileHash) {
44
44
  const metadata = await this.getFileMetadata(fileHash);
45
- const fetchChunksPromises = metadata.chunksHashes.map(hash => this.fetchChunk(hash));
45
+ const fetchChunksPromises = metadata.chunks_hashes.map(hash => this.fetchChunk(hash));
46
46
  const chunks = await Promise.all(fetchChunksPromises);
47
47
  const file = new File(chunks, metadata.name, {
48
- lastModified: metadata.lastModifed,
49
- type: metadata.fileType,
48
+ lastModified: metadata.last_modifed,
49
+ type: metadata.file_type,
50
50
  });
51
51
  return file;
52
52
  }
@@ -86,4 +86,4 @@ export class FileStorageService {
86
86
  return this.cellClient.callZome(this.zomeName, fnName, payload);
87
87
  }
88
88
  }
89
- //# sourceMappingURL=file-storage.service.js.map
89
+ //# sourceMappingURL=file-storage-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-storage-client.js","sourceRoot":"","sources":["../src/file-storage-client.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,iBAAiB;IAC5B;;;;OAIG;IACH,YACY,UAAsB,EACtB,WAAmB,cAAc;QADjC,eAAU,GAAV,UAAU,CAAY;QACtB,aAAQ,GAAR,QAAQ,CAAyB;IACzC,CAAC;IAEL;;;;;OAKG;IACH,KAAK,CAAC,UAAU,CACd,IAAU,EACV,aAEiE,SAAS,EAC1E,YAAoB,GAAG,GAAG,IAAI;QAE9B,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAC/C,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC;QACpC,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAEpC,MAAM,YAAY,GAAqB,EAAE,CAAC;QAC1C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACrC,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACpD,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC7B,IAAI,UAAU,EAAE;gBACd,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,cAAc,EAAE,aAAa,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aACvE;SACF;QAED,MAAM,YAAY,GAAG;YACnB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,SAAS,EAAE,IAAI,CAAC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,EAAE,CAAC;QAE1B,OAAO,IAAI,CAAC,IAAI,GAAG,MAAM,EAAE;YACzB,MAAM,KAAK,GAAG,IAAI,CAAC,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,MAAc,EAAE,OAAY;QAC5C,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAClE,CAAC;CACF","sourcesContent":["import type { CellClient } from '@holochain-open-dev/cell-client';\nimport { EntryHash } from '@holochain/client';\nimport { FileMetadata } from './types';\n\nexport class FileStorageClient {\n /**\n * @param appWebsocket connection to the holochain backend\n * @param cellId the cell to which to upload the file\n * @param zomeName the zome name of the file_storage zome in the given cell\n */\n constructor(\n protected cellClient: CellClient,\n protected 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(fnName: string, payload: any): Promise<any> {\n return this.cellClient.callZome(this.zomeName, fnName, payload);\n }\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import Dropzone, { DropzoneOptions } from 'dropzone';
2
- import { FileStorageService } from './services/file-storage.service';
2
+ import { FileStorageClient } from './file-storage-client';
3
3
  export declare class HolochainDropzone extends Dropzone {
4
- fileStorageService: FileStorageService;
5
- constructor(el: HTMLElement, fileStorageService: FileStorageService, options: DropzoneOptions);
4
+ fileStorageClient: FileStorageClient;
5
+ constructor(el: HTMLElement, fileStorageClient: FileStorageClient, options: DropzoneOptions);
6
6
  uploadFiles(files: Dropzone.DropzoneFile[]): void;
7
7
  _uploadFilesToHolochain(dropzoneFiles: Dropzone.DropzoneFile[]): Promise<void>;
8
8
  }
@@ -1,9 +1,9 @@
1
1
  import Dropzone from 'dropzone';
2
2
  export class HolochainDropzone extends Dropzone {
3
- constructor(el, fileStorageService, options) {
3
+ constructor(el, fileStorageClient, options) {
4
4
  options.url = 'https://holochain.org/'; // just to bypass the check.
5
5
  super(el, options);
6
- this.fileStorageService = fileStorageService;
6
+ this.fileStorageClient = fileStorageClient;
7
7
  }
8
8
  uploadFiles(files) {
9
9
  this._uploadFilesToHolochain(files);
@@ -12,7 +12,7 @@ export class HolochainDropzone extends Dropzone {
12
12
  for (const file of dropzoneFiles) {
13
13
  try {
14
14
  this.emit('sending', file, undefined, undefined);
15
- const hash = await this.fileStorageService.uploadFile(file, (percentatge, bytesSent) => {
15
+ const hash = await this.fileStorageClient.uploadFile(file, (percentatge, bytesSent) => {
16
16
  this.emit('uploadprogress', file, percentatge * 100, bytesSent);
17
17
  });
18
18
  this.emit('success', file, undefined);
@@ -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,kBAAsC,EACtC,OAAwB;QAExB,OAAO,CAAC,GAAG,GAAG,wBAAwB,CAAC,CAAC,4BAA4B;QACpE,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QACnB,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;IAC/C,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,kBAAkB,CAAC,UAAU,CACnD,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;gBACtC,aAAa;gBACb,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;gBACjB,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 { FileStorageService } from './services/file-storage.service';\n\nexport class HolochainDropzone extends Dropzone {\n fileStorageService: FileStorageService;\n constructor(\n el: HTMLElement,\n fileStorageService: FileStorageService,\n options: DropzoneOptions\n ) {\n options.url = 'https://holochain.org/'; // just to bypass the check.\n super(el, options);\n this.fileStorageService = fileStorageService;\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.fileStorageService.uploadFile(\n file,\n (percentatge, bytesSent) => {\n this.emit('uploadprogress', file, percentatge * 100, bytesSent);\n }\n );\n this.emit('success', file, undefined);\n // @ts-ignore\n file.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"]}
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;gBACtC,aAAa;gBACb,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;gBACjB,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 // @ts-ignore\n file.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/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './elements/upload-files';
2
- export * from './services/file-storage.service';
2
+ export * from './elements/show-image';
3
+ export * from './file-storage-client';
3
4
  export * from './holochain-dropzone';
4
5
  export * from './types';
5
6
  export * from './context';
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './elements/upload-files';
2
- export * from './services/file-storage.service';
2
+ export * from './elements/show-image';
3
+ export * from './file-storage-client';
3
4
  export * from './holochain-dropzone';
4
5
  export * from './types';
5
6
  export * from './context';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC;AAChD,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC","sourcesContent":["export * from './elements/upload-files';\nexport * from './services/file-storage.service';\nexport * from './holochain-dropzone';\nexport * from './types';\nexport * from './context';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC","sourcesContent":["export * from './elements/upload-files';\nexport * from './elements/show-image';\nexport * from './file-storage-client';\nexport * from './holochain-dropzone';\nexport * from './types';\nexport * from './context';\n"]}
File without changes
@@ -13,4 +13,4 @@ export const sharedStyles = css `
13
13
  justify-content: center;
14
14
  }
15
15
  `;
16
- //# sourceMappingURL=sharedStyles.js.map
16
+ //# sourceMappingURL=shared-styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-styles.js","sourceRoot":"","sources":["../src/shared-styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAA;;;;;;;;;;;;;CAa9B,CAAC","sourcesContent":["import { css } from 'lit';\n\nexport const sharedStyles = css`\n .column {\n display: flex;\n flex-direction: column;\n }\n .row {\n display: flex;\n flex-direction: row;\n }\n .center-content {\n align-items: center;\n justify-content: center;\n }\n`;\n"]}
package/dist/types.d.ts CHANGED
@@ -1,8 +1,8 @@
1
+ import { EntryHash } from "@holochain/client";
1
2
  export interface FileMetadata {
2
3
  name: string;
3
- lastModifed: number;
4
+ last_modifed: number;
4
5
  size: number;
5
- fileType: string;
6
- creatorPubKey: string;
7
- chunksHashes: Array<string>;
6
+ file_type: string;
7
+ chunks_hashes: Array<EntryHash>;
8
8
  }
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface FileMetadata {\n name: string;\n lastModifed: number;\n size: number;\n fileType: string;\n creatorPubKey: string;\n chunksHashes: Array<string>;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { EntryHash } from \"@holochain/client\";\n\nexport interface FileMetadata {\n name: string;\n last_modifed: number;\n size: number;\n file_type: string;\n chunks_hashes: Array<EntryHash>;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holochain-open-dev/file-storage",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "File storage utilities to store files in holochain DHT",
5
5
  "author": "guillem.cordoba@gmail.com",
6
6
  "license": "MIT",
@@ -8,68 +8,60 @@
8
8
  "module": "dist/index.js",
9
9
  "exports": {
10
10
  ".": "./dist/index.js",
11
- "./upload-files": "./dist/definitions/upload-files.js"
11
+ "./upload-files": "./dist/definitions/upload-files.js",
12
+ "./show-image": "./dist/definitions/show-image.js"
12
13
  },
13
14
  "files": [
14
15
  "dist"
15
16
  ],
16
-
17
17
  "scripts": {
18
- "start": "npm run build && concurrently -k --names tsc,dev-server \"npm run build-watch\" \"web-dev-server --config demo/web-dev-server.config.mjs\"",
18
+ "start": "npm run build && concurrently -k --names tsc,dev-server \"npm run build-watch\" \"web-dev-server --config web-dev-server.config.mjs\"",
19
19
  "build": "tsc",
20
20
  "build-watch": "tsc -w --preserveWatchOutput",
21
- "test": "npm run build && web-test-runner --coverage --puppeteer",
22
- "test-debug": "npm run build && DEBUG=true web-test-runner --coverage --puppeteer",
23
- "test-watch": "web-test-runner --watch --puppeteer",
24
- "e2e": "CONDUCTOR_URL=ws://localhost:8888 concurrently -k -s first \"npm:test\" \"npm:start-holochain\"",
25
- "analyze": "wca analyze src --format json --outFile custom-elements.json",
26
21
  "lint": "eslint --ext .ts,.html . --ignore-path .gitignore",
27
22
  "format": "eslint --ext .ts,.html . --fix --ignore-path .gitignore"
28
23
  },
29
24
  "dependencies": {
30
- "@holochain/client": "^0.3.2",
31
- "@holochain-open-dev/cell-client": "^0.3.2",
32
- "@holochain-open-dev/context": "^0.0.3",
33
- "@open-wc/scoped-elements": "^2.0.1",
25
+ "@holochain/client": "^0.9.3",
26
+ "@holochain-open-dev/elements": "^0.0.4",
27
+ "@lit-labs/context": "^0.1.3",
28
+ "@lit-labs/task": "^2.0.0",
29
+ "@open-wc/scoped-elements": "^2.1.0",
34
30
  "@scoped-elements/dropzone": "^0.0.3",
35
31
  "@scoped-elements/material-web": "^0.0.19",
36
32
  "lit": "^2.2.0"
37
33
  },
38
34
  "devDependencies": {
39
- "@open-wc/eslint-config": "^2.1.0",
40
- "@open-wc/testing": "^3.0.0-next.5",
41
- "@open-wc/testing-karma": "^4.0.9",
42
- "@rollup/plugin-commonjs": "^15.1.0",
43
- "@rollup/plugin-node-resolve": "^9.0.0",
44
- "@rollup/plugin-replace": "^2.4.2",
45
- "@rollup/plugin-typescript": "^8.2.1",
46
- "@types/dropzone": "^5.7.0",
47
- "@types/node": "13.11.1",
48
- "@typescript-eslint/eslint-plugin": "^2.34.0",
49
- "@typescript-eslint/parser": "^2.34.0",
50
- "@web/dev-server": "0.0.13",
51
- "@web/dev-server-rollup": "^0.2.9",
52
- "@web/test-runner": "^0.7.41",
53
- "@web/test-runner-puppeteer": "^0.6.4",
54
- "buffer": "^5.6.0",
55
- "concurrently": "^5.1.0",
56
- "deepmerge": "^3.2.0",
57
- "es-dev-server": "^1.23.0",
58
- "eslint": "^6.8.0",
59
- "eslint-config-prettier": "^6.15.0",
60
- "gh-pages": "^3.1.0",
61
- "husky": "^1.0.0",
62
- "lint-staged": "^10.0.0",
63
- "prettier": "^2.0.4",
35
+ "@babel/preset-env": "^7.15.0",
36
+ "@open-wc/building-rollup": "^1.10.0",
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",
43
+ "@types/dropzone": "^5.7.4",
44
+ "@typescript-eslint/eslint-plugin": "^5.43.0",
45
+ "@typescript-eslint/parser": "^5.43.0",
46
+ "@web/dev-server": "0.1.21",
47
+ "@web/dev-server-rollup": "^0.3.10",
48
+ "@web/rollup-plugin-html": "^1.9.1",
49
+ "@web/rollup-plugin-import-meta-assets": "^1.0.7",
50
+ "babel-plugin-template-html-minifier": "^4.1.0",
51
+ "bestzip": "^2.2.0",
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",
64
59
  "rimraf": "^3.0.2",
65
- "rollup": "^2.32.0",
66
- "rollup-plugin-node-builtins": "^2.1.2",
67
- "rollup-plugin-node-globals": "^1.4.0",
68
- "rollup-plugin-postcss": "^3.1.8",
69
- "rollup-plugin-postcss-lit": "^1.0.1",
70
- "tslib": "^1.11.0",
71
- "typescript": "~4.2.4",
72
- "web-component-analyzer": "^1.1.6"
60
+ "rollup": "^2.56.2",
61
+ "rollup-plugin-terser": "^7.0.2",
62
+ "run-singleton-cli": "^0.0.7",
63
+ "tslib": "^2.3.1",
64
+ "typescript": "^4.9.0"
73
65
  },
74
66
  "eslintConfig": {
75
67
  "extends": [
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-storage.service.js","sourceRoot":"","sources":["../../src/services/file-storage.service.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,kBAAkB;IAC7B;;;;OAIG;IACH,YACY,UAAsB,EACtB,WAAmB,cAAc;QADjC,eAAU,GAAV,UAAU,CAAY;QACtB,aAAQ,GAAR,QAAQ,CAAyB;IAC1C,CAAC;IAEJ;;;;;OAKG;IACH,KAAK,CAAC,UAAU,CACd,IAAU,EACV,aAEiE,SAAS,EAC1E,YAAoB,GAAG,GAAG,IAAI;QAE9B,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAC/C,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC;QACpC,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAEpC,MAAM,YAAY,GAAkB,EAAE,CAAC;QACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACrC,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACpD,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC7B,IAAI,UAAU,EAAE;gBACd,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,cAAc,EAAE,aAAa,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aACvE;SACF;QAED,MAAM,YAAY,GAAG;YACnB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,QAAQ,EAAE,IAAI,CAAC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;QAE1B,OAAO,IAAI,CAAC,IAAI,GAAG,MAAM,EAAE;YACzB,MAAM,KAAK,GAAG,IAAI,CAAC,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,MAAc,EAAE,OAAY;QAC5C,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAClE,CAAC;CACF","sourcesContent":["import type { CellClient } from '@holochain-open-dev/cell-client';\nimport { FileMetadata } from '../types';\n\nexport class FileStorageService {\n /**\n * @param appWebsocket connection to the holochain backend\n * @param cellId the cell to which to upload the file\n * @param zomeName the zome name of the file_storage zome in the given cell\n */\n constructor(\n protected cellClient: CellClient,\n protected 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<string> {\n const blobs = this._splitFile(file, chunkSize);\n const numberOfChunks = blobs.length;\n const bytesPerChunk = blobs[0].size;\n\n const chunksHashes: Array<string> = [];\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 fileType: file.type,\n lastModified: file.lastModified,\n 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: string): Promise<File> {\n const metadata = await this.getFileMetadata(fileHash);\n\n const fetchChunksPromises = metadata.chunksHashes.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.lastModifed,\n type: metadata.fileType,\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: string): 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: string): 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<string> {\n const bytes = await chunk.arrayBuffer();\n\n return this._callZome('create_file_chunk', new Uint8Array(bytes));\n }\n\n private _callZome(fnName: string, payload: any): Promise<any> {\n return this.cellClient.callZome(this.zomeName, fnName, payload);\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"sharedStyles.js","sourceRoot":"","sources":["../src/sharedStyles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAA;;;;;;;;;;;;;CAa9B,CAAC","sourcesContent":["import { css } from 'lit';\n\nexport const sharedStyles = css`\n .column {\n display: flex;\n flex-direction: column;\n }\n .row {\n display: flex;\n flex-direction: row;\n }\n .center-content {\n align-items: center;\n justify-content: center;\n }\n`;\n"]}