Last active
September 17, 2020 17:48
-
-
Save viraj124/28777f8af22603e2cebf4e6372256a15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; | |
const {SpaceClient} = require("@fleekhq/space-client"); | |
const client = new SpaceClient({url: `http://localhost:9998`}); | |
(async () => { | |
console.log(await client.generateKeyPairWithForce()); | |
const bucket = "personal" | |
// try { | |
// console.log("creating bucket..."); | |
// const res = await client.createBucket({slug: bucket}); | |
// const bucketObj = res.getBucket(); | |
// console.log(bucketObj); | |
// } catch (error) { | |
// console.error(error); | |
// } | |
// try { | |
// console.log("creating folder..."); | |
// await client.createFolder({bucket, path: "testFolderA"}); | |
// console.log("folder created!"); | |
// } catch (error) { | |
// console.error(error); | |
// } | |
// try { | |
// console.log('fetchig directory...'); | |
// const res = await client.listDirectory({bucket, path: ""}); | |
// const entryList = res.getEntriesList(); | |
// console.log(entryList); | |
// } catch (error) { | |
// console.error(error); | |
// } | |
// try { | |
// console.log("sharing bucket..."); | |
// const res = await client.shareBucket({bucket}); | |
// const threadInfo = res.getThreadinfo(); | |
// console.log({bucket, key: threadInfo.getKey(), addressList: threadInfo.getAddressesList(), addresses: threadInfo.getAddressesList().join(", ")}); | |
// } catch (error) { | |
// console.error(error); | |
// } | |
try { | |
// console.log("sharing & joining bucket..."); | |
// const res = await client.shareBucket({bucket}); | |
// const threadInfo = res.getThreadinfo(); | |
// console.log({bucket, key: threadInfo.getKey(), addressList: threadInfo.getAddressesList(), addresses: threadInfo.getAddressesList().join(", ")}); | |
// joining bucket needs to be run on the other machine | |
// const res = await client.joinBucket({ | |
// bucket: "buckettoshare1594789044480", | |
// threadInfo: { | |
// key: "bjpkpt3wqkhf7os6zlwi2itplyxjs6tmgcbiqxdn4rgeqgcrvhmgidz2an3pcxmcr2zhs6v324n45xuvym543lz5qkjoa7tfs2o3fyii", | |
// addresses: ["/ip4/127.0.0.1/tcp/4006/p2p/12D3KooWGWzytUr7X9GfoBbGwPdDmeT42MFGaoP8wNxmWMMiyb6H/thread/bafksufublxb7pd63roskj574xcyyxzet3m3juxwysjrjnla4ddh3wei", "/ip4/192.168.43.151/tcp/4006/p2p/12D3KooWGWzytUr7X9GfoBbGwPdDmeT42MFGaoP8wNxmWMMiyb6H/thread/bafksufublxb7pd63roskj574xcyyxzet3m3juxwysjrjnla4ddh3wei", "/ip4/157.33.234.252/tcp/4006/p2p/12D3KooWGWzytUr7X9GfoBbGwPdDmeT42MFGaoP8wNxmWMMiyb6H/thread/bafksufublxb7pd63roskj574xcyyxzet3m3juxwysjrjnla4ddh3wei", "/ip4/157.33.198.184/tcp/4006/p2p/12D3KooWGWzytUr7X9GfoBbGwPdDmeT42MFGaoP8wNxmWMMiyb6H/thread/bafksufublxb7pd63roskj574xcyyxzet3m3juxwysjrjnla4ddh3wei",] | |
// } | |
// }); | |
// console.log("result", res); | |
// uploading files | |
console.log("uploading file") | |
const stream = await client.addItems({ | |
bucket: bucket, targetPath: "", // path in the bucket to be saved | |
sourcePaths: ["G:/Node-Down-Time-App/Nodes.csv"] | |
}); | |
// events to capture the file uploading journey | |
await stream.on("data", (data) => { | |
console.log("data: ", data); | |
}); | |
await stream.on("error", (error) => { | |
console.error("error: ", error); | |
}); | |
await stream.on("end", () => { | |
console.log("end"); | |
}); | |
const res = await client.shareFilesViaPublicKey({ | |
publicKeys: ['0x2DdA8dc2f67f1eB94b250CaEFAc9De16f70c5A51'], | |
paths: [{ | |
path: '', | |
dbId: '', | |
bucket: bucket, | |
}], | |
}); | |
console.log(res); | |
const list = await client.getNotifications({ seek: '', limit: 20 }); | |
console.log(list); | |
} catch (error) { | |
console.error(error); | |
}})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment