diff --git a/packages/sia-skynet/src/components/CodeExamples/Code.js b/packages/sia-skynet/src/components/CodeExamples/Code.js new file mode 100644 index 00000000..7c5119df --- /dev/null +++ b/packages/sia-skynet/src/components/CodeExamples/Code.js @@ -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 = `` diff --git a/packages/sia-skynet/src/components/CodeExamples/CodeExamples.js b/packages/sia-skynet/src/components/CodeExamples/CodeExamples.js index dd8eb437..8c993d9f 100644 --- a/packages/sia-skynet/src/components/CodeExamples/CodeExamples.js +++ b/packages/sia-skynet/src/components/CodeExamples/CodeExamples.js @@ -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 (
@@ -56,7 +54,3 @@ export default function CodeExamples({ type }) {
) } - -CodeExamples.propTypes = { - type: PropTypes.oneOf(['download', 'upload']).isRequired -}; diff --git a/packages/sia-skynet/src/components/CodeExamples/snippets/download.js b/packages/sia-skynet/src/components/CodeExamples/snippets/download.js deleted file mode 100644 index cfdca167..00000000 --- a/packages/sia-skynet/src/components/CodeExamples/snippets/download.js +++ /dev/null @@ -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 = `` diff --git a/packages/sia-skynet/src/components/CodeExamples/snippets/index.js b/packages/sia-skynet/src/components/CodeExamples/snippets/index.js deleted file mode 100644 index 71a25cc6..00000000 --- a/packages/sia-skynet/src/components/CodeExamples/snippets/index.js +++ /dev/null @@ -1,4 +0,0 @@ -import * as download from './download'; -import * as upload from './upload'; - -export default { download, upload }; \ No newline at end of file diff --git a/packages/sia-skynet/src/components/CodeExamples/snippets/upload.js b/packages/sia-skynet/src/components/CodeExamples/snippets/upload.js deleted file mode 100644 index cd548b30..00000000 --- a/packages/sia-skynet/src/components/CodeExamples/snippets/upload.js +++ /dev/null @@ -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 = `` diff --git a/packages/sia-skynet/src/components/HomeBuilt/HomeBuilt.js b/packages/sia-skynet/src/components/HomeBuilt/HomeBuilt.js index 5f3fcac0..4bec746f 100644 --- a/packages/sia-skynet/src/components/HomeBuilt/HomeBuilt.js +++ b/packages/sia-skynet/src/components/HomeBuilt/HomeBuilt.js @@ -32,15 +32,7 @@ export default function HomeBuilt() { -
-

Uploading

- -
- -
-

Downloading

- -
+
); diff --git a/packages/sia-skynet/src/components/HomeBuilt/HomeBuilt.scss b/packages/sia-skynet/src/components/HomeBuilt/HomeBuilt.scss index 4df6c838..fe5b7733 100644 --- a/packages/sia-skynet/src/components/HomeBuilt/HomeBuilt.scss +++ b/packages/sia-skynet/src/components/HomeBuilt/HomeBuilt.scss @@ -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;