parent
e188c5ee39
commit
19d4cbfc21
@ -0,0 +1,64 @@ |
||||
// Copyright (c) 2022-2023 Niko Bonnieure, Par le Peuple, NextGraph.org developers
|
||||
// All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
// <LICENSE-APACHE2 or http://www.apache.org/licenses/LICENSE-2.0>
|
||||
// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
|
||||
// at your option. All files in the project carrying such
|
||||
// notice may not be copied, modified, or distributed except
|
||||
// according to those terms.
|
||||
import {createAsyncProxy} from "async-proxy"; |
||||
import { writable } from "svelte/store"; |
||||
|
||||
const mapping = { |
||||
"create_wallet": [ "name" ], |
||||
"doc_get_file_from_store_with_object_ref": [ "nuri","obj_ref" ], |
||||
"test": [ ] |
||||
} |
||||
|
||||
let lastStreamId = 0; |
||||
|
||||
const handler = { |
||||
async apply(target, path, caller, args) { |
||||
|
||||
if (import.meta.env.NG_APP_WEB) { |
||||
let sdk = await import("ng-sdk-js") |
||||
return Reflect.apply(sdk[path], caller, args) |
||||
} else { |
||||
let tauri = await import("@tauri-apps/api/tauri"); |
||||
|
||||
if (path[0] === "doc_sync_branch") { |
||||
let stream_id = (lastStreamId += 1).toString(); |
||||
console.log("stream_id",stream_id); |
||||
let { listen } = await import("@tauri-apps/api/event"); |
||||
let nuri = args[0]; |
||||
let callback = args[1]; |
||||
|
||||
let unlisten = await listen(stream_id, (event) => { |
||||
callback(event.payload).then(()=> {}) |
||||
}) |
||||
await tauri.invoke("doc_sync_branch",{nuri, stream_id}); |
||||
|
||||
return () => { |
||||
unlisten(); |
||||
tauri.invoke("cancel_doc_sync_branch", {stream_id}); |
||||
} |
||||
} else if (path[0] === "doc_get_file_from_store_with_object_ref") { |
||||
let arg = {}; |
||||
args.map((el,ix) => arg[mapping[path[0]][ix]]=el) |
||||
let res = await tauri.invoke(path[0],arg); |
||||
res['File'].V0.content = Uint8Array.from(res['File'].V0.content); |
||||
res['File'].V0.metadata = Uint8Array.from(res['File'].V0.metadata); |
||||
return res |
||||
} |
||||
else { |
||||
let arg = {}; |
||||
args.map((el,ix) => arg[mapping[path[0]][ix]]=el) |
||||
return tauri.invoke(path[0],arg) |
||||
} |
||||
} |
||||
}, |
||||
}; |
||||
|
||||
const api = createAsyncProxy({}, handler); |
||||
|
||||
export default api; |
@ -0,0 +1,8 @@ |
||||
<script> |
||||
// The params prop contains values matched from the URL |
||||
export let params = {}; |
||||
|
||||
console.log(params); |
||||
</script> |
||||
|
||||
<p>nextgraph URI {params[1]}</p> |
@ -0,0 +1,33 @@ |
||||
import { writable } from "svelte/store"; |
||||
import ng from "./api"; |
||||
|
||||
const branch_commits = (nura, sub) => { |
||||
|
||||
const { subscribe, set, update } = writable([]); // create the underlying writable store
|
||||
|
||||
let unsub = () => {}; |
||||
return { |
||||
load: async () => { |
||||
unsub = await ng.doc_sync_branch(nura, async (commit) => { |
||||
console.log(commit); |
||||
update( (old) => {old.unshift(commit); return old;} ) |
||||
}); |
||||
}, |
||||
subscribe: (run, invalid) => { |
||||
|
||||
let upper_unsub = subscribe(run, invalid); |
||||
|
||||
return () => { |
||||
upper_unsub(); |
||||
unsub(); |
||||
} |
||||
} |
||||
// set: (value) => {
|
||||
// localStorage.setItem(key, toString(value)); // save also to local storage as a string
|
||||
// return set(value);
|
||||
// },
|
||||
// update,
|
||||
}; |
||||
}; |
||||
|
||||
export default branch_commits; |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1 @@ |
||||
pub mod file; |
After Width: | Height: | Size: 29 KiB |
Loading…
Reference in new issue