Skip to content

Commit 199a572

Browse files
committed
Implemented get_file_info() for File attachable.
1 parent db26476 commit 199a572

File tree

7 files changed

+39
-17
lines changed

7 files changed

+39
-17
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use hdk::prelude::*;
2+
use zome_utils::*;
3+
4+
use zome_delivery_types::*;
5+
use crate::utils::ensure_parcel_is_file;
6+
7+
8+
/// Return manifest
9+
#[hdk_extern]
10+
pub fn get_file_info(eh: EntryHash) -> ExternResult<ParcelManifest> {
11+
std::panic::set_hook(Box::new(zome_panic_hook));
12+
let manifest: ParcelManifest = get_typed_from_eh(eh)?;
13+
ensure_parcel_is_file(&manifest.description)?;
14+
Ok(manifest)
15+
}

dna/zomes/file_share/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ mod utils;
1717
mod probe_public_files;
1818
mod write_file_chunk;
1919
mod respond_to_file_share_notice;
20+
mod get_file_info;

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535

3636
"devtest" : "npm run build:devtest && concurrently \"npm run build:watch -w webcomponents\" \"npm run build:watch -w webapp\" \"npm run start:mem\"",
3737
"devtest:we" : "npm run build:devtest:we && npm run devtest -w we-applet",
38+
"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\"",
3839

3940
"_save-ports" : "echo $HC_APP_PORT > .hc_app_$INDEX && echo $HC_ADMIN_PORT > .hc_admin_$INDEX",
4041

41-
"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\"",
4242
"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\"",
4343
"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\"",
4444
"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 @@
4949
"serve:run" : "hc run-local-services --bootstrap-port $BOOT_PORT --signal-port $SIGNAL_PORT",
5050
"serve:save" : "echo SIGNAL_PORT=$SIGNAL_PORT && echo $SIGNAL_PORT > .hc_signalenv && echo $BOOT_PORT > .hc_bootenv && echo BOOT_PORT=$BOOT_PORT",
5151
"serve" : "cross-env BOOT_PORT=$(cat .hc_bootenv) SIGNAL_PORT=$(cat .hc_signalenv) npm run serve:run",
52-
"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\"",
53-
"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\"",
52+
"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\"",
53+
"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\"",
5454
"network:we" : "npm run clean:hc & npm run network:local2 -w we-applet",
5555

56-
"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",
56+
"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",
5757
"_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\"",
5858
"local0" : "cross-env INDEX=0 npm run _local",
5959
"local1" : "cross-env INDEX=1 npm run _local",

we-applet/src/applet-view.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ export async function appletViews(
110110
console.log("(applet-view) cellProxy", cellProxy);
111111
const proxy: FileShareProxy = new FileShareProxy(cellProxy);
112112
console.log("(applet-view) getFile()", encodeHashToBase64(hrl[1]), proxy);
113-
const pair = await proxy.getFile(hrl[1]);
114-
console.log("(applet-view) file", pair);
113+
const manifest = await proxy.getFileInfo(hrl[1]);
114+
console.log("(applet-view) file", manifest.description);
115115
return {
116116
icon_src: "",
117-
name: pair[0].name,
117+
name: manifest.description.name,
118118
};
119119
},
120120

webcomponents/src/bindings/file_share.fn.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const fileShareFunctionNames: FunctionName[] = [
1010
"get_dna_info",
1111

1212
"commit_private_file",
13+
"get_file_info",
1314
"get_private_files",
1415
"get_local_public_files",
1516
"get_private_files_from",

webcomponents/src/bindings/file_share.proxy.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ export class FileShareProxy extends ZomeProxy {
150150
return this.call('commit_private_file', input);
151151
}
152152

153+
async getFileInfo(eh: EntryHash): Promise<ParcelManifest> {
154+
return this.call('get_file_info', eh);
155+
}
156+
153157
async getPrivateFiles(): Promise<[EntryHash, ParcelManifest][]> {
154158
return this.call('get_private_files', null);
155159
}

webcomponents/src/elements/file-view.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export class FileView extends DnaElement<unknown, FileShareDvm> {
4141

4242
/** -- Properties -- */
4343

44-
/** Hash of Thread to display */
45-
@property() hash: ActionHashB64 = ''
44+
/** Hash of ParcelManifest to display */
45+
@property() hash: EntryHashB64 = ''
4646

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

5454
/** -- State variables -- */
5555

56-
@state() private _loading = false;
56+
@state() private _loading = true;
57+
@state() private _manifest?;
5758

5859

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

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

112113
/** render all */
113114
return html`
114-
<h4 style="margin-left: 5px;">${manifest.description.name}</h4>
115-
<div>Size: ${manifest.description.size} bytes</div>
116-
<div>type: ${(manifest.description.kind_info as ParcelKindVariantManifest).Manifest}</div>
115+
<h4 style="margin-left: 5px;">${this._manifest.description.name}</h4>
116+
<div>Size: ${this._manifest.description.size} bytes</div>
117+
<div>type: ${(this._manifest.description.kind_info as ParcelKindVariantManifest).Manifest}</div>
117118
${this.showActionBar
118119
? html`<input type="button" value="Download">`
119120
: html``

0 commit comments

Comments
 (0)