UI for image upload
This commit is contained in:
parent
3edc4c3965
commit
522dc24cd9
2 changed files with 44 additions and 6 deletions
|
@ -89,10 +89,19 @@
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<div class="xs12" v-if="exampleCode != ''">
|
||||||
|
<pre><code class="bash"><span v-html="highlight('bash',exampleCode)"></span></code></pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="xs12" v-if="isLoading">
|
<div class="xs12" v-if="isLoading">
|
||||||
<div class="loader"></div>
|
<div class="loader"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
</div>
|
</div>
|
||||||
|
@ -102,6 +111,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import imagesLoaded from 'vue-images-loaded'
|
import imagesLoaded from 'vue-images-loaded'
|
||||||
|
import hljs from 'highlight.js'
|
||||||
|
|
||||||
import EventBus from '../event-bus';
|
import EventBus from '../event-bus';
|
||||||
|
|
||||||
|
@ -128,12 +138,13 @@ export default {
|
||||||
return {
|
return {
|
||||||
valid: false,
|
valid: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
exampleCode: '',
|
||||||
|
jsonData: '',
|
||||||
loadingMessage: '',
|
loadingMessage: '',
|
||||||
topLine: 'This is an example meme',
|
topLine: 'This is an example meme',
|
||||||
bottomLine: 'that I made',
|
bottomLine: 'that I made',
|
||||||
title: '',
|
title: '',
|
||||||
description: 'Check out this image I published to LBRY via lbry.tech',
|
description: 'Check out this image I published to LBRY via lbry.tech',
|
||||||
author: '',
|
|
||||||
language: 'EN',
|
language: 'EN',
|
||||||
license: 'Public Domain',
|
license: 'Public Domain',
|
||||||
nsfw: false,
|
nsfw: false,
|
||||||
|
@ -144,6 +155,13 @@ export default {
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
mounted () {
|
||||||
|
|
||||||
|
hljs.configure({
|
||||||
|
languages: ['bash', 'json']
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
updateCanvas () {
|
updateCanvas () {
|
||||||
var canvasWidth = 400;
|
var canvasWidth = 400;
|
||||||
|
@ -174,17 +192,24 @@ export default {
|
||||||
submit () {
|
submit () {
|
||||||
var component = this;
|
var component = this;
|
||||||
component.isLoading = true;
|
component.isLoading = true;
|
||||||
component.$http.post('/upload-image', document.getElementById('meme-canvas').toDataURL('image/jpeg', 0.6), {
|
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), {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'text/plain'
|
'Content-Type': 'text/plain'
|
||||||
}
|
}
|
||||||
}).then(function(response) {
|
}).then(function(response) {
|
||||||
component.isLoading = false;
|
if(response.status == 'error') {
|
||||||
console.log(response);
|
component.isLoading = false;
|
||||||
|
component.exampleCode = '';
|
||||||
|
} else {
|
||||||
|
component.$http.get('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) {
|
||||||
|
component.isLoading = false;
|
||||||
|
component.jsonData = JSON.stringify(response.body, null, ' ');
|
||||||
|
EventBus.$emit('HookFileUploaded', response.body.txid);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//EventBus.$emit('HookFileUploaded', 'txhashhere');
|
|
||||||
|
|
||||||
},
|
},
|
||||||
imagesLoaded (instance) {
|
imagesLoaded (instance) {
|
||||||
var component = this;
|
var component = this;
|
||||||
|
@ -203,6 +228,9 @@ export default {
|
||||||
document.getElementById('base-image').src = file;
|
document.getElementById('base-image').src = file;
|
||||||
// allow one second to load the image
|
// allow one second to load the image
|
||||||
setTimeout(component.updateCanvas, 1000);
|
setTimeout(component.updateCanvas, 1000);
|
||||||
|
},
|
||||||
|
highlight (language, text) {
|
||||||
|
return hljs.highlight(language, text).value;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
|
|
10
server.js
10
server.js
|
@ -71,6 +71,16 @@ app.get('/forward', function(req, res) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(req.query.method == "publish") {
|
||||||
|
|
||||||
|
// Hardcode the publish amount to be always 0.001 always
|
||||||
|
req.query.bid = 0.001;
|
||||||
|
|
||||||
|
// Fix the internal image path in daemon
|
||||||
|
req.query.file_path = process.env.LBRY_DAEMON_IMAGES_PATH + req.query.file_path;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
req.query.access_token = process.env.LBRY_DAEMON_ACCESS_TOKEN;
|
req.query.access_token = process.env.LBRY_DAEMON_ACCESS_TOKEN;
|
||||||
|
|
||||||
request({
|
request({
|
||||||
|
|
Loading…
Add table
Reference in a new issue