Snippets (#28)
* Revert "add download snippets"
This reverts commit 664eea21f5
.
* snippets changes proposal
* reformat white spaces
* Fix snippets
Co-authored-by: Peter-Jan Brone <peter-jan@settlemint.com>
This commit is contained in:
parent
1577c7bd47
commit
2247e2d533
|
@ -0,0 +1,63 @@
|
|||
export const python = `from siaskynet import Skynet
|
||||
|
||||
# upload
|
||||
skylink = Skynet.UploadFile("./src.jpg")
|
||||
print("Upload successful, skylink: " + skylink)
|
||||
|
||||
# download
|
||||
Skynet.DownloadFile("./dst.jpg", skylink)
|
||||
print("Download successful")`
|
||||
|
||||
export const curl = `# upload
|
||||
curl -X POST "https://siasky.net/skynet/skyfile/[uuid]" -F file=@src.jpg
|
||||
|
||||
# download
|
||||
curl "https://siasky.net/[skylink]" -o dst.jpg`
|
||||
|
||||
export const node = `const skynet = require('@nebulous/skynet');
|
||||
|
||||
(async () => {
|
||||
// upload
|
||||
const skylink = await skynet.UploadFile(
|
||||
"./src.jpg",
|
||||
skynet.DefaultUploadOptions
|
||||
);
|
||||
console.log(\`Upload successful, skylink: \${skylink}\`);
|
||||
|
||||
// download
|
||||
await skynet.DownloadFile(
|
||||
"./dst.jpg",
|
||||
skylink,
|
||||
skynet.DefaultDownloadOptions
|
||||
);
|
||||
console.log('Download successful');
|
||||
})()`
|
||||
|
||||
export const go = `package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
skynet "github.com/NebulousLabs/go-skynet"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// upload
|
||||
skylink, err := skynet.UploadFile("./src.jpg", skynet.DefaultUploadOptions)
|
||||
if err != nil {
|
||||
fmt.Printf("Unable to upload: %v", err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Printf("Upload successful, skylink: %v\\n", skylink)
|
||||
|
||||
// download
|
||||
err = skynet.DownloadFile("./dst.jpg", skylink, skynet.DefaultDownloadOptions)
|
||||
if err != nil {
|
||||
fmt.Printf("Something went wrong, please try again.\\nError: %v", err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Println("Download successful")
|
||||
}`
|
||||
|
||||
export const ruby = ``
|
||||
|
||||
export const php = ``
|
|
@ -1,15 +1,13 @@
|
|||
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 snippets from './snippets'
|
||||
import { python, curl, node, go } from './Code'
|
||||
|
||||
export default function CodeExamples({ type }) {
|
||||
export default function CodeExamples() {
|
||||
const [active, setActive] = useState(1)
|
||||
const { python, curl, node, go } = snippets[type];
|
||||
|
||||
return (
|
||||
<div className="code-examples">
|
||||
|
@ -56,7 +54,3 @@ export default function CodeExamples({ type }) {
|
|||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
CodeExamples.propTypes = {
|
||||
type: PropTypes.oneOf(['download', 'upload']).isRequired
|
||||
};
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
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", err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Println("Download successful")
|
||||
}`
|
||||
|
||||
export const ruby = ``
|
||||
|
||||
export const php = ``
|
|
@ -1,4 +0,0 @@
|
|||
import * as download from './download';
|
||||
import * as upload from './upload';
|
||||
|
||||
export default { download, upload };
|
|
@ -1,37 +0,0 @@
|
|||
export const python = `from siaskynet import Skynet
|
||||
path = "./image.jpg"
|
||||
skylink = Skynet.UploadFile(path)
|
||||
print("Upload successful, skylink: " + skylink)`
|
||||
|
||||
export const curl = `curl -X POST "https://siasky.net/api/skyfile/[uuid]" -F file=@image.jpg`
|
||||
|
||||
export const node = `const skynet = require('@nebulous/skynet');
|
||||
|
||||
(async () => {
|
||||
const path = "./image.jpg";
|
||||
const skylink = await skynet.UploadFile(
|
||||
path,
|
||||
skynet.DefaultUploadOptions
|
||||
);
|
||||
console.log(\`Upload successful, skylink: \${skylink}\`);
|
||||
})()`
|
||||
|
||||
export const go = `package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
skynet "github.com/NebulousLabs/go-skynet"
|
||||
)
|
||||
|
||||
func main() {
|
||||
skylink, err := skynet.UploadFile("./image.jpg", skynet.DefaultUploadOptions)
|
||||
if err != nil {
|
||||
fmt.Printf("Unable to upload: %v", err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Printf("Upload successful, skylink: %v", skylink)
|
||||
}`
|
||||
|
||||
export const ruby = ``
|
||||
|
||||
export const php = ``
|
|
@ -32,15 +32,7 @@ export default function HomeBuilt() {
|
|||
</header>
|
||||
|
||||
<Fade duration={700} distance="40px" bottom>
|
||||
<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>
|
||||
<CodeExamples />
|
||||
</Fade>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -8,26 +8,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
.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;
|
||||
|
||||
|
|
Reference in New Issue