2018-03-23 12:53:54 +01:00
< template >
2018-05-11 21:49:04 +02:00
< section class = "hook__page" id = "step2-page" >
2018-05-10 10:25:47 +02:00
< div v -images -loaded = " imagesLoaded " >
2018-05-11 21:49:04 +02:00
< header class = "hook__page__hero" >
< div class = "inner-wrap" >
< h1 > Publish your content on the blockchain < / h1 >
< p > Upload an image to the blockchain and you are able to view it on the < a href = "http://explorer.lbry.io" title = "LBRY Blockchain Explorer" target = "_blank" > LBRY Blockchain Explorer < / a > . < / p >
< / div >
< / header >
2018-05-12 00:22:08 +02:00
< aside class = "hook__page__content" >
< div class = "inner-wrap" >
2018-06-08 13:16:24 +02:00
< template v-if = "!isLoading" >
< div class = "hook__page__content__meme left" >
< img v -bind :src = "backgroundImage" id = "base-image" alt = "" / >
< canvas id = "meme-canvas" width = "400" height = "300" > Sorry , canvas not supported < / canvas >
< img v-for = "image in images" v-bind:src="image.src" v-on:click="chooseImage(image.src)" class="thumbnail" v-bind:class="{'selected': backgroundImage == image.src}" v-bind:alt="image.alt" >
< / div >
< form class = "hook__page__content__meme right" v -on :submit.prevent = "submit" >
< h2 > Image Text < / h2 >
< fieldset >
< label for = "meme-top-line" > Top line < / label >
< input name = "meme-top-line" id = "meme-top-line" type = "text" v-model = "topLine" placeholder="Top line" required / >
< / fieldset >
< fieldset >
< label for = "meme-bottom-line" > Bottom line < / label >
< input name = "meme-bottom-line" id = "meme-bottom-line" type = "text" v-model = "bottomLine" placeholder="Bottom line" required / >
< / fieldset >
< h2 class = "metadata" > Metadata < / h2 >
< fieldset >
< label for = "meme-title" > Title < / label >
< input name = "meme-title" id = "meme-title" type = "text" v-model = "title" placeholder="Title" required / >
< / fieldset >
< fieldset >
< label for = "meme-description" > Description < / label >
< textarea name = "meme-description" id = "meme-description" type = "text" v-model = "description" placeholder="Description" required > { { description } } < / textarea >
< / fieldset >
< fieldset >
< label for = "meme-language" > Language < / label >
< select name = "meme-language" id = "meme-language" v-model = "language" >
< option value = "EN" > English < / option >
< option value = "FR" > French < / option >
< option value = "ES" > Spanish < / option >
< option value = "DE" > German < / option >
< option value = "IT" > Italian < / option >
< option value = "ZH" > Chinese ( Mandarin ) < / option >
< option value = "AR" > Arabic < / option >
< option value = "RU" > Russian < / option >
< option value = "JP" > Japanese < / option >
< option value = "" > Not specified < / option >
< / select >
< / fieldset >
< fieldset >
< label for = "meme-license" > License < / label >
< select name = "meme-license" id = "meme-license" v-model = "license" required >
< option value = "Public Domain" > Public Domain < / option >
< option value = "Creative Commons Attribution 4.0 International" > Creative Commons Attribution 4.0 International < / option >
< option value = "Creative Commons Attribution-ShareAlike 4.0 International" > Creative Commons Attribution - ShareAlike 4.0 International < / option >
< option value = "Creative Commons Attribution-NoDerivatives 4.0 International" > Creative Commons Attribution - NoDerivatives 4.0 International < / option >
< option value = "Creative Commons Attribution-NonCommercial 4.0 International" > Creative Commons Attribution - NonCommercial 4.0 International < / option >
< option value = "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International" > Creative Commons Attribution - NonCommercial - ShareAlike 4.0 International < / option >
< option value = "Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International" > Creative Commons Attribution - NonCommercial - NoDerivatives 4.0 International < / option >
< option value = "None" > None < / option >
< / select >
< / fieldset >
< fieldset >
< label > < input type = "checkbox" v-model = "nsfw" name = "nsfw" / > NSFW < / label >
< / fieldset >
< fieldset >
< input type = "submit" class = "__button-black" value = "Submit" / >
< / fieldset >
< / form >
< / template >
2018-05-11 21:49:04 +02:00
2018-06-08 13:45:56 +02:00
< div class = "xs12" v-if = "exampleCode != ''" >
< pre > < code class = "bash" > < span v-html = "highlight('bash',exampleCode)" > < / span > < / code > < / pre >
< / div >
2018-05-12 00:22:08 +02:00
< div class = "xs12" v-if = "isLoading" >
< div class = "loader" > < / div >
< / div >
2018-06-08 13:45:56 +02:00
< div class = "xs12" v-if = "jsonData" >
< p > Success ! Here is the response : < / p >
< pre > < code class = "json" > < span v-html = "highlight('json',jsonData)" > < / span > < / code > < / pre >
< / div >
2018-05-12 00:22:08 +02:00
< / div >
< / aside >
2018-05-10 10:25:47 +02:00
< / div >
2018-05-11 21:49:04 +02:00
< / section >
2018-03-23 12:53:54 +01:00
< / template >
< script >
import imagesLoaded from 'vue-images-loaded'
2018-06-08 13:45:56 +02:00
import hljs from 'highlight.js'
2018-03-23 12:53:54 +01:00
2018-04-20 15:17:16 +02:00
import EventBus from '../event-bus' ;
2018-03-23 12:53:54 +01:00
export default {
directives : {
imagesLoaded
} ,
2018-05-18 11:55:50 +02:00
2018-03-23 12:53:54 +01:00
data ( ) {
2018-05-18 11:55:50 +02:00
var images = [
{
2018-06-08 11:56:28 +02:00
src : './carlsagan2.jpg' ,
2018-05-18 11:55:50 +02:00
alt : 'Carl Sagan'
} ,
{
2018-06-08 11:56:28 +02:00
src : './doge-meme.jpg' ,
2018-05-18 11:55:50 +02:00
alt : 'Doge'
} ,
{
2018-06-08 11:56:28 +02:00
src : 'lbry-green.png' ,
2018-05-18 11:55:50 +02:00
alt : 'LBRY Logo With Green Background'
}
] ;
2018-03-23 12:53:54 +01:00
return {
valid : false ,
isLoading : false ,
2018-06-08 13:45:56 +02:00
exampleCode : '' ,
jsonData : '' ,
2018-06-08 13:16:24 +02:00
loadingMessage : '' ,
2018-03-23 12:53:54 +01:00
topLine : 'This is an example meme' ,
bottomLine : 'that I made' ,
title : '' ,
2018-05-18 11:55:50 +02:00
description : 'Check out this image I published to LBRY via lbry.tech' ,
2018-03-23 12:53:54 +01:00
language : 'EN' ,
license : 'Public Domain' ,
nsfw : false ,
2018-05-18 11:55:50 +02:00
images : images ,
backgroundImage : images [ 0 ] . src ,
2018-03-23 12:53:54 +01:00
textFieldRules : [
v => ! ! v || 'Field is required'
] ,
}
} ,
2018-06-08 13:45:56 +02:00
mounted ( ) {
hljs . configure ( {
languages : [ 'bash' , 'json' ]
} ) ;
} ,
2018-03-23 12:53:54 +01:00
methods : {
updateCanvas ( ) {
var canvasWidth = 400 ;
var canvasHeight = 300 ;
var canvas = document . getElementById ( 'meme-canvas' ) ;
var ctx = canvas . getContext ( '2d' ) ;
var img = document . getElementById ( 'base-image' ) ;
ctx . clearRect ( 0 , 0 , canvasWidth , canvasHeight ) ;
ctx . drawImage ( img , 0 , 0 , canvasWidth , canvasHeight , 0 , 0 , canvasWidth , canvasHeight ) ;
ctx . lineWidth = 4 ;
2018-05-18 11:55:50 +02:00
ctx . font = 'bold 28px Karla' ;
2018-03-23 12:53:54 +01:00
ctx . strokeStyle = 'black' ;
ctx . fillStyle = 'white' ;
ctx . textAlign = 'center' ;
ctx . textBaseline = 'top' ;
2018-05-18 11:55:50 +02:00
ctx . lineJoin = 'round' ;
2018-03-23 12:53:54 +01:00
ctx . strokeText ( this . topLine . toUpperCase ( ) , canvasWidth / 2 , 20 ) ;
ctx . fillText ( this . topLine . toUpperCase ( ) , canvasWidth / 2 , 20 ) ;
ctx . strokeText ( this . bottomLine . toUpperCase ( ) , canvasWidth / 2 , ( canvasHeight - 40 ) ) ;
ctx . fillText ( this . bottomLine . toUpperCase ( ) , canvasWidth / 2 , ( canvasHeight - 40 ) ) ;
} ,
submit ( ) {
2018-06-08 11:12:49 +02:00
var component = this ;
component . isLoading = true ;
2018-06-08 13:45:56 +02:00
component . exampleCode = '# Example code using the daemon\ncurl \'http://localhost:5279\' --data \'{"method":"publish","params":{"name":"' + component . title + '","bid":0.001, "file_path":"/path/to/your/file.jpg","title":"' + component . title + '", "description":"' + component . description + '","language":"' + component . language + '","license":"' + component . license + '","nsfw":' + component . nsfw + '}}\'' ;
component . $http . post ( 'https://lbry.tech/upload-image' , document . getElementById ( 'meme-canvas' ) . toDataURL ( 'image/jpeg' , 0.6 ) , {
2018-06-08 13:16:24 +02:00
headers : {
'Content-Type' : 'text/plain'
}
} ) . then ( function ( response ) {
2018-06-08 13:45:56 +02:00
if ( response . status == 'error' ) {
component . isLoading = false ;
component . exampleCode = '' ;
} else {
2018-06-15 07:39:11 +02:00
component . $http . post ( 'https://lbry.tech/forward' , {
method : 'publish' ,
name : component . title ,
bid : 0.001 ,
file _path : response . filename ,
title : component . title ,
description : component . description ,
language : component . language ,
license : component . license ,
nsfw : component . nsfw
} ) . then ( function ( response ) {
2018-06-08 13:45:56 +02:00
component . isLoading = false ;
component . jsonData = JSON . stringify ( response . body , null , ' ' ) ;
EventBus . $emit ( 'HookFileUploaded' , response . body . txid ) ;
} ) ;
}
2018-06-08 11:12:49 +02:00
} ) ;
2018-03-23 12:53:54 +01:00
} ,
imagesLoaded ( instance ) {
var component = this ;
// Make sure the font is loaded
2018-05-18 11:55:50 +02:00
document . fonts . load ( 'bold 28px Karla' ) . then ( function ( ) {
2018-03-23 12:53:54 +01:00
component . updateCanvas ( ) ;
} ) ;
} ,
2018-05-18 11:55:50 +02:00
chooseImage ( src ) {
var component = this ;
component . backgroundImage = src ;
component . updateCanvas ( ) ;
} ,
2018-03-23 12:53:54 +01:00
setImage ( file ) {
var component = this ;
document . getElementById ( 'base-image' ) . src = file ;
// allow one second to load the image
setTimeout ( component . updateCanvas , 1000 ) ;
2018-06-08 13:45:56 +02:00
} ,
highlight ( language , text ) {
return hljs . highlight ( language , text ) . value ;
2018-03-23 12:53:54 +01:00
}
} ,
created ( ) {
} ,
watch : {
topLine ( ) {
this . updateCanvas ( ) ;
} ,
bottomLine ( ) {
this . updateCanvas ( ) ;
}
} ,
name : 'Step2'
2018-05-10 10:25:47 +02:00
} ;
2018-03-23 12:53:54 +01:00
< / script >