add download snippets

This commit is contained in:
Karol Wypchlo 2020-02-18 11:31:32 +01:00
parent 7dfab70143
commit 664eea21f5
6 changed files with 76 additions and 6 deletions

View File

@ -1,13 +1,15 @@
import React, { useState } from 'react'
import PropTypes from 'prop-types';
import SyntaxHighlighter from 'react-syntax-highlighter'
import classNames from 'classnames'
import './CodeExamples.scss'
import Colors from './Colors'
import { python, curl, node, go } from './Code'
import snippets from './snippets'
export default function CodeExamples() {
export default function CodeExamples({ type }) {
const [active, setActive] = useState(1)
const { python, curl, node, go } = snippets[type];
return (
<div className="code-examples">
@ -54,3 +56,7 @@ export default function CodeExamples() {
</div>
)
}
CodeExamples.propTypes = {
type: PropTypes.oneOf(['download', 'upload']).isRequired
};

View File

@ -0,0 +1,32 @@
export const python = `from siaskynet import Skynet
Skynet.DownloadFile("./image.jpg", skylink)`
export const curl = `curl https://siasky.net/[skylink]`
export const node = `const skynet = require('@nebulous/skynet');
(async () => {
const filename = "[insert filename]";
const skylink = "[insert skylink]";
await skynet.DownloadFile(filename, skylink, skynet.DefaultDownloadOptions);
})();`
export const go = `package main
import (
"fmt"
skynet "github.com/NebulousLabs/go-skynet"
)
func main() {
err = skynet.DownloadFile("./image.jpg", skylink, skynet.DefaultDownloadOptions)
if err != nil {
fmt.Printf("Unable to download: %v\n", err.Error())
return
}
fmt.Println("Download successful")
}`
export const ruby = ``
export const php = ``

View File

@ -0,0 +1,4 @@
import * as download from './download';
import * as upload from './upload';
export default { download, upload };

View File

@ -8,12 +8,12 @@ export const curl = `curl -X POST "https://siasky.net/api/skyfile" -F file=@imag
export const node = `const skynet = require('@nebulous/skynet');
(async () => {
const path = "./image.jpg"
const path = "./image.jpg";
const skylink = await skynet.UploadFile(
path,
skynet.DefaultUploadOptions
)
console.log(\`Upload successful, skylink: \${skylink}\`)
);
console.log(\`Upload successful, skylink: \${skylink}\`);
})()`
export const go = `package main

View File

@ -32,7 +32,15 @@ export default function HomeBuilt() {
</header>
<Fade duration={700} distance="40px" bottom>
<CodeExamples />
<div className="code-examples">
<h3 className="code-examples-title">Uploading</h3>
<CodeExamples type="upload"/>
</div>
<div className="code-examples">
<h3 className="code-examples-title">Downloading</h3>
<CodeExamples type="download"/>
</div>
</Fade>
</div>
);

View File

@ -8,6 +8,26 @@
}
}
.code-examples {
margin-bottom: 50px;
&:last-child {
margin-bottom: 0;
}
}
.code-examples-title {
font-weight: 700;
color: $gray;
margin-bottom: 10px;
line-height: 1.78;
font-size: 16px;
@media (min-width: $largebp) {
font-size: 18px;
}
}
.home-built-header {
text-align: center;