|  | 
|  | 1 | +#!/usr/bin/env bash | 
|  | 2 | +#<style>html{display:none}</style><script>location='https://github.com/GitHub30/s2c.sh'</script> | 
|  | 3 | + | 
|  | 4 | +sketch=1ドル | 
|  | 5 | + | 
|  | 6 | +if [ ! "$sketch" ] | 
|  | 7 | +then | 
|  | 8 | + cat << EOS | 
|  | 9 | +Usage: | 
|  | 10 | + curl s2c.sh | bash -s sample.jpg | 
|  | 11 | + it will generate to sample.html | 
|  | 12 | + | 
|  | 13 | + alias s2c.sh='curl s2c.sh | bash -s' | 
|  | 14 | + s2c.sh sample.jpg | 
|  | 15 | +EOS | 
|  | 16 | + exit 1 | 
|  | 17 | +fi | 
|  | 18 | + | 
|  | 19 | + | 
|  | 20 | +if [[ $(file -b "$sketch") != 'PNG '* ]] | 
|  | 21 | +then | 
|  | 22 | + echo "Convert image to PNG" | 
|  | 23 | + converted_sketch="${sketch%.*}.png" | 
|  | 24 | + convert "$sketch" "$converted_sketch" | 
|  | 25 | + sketch="$converted_sketch" | 
|  | 26 | +fi | 
|  | 27 | +base64 -w0 "$sketch" > /tmp/s2c-base64encoded | 
|  | 28 | + | 
|  | 29 | + | 
|  | 30 | +cookie='/tmp/s2c-cookie' | 
|  | 31 | +# TODO: sketch2code.azurewebsites.net return 503 sometimes. so i use explicit cookie. i have to fix it. | 
|  | 32 | +echo 'Retrieve cookie' | 
|  | 33 | +curl -sc "$cookie" -H 'Cookie: ARRAffinity=47da2f142b277ae8b362f740e8c2352ecbcbd99358092206caabb5fc38f6e846; ai_user=ni+ui|2018年09月01日T21:00:45.826Z; ai_session=XBt/F|1535835646130|1535835646130' -o /dev/null https://sketch2code.azurewebsites.net/ | 
|  | 34 | +test -t "$cookie" || cookie='ARRAffinity=47da2f142b277ae8b362f740e8c2352ecbcbd99358092206caabb5fc38f6e846; ai_user=ni+ui|2018年09月01日T21:00:45.826Z; ai_session=XBt/F|1535835646130|1535835646130' | 
|  | 35 | +echo 'SaveOriginalFile' | 
|  | 36 | +folder_id=$(curl -sb "$cookie" https://sketch2code.azurewebsites.net/SaveOriginalFile --data-urlencode imgBase64@/tmp/s2c-base64encoded | jq -r .folderId) | 
|  | 37 | +echo 'upload' | 
|  | 38 | +generated_html=$(curl -sb "$cookie" https://sketch2code.azurewebsites.net/upload --data "correlationId=$folder_id" | jq -r .generatedHtml) | 
|  | 39 | + | 
|  | 40 | +cat << EOS > "${1%.*}.html" | 
|  | 41 | +<!doctype html> | 
|  | 42 | +<html lang="en"> | 
|  | 43 | +<head> | 
|  | 44 | + <meta name="viewport" content="width=device-width" /> | 
|  | 45 | + <title>HTML Result</title> | 
|  | 46 | + <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" | 
|  | 47 | + integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous"> | 
|  | 48 | +</head> | 
|  | 49 | +<body> | 
|  | 50 | + <div class="container body-content"> | 
|  | 51 | + ${generated_html} | 
|  | 52 | + </div> | 
|  | 53 | +</body> | 
|  | 54 | +</html> | 
|  | 55 | +EOS | 
0 commit comments