Skip to content

Commit

Permalink
Implemented get_file_info() for File attachable.
Browse files Browse the repository at this point in the history
  • Loading branch information
ddd-mtl committed Sep 26, 2023
1 parent db26476 commit 199a572
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 17 deletions.
15 changes: 15 additions & 0 deletions dna/zomes/file_share/src/get_file_info.rs
Original file line number Diff line number Diff line change
@@ -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<ParcelManifest> {
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)
}
1 change: 1 addition & 0 deletions dna/zomes/file_share/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ mod utils;
mod probe_public_files;
mod write_file_chunk;
mod respond_to_file_share_notice;
mod get_file_info;
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"",
Expand All @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions we-applet/src/applet-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
},

Expand Down
1 change: 1 addition & 0 deletions webcomponents/src/bindings/file_share.fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions webcomponents/src/bindings/file_share.proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ export class FileShareProxy extends ZomeProxy {
return this.call('commit_private_file', input);
}

async getFileInfo(eh: EntryHash): Promise<ParcelManifest> {
return this.call('get_file_info', eh);
}

async getPrivateFiles(): Promise<[EntryHash, ParcelManifest][]> {
return this.call('get_private_files', null);
}
Expand Down
21 changes: 11 additions & 10 deletions webcomponents/src/elements/file-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export class FileView extends DnaElement<unknown, FileShareDvm> {

/** -- Properties -- */

/** Hash of Thread to display */
@property() hash: ActionHashB64 = ''
/** Hash of ParcelManifest to display */
@property() hash: EntryHashB64 = ''

/** Enable action bar */
@property() showActionBar: boolean = false
Expand All @@ -53,7 +53,8 @@ export class FileView extends DnaElement<unknown, FileShareDvm> {

/** -- State variables -- */

@state() private _loading = false;
@state() private _loading = true;
@state() private _manifest?;


/** -- Methods -- */
Expand Down Expand Up @@ -93,7 +94,7 @@ export class FileView extends DnaElement<unknown, FileShareDvm> {
console.log("<file-view>.loadMessages()", changedProperties, !!this._dvm, this.hash);
if (changedProperties.has("hash") && this._dvm) {
console.log("<file-view>.willUpdate()", this.hash);
this._dvm.fileShareZvm.probeAll();
this._manifest = await this._dvm.fileShareZvm.zomeProxy.getFileInfo(decodeHashFromBase64(this.hash));
}
}

Expand All @@ -104,16 +105,16 @@ export class FileView extends DnaElement<unknown, FileShareDvm> {
return html`
<div style="color:#c10a0a">No file selected</div>`;
}
const manifest = this.fileSharePerspective.privateFiles[this.hash];
if (!manifest) {
return html`<div style="color:#c10a0a">File not found</div>`;
if (!this._manifest) {
return html`
<div style="color:#c10a0a">File not found</div>`;
}

/** render all */
return html`
<h4 style="margin-left: 5px;">${manifest.description.name}</h4>
<div>Size: ${manifest.description.size} bytes</div>
<div>type: ${(manifest.description.kind_info as ParcelKindVariantManifest).Manifest}</div>
<h4 style="margin-left: 5px;">${this._manifest.description.name}</h4>
<div>Size: ${this._manifest.description.size} bytes</div>
<div>type: ${(this._manifest.description.kind_info as ParcelKindVariantManifest).Manifest}</div>
${this.showActionBar
? html`<input type="button" value="Download">`
: html``
Expand Down

0 comments on commit 199a572

Please sign in to comment.