From ab66b6ff5b0ce5e51f310efeb99bb1048fd63f48 Mon Sep 17 00:00:00 2001 From: Marcin S Date: Mon, 7 Sep 2020 17:32:25 +0200 Subject: [PATCH 1/2] Update code samples for API v2 --- .../src/components/CodeExamples/Code.js | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/packages/webapp/src/components/CodeExamples/Code.js b/packages/webapp/src/components/CodeExamples/Code.js index 33018c4a..d491a357 100644 --- a/packages/webapp/src/components/CodeExamples/Code.js +++ b/packages/webapp/src/components/CodeExamples/Code.js @@ -1,11 +1,14 @@ -export const python = `import siaskynet +export const python = `import siaskynet as skynet + +# create a client +client = skynet.SkynetClient() # upload -skylink = siaskynet.upload_file("./src.jpg") +skylink = client.upload_file("./src.jpg") print("Upload successful, skylink: " + skylink) # download -siaskynet.download_file("./dst.jpg", skylink) +client.download_file("./dst.jpg", skylink) print("Download successful")`; export const curl = `# upload @@ -14,22 +17,18 @@ curl -X POST "https://siasky.net/skynet/skyfile" -F file=@src.jpg # download curl "https://siasky.net/[skylink]" -o dst.jpg`; -export const node = `const skynet = require('@nebulous/skynet'); +export const node = `const { SkynetClient } = require('@nebulous/skynet'); + +// create a client +const client = new SkynetClient(); (async () => { // upload - const skylink = await skynet.UploadFile( - "./src.jpg", - skynet.DefaultUploadOptions - ); + const skylink = await client.UploadFile("./src.jpg"); console.log(\`Upload successful, skylink: \${skylink}\`); - + // download - await skynet.DownloadFile( - "./dst.jpg", - skylink, - skynet.DefaultDownloadOptions - ); + await client.DownloadFile("./dst.jpg", skylink); console.log('Download successful'); })()`; @@ -39,21 +38,21 @@ import ( "fmt" skynet "github.com/NebulousLabs/go-skynet" ) - + +var client = skynet.New() + func main() { // upload - skylink, err := skynet.UploadFile("./src.jpg", skynet.DefaultUploadOptions) + skylink, err := client.UploadFile("./src.jpg", skynet.DefaultUploadOptions) if err != nil { - fmt.Printf("Unable to upload: %v", err.Error()) - return + panic("Unable to upload: %v", err.Error()) } fmt.Printf("Upload successful, skylink: %v\\n", skylink) // download - err = skynet.DownloadFile("./dst.jpg", skylink, skynet.DefaultDownloadOptions) + err = client.DownloadFile("./dst.jpg", skylink, skynet.DefaultDownloadOptions) if err != nil { - fmt.Printf("Something went wrong, please try again.\\nError: %v", err.Error()) - return + panic("Something went wrong, please try again.\\nError: %v", err.Error()) } fmt.Println("Download successful") }`; From 072b6264759bd40518d92bebe942fe6c9281aa98 Mon Sep 17 00:00:00 2001 From: Marcin S Date: Tue, 8 Sep 2020 16:53:05 +0200 Subject: [PATCH 2/2] Fix syntax error in panic calls --- packages/webapp/src/components/CodeExamples/Code.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/webapp/src/components/CodeExamples/Code.js b/packages/webapp/src/components/CodeExamples/Code.js index d491a357..695a4634 100644 --- a/packages/webapp/src/components/CodeExamples/Code.js +++ b/packages/webapp/src/components/CodeExamples/Code.js @@ -45,14 +45,14 @@ func main() { // upload skylink, err := client.UploadFile("./src.jpg", skynet.DefaultUploadOptions) if err != nil { - panic("Unable to upload: %v", err.Error()) + panic("Unable to upload: " + err.Error()) } fmt.Printf("Upload successful, skylink: %v\\n", skylink) // download err = client.DownloadFile("./dst.jpg", skylink, skynet.DefaultDownloadOptions) if err != nil { - panic("Something went wrong, please try again.\\nError: %v", err.Error()) + panic("Something went wrong, please try again.\\nError: " + err.Error()) } fmt.Println("Download successful") }`;