From 2247e2d53397ace0b55852aa9e2e53bf3c635962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Wypch=C5=82o?= Date: Tue, 18 Feb 2020 14:39:04 +0100 Subject: [PATCH] Snippets (#28) * Revert "add download snippets" This reverts commit 664eea21f5819a545f5d92a54828821e76728784. * snippets changes proposal * reformat white spaces * Fix snippets Co-authored-by: Peter-Jan Brone --- .../src/components/CodeExamples/Code.js | 63 +++++++++++++++++++ .../components/CodeExamples/CodeExamples.js | 10 +-- .../CodeExamples/snippets/download.js | 32 ---------- .../components/CodeExamples/snippets/index.js | 4 -- .../CodeExamples/snippets/upload.js | 37 ----------- .../src/components/HomeBuilt/HomeBuilt.js | 10 +-- .../src/components/HomeBuilt/HomeBuilt.scss | 20 ------ 7 files changed, 66 insertions(+), 110 deletions(-) create mode 100644 packages/sia-skynet/src/components/CodeExamples/Code.js delete mode 100644 packages/sia-skynet/src/components/CodeExamples/snippets/download.js delete mode 100644 packages/sia-skynet/src/components/CodeExamples/snippets/index.js delete mode 100644 packages/sia-skynet/src/components/CodeExamples/snippets/upload.js 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;