Add Browser JS to SDK examples

Closes #406
This commit is contained in:
Marcin S 2020-09-22 16:46:24 +02:00
parent f3b2a130fe
commit d2f40d3592
No known key found for this signature in database
GPG Key ID: 68A476F4791BB6B3
3 changed files with 42 additions and 15 deletions

View File

@ -17,7 +17,7 @@ List of available parameters:
## Contributing
### Testing you Code
### Testing Your Code
Before pushing your code you should verify that it will pass our online test
suite.

View File

@ -1,3 +1,30 @@
export const curl = `# upload
curl -X POST "https://siasky.net/skynet/skyfile" -F file=@src.jpg
# download
curl "https://siasky.net/[skylink]" -o dst.jpg`;
export const browserjs = `import { SkynetClient } from "skynet-js";
// create a client
const client = new SkynetClient();
// Assume we have a file from an input form.
async function example() {
try {
// upload
const { skylink } = await client.uploadFile(file);
console.log(\`Upload successful, skylink: \${skylink}\`);
// download
await client.downloadFile(skylink);
console.log('Download successful');
} catch (error) {
console.log(error)
}
}`;
export const python = `import siaskynet as skynet
# create a client
@ -11,12 +38,6 @@ print("Upload successful, skylink: " + skylink)
client.download_file("./dst.jpg", skylink)
print("Download successful")`;
export const curl = `# upload
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 { SkynetClient } = require('@nebulous/skynet');
// create a client
@ -39,6 +60,7 @@ import (
skynet "github.com/NebulousLabs/go-skynet"
)
// create a client
var client = skynet.New()
func main() {
@ -56,7 +78,3 @@ func main() {
}
fmt.Println("Download successful")
}`;
export const ruby = ``;
export const php = ``;

View File

@ -25,12 +25,15 @@ export default function CodeExamples() {
CURL
</button>
<button type="button" onClick={() => setActive(2)} className={classNames({ active: active === 2 })}>
Python
BrowserJS
</button>
<button type="button" onClick={() => setActive(3)} className={classNames({ active: active === 3 })}>
Node.js
Python
</button>
<button type="button" onClick={() => setActive(4)} className={classNames({ active: active === 4 })}>
Node.js
</button>
<button type="button" onClick={() => setActive(5)} className={classNames({ active: active === 5 })}>
Go
</button>
</div>
@ -43,18 +46,24 @@ export default function CodeExamples() {
)}
{active === 2 && (
<SyntaxHighlighter wrapLines showLineNumbers={true} language="javascript" style={Colors}>
{interpolateSnippet(snippets.browserjs)}
</SyntaxHighlighter>
)}
{active === 3 && (
<SyntaxHighlighter wrapLines showLineNumbers={true} language="python" style={Colors}>
{interpolateSnippet(snippets.python)}
</SyntaxHighlighter>
)}
{active === 3 && (
{active === 4 && (
<SyntaxHighlighter wrapLines showLineNumbers={true} language="javascript" style={Colors}>
{interpolateSnippet(snippets.node)}
</SyntaxHighlighter>
)}
{active === 4 && (
{active === 5 && (
<SyntaxHighlighter wrapLines showLineNumbers={true} language="go" style={Colors}>
{interpolateSnippet(snippets.go)}
</SyntaxHighlighter>