From 199a572e1d42db3ca37b5949a940630e3b783da2 Mon Sep 17 00:00:00 2001 From: damien Date: Tue, 26 Sep 2023 11:15:57 -0400 Subject: [PATCH] Implemented get_file_info() for File attachable. --- dna/zomes/file_share/src/get_file_info.rs | 15 +++++++++++++ dna/zomes/file_share/src/lib.rs | 1 + package.json | 8 +++---- we-applet/src/applet-view.ts | 6 +++--- webcomponents/src/bindings/file_share.fn.ts | 1 + .../src/bindings/file_share.proxy.ts | 4 ++++ webcomponents/src/elements/file-view.ts | 21 ++++++++++--------- 7 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 dna/zomes/file_share/src/get_file_info.rs diff --git a/dna/zomes/file_share/src/get_file_info.rs b/dna/zomes/file_share/src/get_file_info.rs new file mode 100644 index 0000000..849d03d --- /dev/null +++ b/dna/zomes/file_share/src/get_file_info.rs @@ -0,0 +1,15 @@ +use hdk::prelude::*; +use zome_utils::*; + +use zome_delivery_types::*; +use crate::utils::ensure_parcel_is_file; + + +/// Return manifest +#[hdk_extern] +pub fn get_file_info(eh: EntryHash) -> ExternResult { + std::panic::set_hook(Box::new(zome_panic_hook)); + let manifest: ParcelManifest = get_typed_from_eh(eh)?; + ensure_parcel_is_file(&manifest.description)?; + Ok(manifest) +} diff --git a/dna/zomes/file_share/src/lib.rs b/dna/zomes/file_share/src/lib.rs index cae67f7..e5b9056 100644 --- a/dna/zomes/file_share/src/lib.rs +++ b/dna/zomes/file_share/src/lib.rs @@ -17,3 +17,4 @@ mod utils; mod probe_public_files; mod write_file_chunk; mod respond_to_file_share_notice; +mod get_file_info; diff --git a/package.json b/package.json index b510b31..dc26826 100644 --- a/package.json +++ b/package.json @@ -35,10 +35,10 @@ "devtest" : "npm run build:devtest && concurrently \"npm run build:watch -w webcomponents\" \"npm run build:watch -w webapp\" \"npm run start:mem\"", "devtest:we" : "npm run build:devtest:we && npm run devtest -w we-applet", + "prodtest" : "npm run dist -w webapp && cross-env HC_APP_PORT=$(port) HC_ADMIN_PORT=$(port) concurrently \"npm run dev:components\" \"npm run new-sandbox:mem\" \"sleep 7 && npm run start:ui -w webapp\"", "_save-ports" : "echo $HC_APP_PORT > .hc_app_$INDEX && echo $HC_ADMIN_PORT > .hc_admin_$INDEX", - "prodtest" : "npm run dist -w webapp && cross-env HC_APP_PORT=$(port) HC_ADMIN_PORT=$(port) concurrently \"npm run dev:components\" \"npm run new-sandbox:mem\" \"sleep 7 && npm run start:ui -w webapp\"", "start:mem" : "cross-env HC_APP_PORT=$(port) HC_ADMIN_PORT=$(port) BUILD_MODE='dev' ADD_PROFILES=1 concurrently \"npm run dev:components\" \"npm run new-sandbox:mem\" \"sleep 7 && npm run start:ui -w webapp\"", "start:local" : "echo START:LOCAL $INDEX & cross-env HC_APP_PORT=$(port) HC_ADMIN_PORT=$(port) BUILD_MODE='dev' ADD_PROFILES=1 concurrently \"npm run _save-ports\" \"npm run dev:components\" \"npm run new-sandbox:local\" \"sleep 7 && npm run start:ui -w webapp\"", "start:public" : "cross-env HC_APP_PORT=$(port) HC_ADMIN_PORT=$(port) BUILD_MODE='dev' concurrently \"npm run dev:components\" \"npm run new-sandbox:public\" \"sleep 7 && npm run start:ui -w webapp\"", @@ -49,11 +49,11 @@ "serve:run" : "hc run-local-services --bootstrap-port $BOOT_PORT --signal-port $SIGNAL_PORT", "serve:save" : "echo SIGNAL_PORT=$SIGNAL_PORT && echo $SIGNAL_PORT > .hc_signalenv && echo $BOOT_PORT > .hc_bootenv && echo BOOT_PORT=$BOOT_PORT", "serve" : "cross-env BOOT_PORT=$(cat .hc_bootenv) SIGNAL_PORT=$(cat .hc_signalenv) npm run serve:run", - "network2" : "npm run clean:hc & npm run build:devtest && cross-env BOOT_PORT=$(port) SIGNAL_PORT=$(port) concurrently \"npm run serve:save\" \"npm run serve:run\" \"cross-env INDEX=0 npm run new-sandbox:local\" \"sleep 1 && cross-env INDEX=1 npm run new-sandbox:local\"", - "network3" : "npm run clean:hc & npm run build:devtest && cross-env BOOT_PORT=$(port) SIGNAL_PORT=$(port) concurrently \"npm run serve:save\" \"npm run serve:run\" \"cross-env INDEX=0 npm run new-sandbox:local\" \"sleep 1 && cross-env INDEX=1 npm run new-sandbox:local\" \"sleep 2 && cross-env INDEX=2 npm run new-sandbox:local\"", + "network2" : "npm run clean:hc & npm run build:devtest && cross-env BOOT_PORT=$(port) SIGNAL_PORT=$(port) concurrently \"npm run serve:save\" \"npm run serve:run\" \"cross-env INDEX=0 npm run start:local\" \"sleep 1 && cross-env INDEX=1 npm run start:local\"", + "network3" : "npm run clean:hc & npm run build:devtest && cross-env BOOT_PORT=$(port) SIGNAL_PORT=$(port) concurrently \"npm run serve:save\" \"npm run serve:run\" \"cross-env INDEX=0 npm run start:local\" \"sleep 1 && cross-env INDEX=1 npm run start:local\" \"sleep 2 && cross-env INDEX=2 npm run start:local\"", "network:we" : "npm run clean:hc & npm run network:local2 -w we-applet", - "local:sandbox" : "echo INDEX: $INDEX & echo PORTS: $BOOT_PORT $SIGNAL_PORT $HC_APP_PORT $HC_ADMIN_PORT & RUST_LOG=warn WASM_LOG=warn echo \"pass\" | $npm_package_config_bin/hc s --piped -f=$HC_ADMIN_PORT run $INDEX", + "local:sandbox" : "echo INDEX $INDEX & echo PORTS $BOOT_PORT $SIGNAL_PORT $HC_APP_PORT $HC_ADMIN_PORT & RUST_LOG=warn WASM_LOG=warn echo \"pass\" | $npm_package_config_bin/hc s --piped -f=$HC_ADMIN_PORT run $INDEX", "_local" : "cross-env BOOT_PORT=$(cat .hc_bootenv) SIGNAL_PORT=$(cat .hc_signalenv) HC_APP_PORT=$(cat .hc_app_$INDEX) HC_ADMIN_PORT=$(cat .hc_admin_$INDEX) BUILD_MODE='dev' ADD_PROFILES=1 concurrently \"npm run local:sandbox\" \"sleep 7 && npm run start:ui-only -w webapp\"", "local0" : "cross-env INDEX=0 npm run _local", "local1" : "cross-env INDEX=1 npm run _local", diff --git a/we-applet/src/applet-view.ts b/we-applet/src/applet-view.ts index d89c9e7..769d952 100644 --- a/we-applet/src/applet-view.ts +++ b/we-applet/src/applet-view.ts @@ -110,11 +110,11 @@ export async function appletViews( console.log("(applet-view) cellProxy", cellProxy); const proxy: FileShareProxy = new FileShareProxy(cellProxy); console.log("(applet-view) getFile()", encodeHashToBase64(hrl[1]), proxy); - const pair = await proxy.getFile(hrl[1]); - console.log("(applet-view) file", pair); + const manifest = await proxy.getFileInfo(hrl[1]); + console.log("(applet-view) file", manifest.description); return { icon_src: "", - name: pair[0].name, + name: manifest.description.name, }; }, diff --git a/webcomponents/src/bindings/file_share.fn.ts b/webcomponents/src/bindings/file_share.fn.ts index 9bb7631..9b65da5 100644 --- a/webcomponents/src/bindings/file_share.fn.ts +++ b/webcomponents/src/bindings/file_share.fn.ts @@ -10,6 +10,7 @@ export const fileShareFunctionNames: FunctionName[] = [ "get_dna_info", "commit_private_file", + "get_file_info", "get_private_files", "get_local_public_files", "get_private_files_from", diff --git a/webcomponents/src/bindings/file_share.proxy.ts b/webcomponents/src/bindings/file_share.proxy.ts index a79d1d0..a766e40 100644 --- a/webcomponents/src/bindings/file_share.proxy.ts +++ b/webcomponents/src/bindings/file_share.proxy.ts @@ -150,6 +150,10 @@ export class FileShareProxy extends ZomeProxy { return this.call('commit_private_file', input); } + async getFileInfo(eh: EntryHash): Promise { + return this.call('get_file_info', eh); + } + async getPrivateFiles(): Promise<[EntryHash, ParcelManifest][]> { return this.call('get_private_files', null); } diff --git a/webcomponents/src/elements/file-view.ts b/webcomponents/src/elements/file-view.ts index 0998fe7..bd96cc8 100644 --- a/webcomponents/src/elements/file-view.ts +++ b/webcomponents/src/elements/file-view.ts @@ -41,8 +41,8 @@ export class FileView extends DnaElement { /** -- Properties -- */ - /** Hash of Thread to display */ - @property() hash: ActionHashB64 = '' + /** Hash of ParcelManifest to display */ + @property() hash: EntryHashB64 = '' /** Enable action bar */ @property() showActionBar: boolean = false @@ -53,7 +53,8 @@ export class FileView extends DnaElement { /** -- State variables -- */ - @state() private _loading = false; + @state() private _loading = true; + @state() private _manifest?; /** -- Methods -- */ @@ -93,7 +94,7 @@ export class FileView extends DnaElement { console.log(".loadMessages()", changedProperties, !!this._dvm, this.hash); if (changedProperties.has("hash") && this._dvm) { console.log(".willUpdate()", this.hash); - this._dvm.fileShareZvm.probeAll(); + this._manifest = await this._dvm.fileShareZvm.zomeProxy.getFileInfo(decodeHashFromBase64(this.hash)); } } @@ -104,16 +105,16 @@ export class FileView extends DnaElement { return html`
No file selected
`; } - const manifest = this.fileSharePerspective.privateFiles[this.hash]; - if (!manifest) { - return html`
File not found
`; + if (!this._manifest) { + return html` +
File not found
`; } /** render all */ return html` -

${manifest.description.name}

-
Size: ${manifest.description.size} bytes
-
type: ${(manifest.description.kind_info as ParcelKindVariantManifest).Manifest}
+

${this._manifest.description.name}

+
Size: ${this._manifest.description.size} bytes
+
type: ${(this._manifest.description.kind_info as ParcelKindVariantManifest).Manifest}
${this.showActionBar ? html`` : html``