From 0e5215a84e9ca051aef65afc90ad7df420abe603 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 21 Jun 2017 16:36:08 -0700 Subject: [PATCH 1/9] finished /claim/claimId serve local first --- controllers/publishController.js | 49 ++++++++++++-- controllers/serveController.js | 108 +++++++++++++++++++++++-------- helpers/libraries/lbryApi.js | 22 ++----- models/index.js | 4 +- 4 files changed, 130 insertions(+), 53 deletions(-) diff --git a/controllers/publishController.js b/controllers/publishController.js index fc632836..64c97c3c 100644 --- a/controllers/publishController.js +++ b/controllers/publishController.js @@ -4,12 +4,10 @@ const lbryApi = require('../helpers/libraries/lbryApi.js'); const config = require('config'); const walledAddress = config.get('WalletConfig.lbryAddress'); const errorHandlers = require('../helpers/libraries/errorHandlers.js'); +const db = require('../models'); function createPublishParams (claim, filePath, license, nsfw) { logger.debug(`Creating Publish Parameters for "${claim}"`); - if (typeof nsfw === 'string') { - nsfw = (nsfw.toLowerCase() === 'on'); - } const publishParams = { name : claim, file_path: filePath, @@ -36,24 +34,61 @@ function deleteTemporaryFile (filePath) { }); } +function upsert (Model, values, condition) { + return Model + .findOne({ where: condition }) + .then(function (obj) { + if (obj) { // update + return obj.update(values); + } else { // insert + return Model.create(values); + } + }).catch(function (error) { + logger.error('Sequelize findOne error', error); + }); +} + module.exports = { - publish (claim, fileName, filePath, fileType, license, nsfw, socket, visitor) { + publish (name, fileName, filePath, fileType, license, nsfw, socket, visitor) { + // validate nsfw + if (typeof nsfw === 'string') { + nsfw = (nsfw.toLowerCase() === 'on'); + } // update the client socket.emit('publish-status', 'Your image is being published (this might take a second)...'); // send to analytics visitor.event('Publish Route', 'Publish Request', filePath).send(); // create the publish object - const publishParams = createPublishParams(claim, filePath, license, nsfw); + const publishParams = createPublishParams(name, filePath, license, nsfw); // get a promise to publish lbryApi .publishClaim(publishParams, fileName, fileType) .then(result => { - logger.info(`Successfully published ${fileName}`); + logger.info(`Successfully published ${fileName}`, result); + // google analytics visitor.event('Publish Route', 'Publish Success', filePath).send(); - socket.emit('publish-complete', { name: claim, result }); + // update old record of create new one + upsert( + db.File, + { + name, + claimId : result.claim_id, + outpoint: `${result.txid}:${result.nout}`, + fileName, + filePath, + fileType, + nsfw, + }, + { name, claimId: result.claim_id } + ).catch(error => { + logger.error('Sequelize findOne error', error); + }); + // update client + socket.emit('publish-complete', { name, result }); }) .catch(error => { logger.error(`Error publishing ${fileName}`, error); + // google analytics visitor.event('Publish Route', 'Publish Failure', filePath).send(); socket.emit('publish-failure', errorHandlers.handlePublishError(error)); deleteTemporaryFile(filePath); diff --git a/controllers/serveController.js b/controllers/serveController.js index e00daf46..e47a18b0 100644 --- a/controllers/serveController.js +++ b/controllers/serveController.js @@ -19,6 +19,61 @@ function getClaimAndHandleResponse (claimUri, resolve, reject) { }); } +function resolveAndUpdateIfNeeded (uri, claimName, claimId, outpoint) { + logger.debug('initiating resolve on local record to check outpoint'); + // 1. resolve claim + lbryApi + .resolveUri(uri) + .then(result => { + // logger.debug('resolved result:', result); + const resolvedOutpoint = `${result[uri].claim.txid}:${result[uri].claim.nout}`; + logger.debug('database outpoint:', outpoint); + logger.debug('resolved outpoint:', resolvedOutpoint); + // 2. if the outpoint's match, no further work needed + if (outpoint === resolvedOutpoint) { + logger.debug(`local outpoint matched`); + // 2. if the outpoints don't match, get claim and update records + } else { + logger.debug(`local outpoint did not match for ${uri}. Initiating update.`); + getClaimAndUpdate(uri, claimName, claimId); + } + }) + .catch(error => { + logger.error(`error resolving ${uri}`, error); + }); +} + +function getClaimAndUpdate (uri, claimName, claimId) { + // 1. get the claim + lbryApi + .getClaim(uri) + .then(({ outpoint, file_name, download_path, mime_type }) => { + logger.debug('getClaim outpoint', outpoint); + // 2. update the entry in db + db.File + .update({ + outpoint: outpoint, + fileName: file_name, + filePath: download_path, + fileType: mime_type, + }, { + where: { + name : claimName, + claimId: claimId, + }, + }) + .then(result => { + logger.debug('successfully updated mysql record', result); + }) + .catch(error => { + logger.error('sequelize error', error); + }); + }) + .catch(error => { + logger.error(`error while getting claim for ${uri}`, error); + }); +} + module.exports = { getClaimByName (claimName) { const deferred = new Promise((resolve, reject) => { @@ -51,6 +106,7 @@ module.exports = { } }) .catch(error => { + logger.error('sequelize error', error); reject(error); }); }) @@ -63,39 +119,35 @@ module.exports = { getClaimByClaimId (claimName, claimId) { const deferred = new Promise((resolve, reject) => { const uri = `${claimName}#${claimId}`; - // resolve the Uri - lbryApi - .resolveUri(uri) // note: use 'spread' and make parallel with db.File.findOne() - .then(result => { - const resolvedOutpoint = `${result[uri].claim.txid}:${result[uri].claim.nout}`; - // check locally for the claim - db.File - .findOne({ where: { name: claimName, claimId: claimId } }) - .then(claim => { - // if a found locally... - if (claim) { - logger.debug(`A mysql record was found for ${claimId}`); - // if the outpoint's match return it - if (claim.dataValues.outpoint === resolvedOutpoint) { - logger.debug(`local outpoint matched for ${claimId}`); - resolve(claim.dataValues); - // if the outpoint's don't match, fetch updated claim - } else { - logger.debug(`local outpoint did not match for ${claimId}`); - getClaimAndHandleResponse(uri, resolve, reject); - } - // ... otherwise use daemon to retrieve it - } else { + // 1. check locally for the claim + db.File + .findOne({ where: { name: claimName, claimId: claimId } }) + .then(claim => { + // 2. if a found locally, serve + if (claim) { + logger.debug(`A mysql record was found for ${claimId}`); + // trigger an update if needed + resolveAndUpdateIfNeeded(uri, claimName, claimId, claim.dataValues.outpoint); // ok to just start asynch function, or need to add to a task cue? + // resolve and send + resolve(claim.dataValues); + // 2. otherwise use daemon to retrieve it + } else { + // 3. resolve the Uri + lbryApi + .resolveUri(uri) + .then(result => { + // 4. check to see if the claim is free & public if (isFreePublicClaim(result[uri].claim)) { + // 5. get claim and serve getClaimAndHandleResponse(uri, resolve, reject); } else { reject('NO_FREE_PUBLIC_CLAIMS'); } - } - }) - .catch(error => { - reject(error); - }); + }) + .catch(error => { + reject(error); + }); + } }) .catch(error => { reject(error); diff --git a/helpers/libraries/lbryApi.js b/helpers/libraries/lbryApi.js index 7eb95fcc..3ff86cfd 100644 --- a/helpers/libraries/lbryApi.js +++ b/helpers/libraries/lbryApi.js @@ -1,15 +1,6 @@ const axios = require('axios'); -const db = require('../../models'); const logger = require('winston'); -function createFilesRecord (name, claimId, outpoint, fileName, filePath, fileType, nsfw) { - db.File - .create({ name, claimId, outpoint, fileName, filePath, fileType, nsfw }) - .catch(error => { - logger.error(`Sequelize File.create error`, error); - }); -} - module.exports = { publishClaim (publishParams, fileName, fileType) { logger.debug(`Publishing claim for "${fileName}"`); @@ -21,8 +12,6 @@ module.exports = { }) .then(response => { const result = response.data.result; - createFilesRecord( - publishParams.name, result.claim_id, `${result.txid}:${result.nout}`, fileName, publishParams.file_path, fileType, publishParams.metadata.nsfw); resolve(result); }) .catch(error => { @@ -50,11 +39,7 @@ module.exports = { /* note: put in a check to make sure we do not resolve until the download is actually complete (response.data.completed === true) */ - // save a record of the file to the Files table - const result = data.result; - createFilesRecord( - result.name, result.claim_id, result.outpoint, result.file_name, result.download_path, result.mime_type, result.metadata.stream.metadata.nsfw); - resolve(result); + resolve(data.result); }) .catch(error => { reject(error); @@ -88,6 +73,11 @@ module.exports = { params: { uri }, }) .then(({ data }) => { + // check for errors + if (data.result[uri].error) { + reject(data.result[uri].error); + return; + } resolve(data.result); }) .catch(error => { diff --git a/models/index.js b/models/index.js index 74e31518..0b64bb69 100644 --- a/models/index.js +++ b/models/index.js @@ -14,10 +14,10 @@ const sequelize = new Sequelize(connectionUri, { sequelize .authenticate() .then(() => { - logger.info('Sequelize has has been established mysql connection successfully.'); + logger.info('Sequelize has established mysql connection successfully.'); }) .catch(err => { - logger.error('Sequelize was nable to connect to the database:', err); + logger.error('Sequelize was unable to connect to the database:', err); }); fs.readdirSync(__dirname).filter(file => file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js').forEach(file => { From d278c4d4bb92beaaa2bd983b938d362adca8c69e Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 21 Jun 2017 19:10:39 -0700 Subject: [PATCH 2/9] updated /name to serve local first --- controllers/serveController.js | 43 +++++++++++++++++++++---------- public/assets/js/memePublish.js | 6 ++--- views/allClaims.handlebars | 2 +- views/index.handlebars | 18 ++++++------- views/partials/publish.handlebars | 7 ++--- 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/controllers/serveController.js b/controllers/serveController.js index e47a18b0..ad662ba0 100644 --- a/controllers/serveController.js +++ b/controllers/serveController.js @@ -7,7 +7,23 @@ const isFreePublicClaim = require('../helpers/functions/isFreePublicClaim.js'); function getClaimAndHandleResponse (claimUri, resolve, reject) { lbryApi .getClaim(claimUri) - .then(({ file_name, download_path, mime_type }) => { + .then(({ name, outpoint, claim_id, file_name, download_path, mime_type, metadata }) => { + // create entry in the db + logger.debug('creating new record in db'); + db.File + .create({ + name, + claimId : claim_id, + outpoint, + fileName: file_name, + filePath: download_path, + fileType: mime_type, + nsfw : metadata.stream.metadata.nsfw, + }) + .catch(error => { + logger.error('sequelize create error', error); + }); + // resolve the request resolve({ fileName: file_name, filePath: download_path, @@ -77,31 +93,32 @@ function getClaimAndUpdate (uri, claimName, claimId) { module.exports = { getClaimByName (claimName) { const deferred = new Promise((resolve, reject) => { - // get all free public claims + // 1. get all free public claims getAllFreePublicClaims(claimName) .then(freePublicClaimList => { const claimId = freePublicClaimList[0].claim_id; const name = freePublicClaimList[0].name; const freePublicClaimOutpoint = `${freePublicClaimList[0].txid}:${freePublicClaimList[0].nout}`; const freePublicClaimUri = `${name}#${claimId}`; - // check to see if the file is available locally + // 2. check to see if the file is available locally db.File - .findOne({ where: { name: name, claimId: claimId } }) + .findOne({ where: { name: name, claimId: claimId } }) // note: consolidate for es6? .then(claim => { - // if a matching claim is found locally... + // 3. if a matching claim_id is found locally, serve it if (claim) { logger.debug(`A mysql record was found for ${claimId}`); - // if the outpoint's match return it + // trigger update if needed if (claim.dataValues.outpoint === freePublicClaimOutpoint) { logger.debug(`local outpoint matched for ${claimId}`); - resolve(claim.dataValues); - // if the outpoint's don't match, fetch updated claim } else { logger.debug(`local outpoint did not match for ${claimId}`); - getClaimAndHandleResponse(freePublicClaimUri, resolve, reject); + getClaimAndUpdate(freePublicClaimUri, name, claimId); } - // ... otherwise use daemon to retrieve it - } else { + // return the claim + resolve(claim.dataValues); + // 3. otherwise use daemon to retrieve it + } else { + // 4. get the claim and serve it getClaimAndHandleResponse(freePublicClaimUri, resolve, reject); } }) @@ -121,9 +138,9 @@ module.exports = { const uri = `${claimName}#${claimId}`; // 1. check locally for the claim db.File - .findOne({ where: { name: claimName, claimId: claimId } }) + .findOne({ where: { name: claimName, claimId: claimId } }) // note: consolidate for es6? .then(claim => { - // 2. if a found locally, serve + // 2. if a match is found locally, serve it if (claim) { logger.debug(`A mysql record was found for ${claimId}`); // trigger an update if needed diff --git a/public/assets/js/memePublish.js b/public/assets/js/memePublish.js index 1d020aab..f1447201 100644 --- a/public/assets/js/memePublish.js +++ b/public/assets/js/memePublish.js @@ -114,12 +114,10 @@ socket.on('publish-failure', function(msg){ }); socket.on('publish-complete', function(msg){ var publishResults; - var directUrl = 'https://spee.ch/' + msg.name + '/' + msg.result.claim_id; + var directUrl = '/' + msg.name + '/' + msg.result.claim_id; // build new publish area publishResults = '

Your publish is complete! Go ahead, share it with the world!

'; - publishResults += '

NOTE: the blockchain will need a few minutes to process your amazing work. Please allow some time for your meme to appear at your link.

'; - publishResults += '

Your meme has been published to http://spee.ch/' + msg.name + '

'; - publishResults += '

Here is a direct link to where your meme will be stored: ' + directUrl + '

'; + publishResults += '

Check it out, here: spee.ch/' + directUrl + '!

'; publishResults += '

Your Transaction ID is: ' + msg.result.txid + '

'; publishResults += '

Reload to publish another

'; // update publish area diff --git a/views/allClaims.handlebars b/views/allClaims.handlebars index 75b5eb20..437ec081 100644 --- a/views/allClaims.handlebars +++ b/views/allClaims.handlebars @@ -5,7 +5,7 @@

All Claims

These are all the free, public assets at that claim. You can publish more at spee.ch.

{{#each claims}} - +

claim_id: {{this.claim_id}}

direct link here

diff --git a/views/index.handlebars b/views/index.handlebars index 120edfff..6a1d2556 100644 --- a/views/index.handlebars +++ b/views/index.handlebars @@ -1,10 +1,10 @@
{{> topBar}}
- {{> examples}} + {{> publish}}
- {{> publish}} + {{> examples}}
{{> documentation}} @@ -152,13 +152,13 @@ document.getElementById('publish-active-area').innerHTML = '

' + JSON.stringify(msg) + '

--(✖╭╮✖)→

For help, post the above error text in the #speech channel on the lbry slack'; }); socket.on('publish-complete', function(msg){ - var publishResults = '

Your publish is complete!

'; - publishResults += '

NOTE: the transaction still needs to be mined by the network before you can access it! This will take a few minutes. To view the transaction on the blockchain explorer click the Transaction ID link below.

'; - publishResults += '

Your Transaction ID is: ' + msg.result.txid + '

'; - publishResults += '

Your Claim ID is: ' + msg.result.claim_id + '

'; - publishResults += '

Here is a link to the claim where your asset will be published: spee.ch/' + msg.name + '

'; - publishResults += '

Here is a direct link to where your asset will be stored: spee.ch/' + msg.name + '/' + msg.result.claim_id + '

'; - publishResults += '

Reload to publish another asset

'; + var publishResults; + var directUrl = '/' + msg.name + '/' + msg.result.claim_id; + + publishResults = '

Your publish is complete!

'; + publishResults += '

Check it out, here: view it here!

'; + publishResults += '

View the transaction details

'; + publishResults += '

'; document.getElementById('publish-active-area').innerHTML = publishResults; }); diff --git a/views/partials/publish.handlebars b/views/partials/publish.handlebars index e99aedbb..25a1cc9e 100644 --- a/views/partials/publish.handlebars +++ b/views/partials/publish.handlebars @@ -3,8 +3,7 @@

Publish Your Own

-
-
+
@@ -13,7 +12,7 @@
Image preview...
-
+
@@ -33,8 +32,6 @@
- -
\ No newline at end of file From 192f0de4dad3497abec9890617709fb825efd36d Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 21 Jun 2017 19:45:56 -0700 Subject: [PATCH 3/9] updated the post publish links --- controllers/serveController.js | 2 +- public/assets/js/claimPublish.js | 159 ++++++++++++++++++ public/assets/js/memePublish.js | 8 +- views/index.handlebars | 148 +--------------- views/memeFodder.handlebars | 9 +- ....handlebars => memeFodderMaker.handlebars} | 8 +- ...andlebars => memeFodderResults.handlebars} | 0 7 files changed, 175 insertions(+), 159 deletions(-) create mode 100644 public/assets/js/claimPublish.js rename views/partials/{memeMaker.handlebars => memeFodderMaker.handlebars} (72%) rename views/partials/{memeResults.handlebars => memeFodderResults.handlebars} (100%) diff --git a/controllers/serveController.js b/controllers/serveController.js index ad662ba0..fb63cef2 100644 --- a/controllers/serveController.js +++ b/controllers/serveController.js @@ -117,7 +117,7 @@ module.exports = { // return the claim resolve(claim.dataValues); // 3. otherwise use daemon to retrieve it - } else { + } else { // 4. get the claim and serve it getClaimAndHandleResponse(freePublicClaimUri, resolve, reject); } diff --git a/public/assets/js/claimPublish.js b/public/assets/js/claimPublish.js new file mode 100644 index 00000000..f195d90b --- /dev/null +++ b/public/assets/js/claimPublish.js @@ -0,0 +1,159 @@ +// define variables +var socket = io(); +var uploader = new SocketIOFileUpload(socket); +var stagedFiles = null; + +/* helper functions */ +// create a progress animation +function createProgressBar(element, size){ + var x = 1; + var adder = 1; + function addOne(){ + var bars = '

|'; + for (var i = 0; i < x; i++){ bars += ' | '; } + bars += '

'; + element.innerHTML = bars; + if (x === size){ + adder = -1; + } else if ( x === 0){ + adder = 1; + } + x += adder; + }; + setInterval(addOne, 300); +} +// preview file and stage the image for upload +function previewAndStageFile(selectedFile){ + var preview = document.getElementById('image-preview'); + var dropzone = document.getElementById('drop-zone'); + var previewReader = new FileReader(); + + preview.style.display = 'block'; + dropzone.style.display = 'none'; + + previewReader.onloadend = function () { + preview.src = previewReader.result; + }; + + if (selectedFile) { + console.log(selectedFile); + previewReader.readAsDataURL(selectedFile); // reads the data and sets the img src + document.getElementById('publish-name').value = selectedFile.name.substring(0, selectedFile.name.indexOf('.')); // updates metadata inputs + stagedFiles = [selectedFile]; // stores the selected file for upload + } else { + preview.src = ''; + } +} +// update the publish status +function updatePublishStatus(msg){ + document.getElementById('publish-status').innerHTML = msg; +} +// process the drop-zone drop +function drop_handler(ev) { + console.log("drop"); + ev.preventDefault(); + // if dropped items aren't files, reject them + var dt = ev.dataTransfer; + if (dt.items) { + if (dt.items[0].kind == 'file') { + var droppedFile = dt.items[0].getAsFile(); + previewAndStageFile(droppedFile); + } else { + console.log("no files were found") + } + } else { + console.log("no items were found") + } +} +// prevent the browser's default drag behavior +function dragover_handler(ev) { + ev.preventDefault(); +} +// remove all of the drag data +function dragend_handler(ev) { + var dt = ev.dataTransfer; + if (dt.items) { + for (var i = 0; i < dt.items.length; i++) { + dt.items.remove(i); + } + } else { + ev.dataTransfer.clearData(); + } +} + +/* configure the submit button */ +document.getElementById('publish-submit').addEventListener('click', function(event){ + event.preventDefault(); + // make sure a file was selected + if (stagedFiles) { + // make sure only 1 file was selected + if (stagedFiles.length > 1) { + alert("Only one file allowed at a time"); + return; + } + // make sure the content type is acceptable + switch (stagedFiles[0].type) { + case "image/png": + case "image/jpeg": + case "image/gif": + case "video/mp4": + uploader.submitFiles(stagedFiles); + break; + default: + alert("Only .png, .jpeg, .gif, and .mp4 files are currently supported"); + break; + } + } +}) + +/* socketio-file-upload listeners */ +uploader.addEventListener('start', function(event){ + var name = document.getElementById('publish-name').value; + var license = document.getElementById('publish-license').value; + var nsfw = document.getElementById('publish-nsfw').value; + event.file.meta.name = name; + event.file.meta.license = license; + event.file.meta.nsfw = nsfw; + event.file.meta.type = stagedFiles[0].type; + // re-set the html in the publish area + document.getElementById('publish-active-area').innerHTML = '
'; + // start a progress animation + createProgressBar(document.getElementById('progress-bar'), 12); +}); +uploader.addEventListener('progress', function(event){ + var percent = event.bytesLoaded / event.file.size * 100; + updatePublishStatus('File is ' + percent.toFixed(2) + '% loaded to the server'); +}); + +/* socket.io message listeners */ +socket.on('publish-status', function(msg){ + updatePublishStatus(msg); +}); +socket.on('publish-failure', function(msg){ + document.getElementById('publish-active-area').innerHTML = '

' + JSON.stringify(msg) + '

--(✖╭╮✖)→

For help, post the above error text in the #speech channel on the lbry slack'; +}); + +socket.on('publish-complete', function(msg){ + var publishResults; + var directUrl = '/' + msg.name + '/' + msg.result.claim_id; + // build new publish area + publishResults = '

Your publish is complete! Go ahead, share it with the world!

'; + publishResults += '

Check it out, here: view it here!

'; + publishResults += '

View the transaction details

'; + publishResults += '

'; + // update publish area + document.getElementById('publish-active-area').innerHTML = publishResults; + // add a tweet button + twttr.widgets + .createShareButton( + 'https://spee.ch/' + directUrl, + document.getElementById('tweet-meme-button'), + { + text: 'Check out my image, hosted for free on the distributed awesomeness that is the LBRY blockchain!', + hashtags: 'LBRY', + via: 'lbryio' + }) + .then( function( el ) { + console.log('Tweet button added.'); + }); +}); \ No newline at end of file diff --git a/public/assets/js/memePublish.js b/public/assets/js/memePublish.js index f1447201..b7b6a66c 100644 --- a/public/assets/js/memePublish.js +++ b/public/assets/js/memePublish.js @@ -117,15 +117,15 @@ socket.on('publish-complete', function(msg){ var directUrl = '/' + msg.name + '/' + msg.result.claim_id; // build new publish area publishResults = '

Your publish is complete! Go ahead, share it with the world!

'; - publishResults += '

Check it out, here: spee.ch/' + directUrl + '!

'; - publishResults += '

Your Transaction ID is: ' + msg.result.txid + '

'; - publishResults += '

Reload to publish another

'; + publishResults += '

Check it out, here: view it here!

'; + publishResults += '

View the transaction details

'; + publishResults += '

'; // update publish area document.getElementById('publish-active-area').innerHTML = publishResults; // add a tweet button twttr.widgets .createShareButton( - directUrl, + 'https://spee.ch/' + directUrl, document.getElementById('tweet-meme-button'), { text: 'Check out my meme creation on the LBRY blockchain!', diff --git a/views/index.handlebars b/views/index.handlebars index 6a1d2556..86a27dc4 100644 --- a/views/index.handlebars +++ b/views/index.handlebars @@ -14,151 +14,9 @@
+ + - + diff --git a/views/memeFodder.handlebars b/views/memeFodder.handlebars index 4257bf0c..5620eba3 100644 --- a/views/memeFodder.handlebars +++ b/views/memeFodder.handlebars @@ -1,17 +1,18 @@
{{> topBar}} - {{ image }}
- {{> memeMaker}} + {{> memeFodderMaker}}
- {{> memeResults}} + {{> memeFodderResults}}
- + + + \ No newline at end of file diff --git a/views/partials/memeMaker.handlebars b/views/partials/memeFodderMaker.handlebars similarity index 72% rename from views/partials/memeMaker.handlebars rename to views/partials/memeFodderMaker.handlebars index c9c1f8fe..4cfe31fb 100644 --- a/views/partials/memeMaker.handlebars +++ b/views/partials/memeFodderMaker.handlebars @@ -8,8 +8,8 @@

Congratulations, you found the /meme-fodder game

Here's how it's played...

-

Create a meme based on the current /meme-fodder claim using the tools below. Got a masterpiece? Share it with the community and see what they think!

-

Note: /meme-fodder will always use the public, free image at the claim lbry://meme-fodder. Want to put a different image on the chopping block? Go publish it!

+

Create a meme based on the current lbry://meme-fodder claim using the tools below. Got a masterpiece? Share it with the community and see what they think!

+

Spee.ch/meme-fodder/play will always use the public, free image that owns the claim lbry://meme-fodder. Want to put a different image on the chopping block? Go publish it!

@@ -48,6 +48,4 @@
- - - \ No newline at end of file + \ No newline at end of file diff --git a/views/partials/memeResults.handlebars b/views/partials/memeFodderResults.handlebars similarity index 100% rename from views/partials/memeResults.handlebars rename to views/partials/memeFodderResults.handlebars From e50802fa9d461125177ae67dfe24e1cb4a0358e7 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 21 Jun 2017 20:05:11 -0700 Subject: [PATCH 4/9] updated memefodder hashtag --- public/assets/js/memePublish.js | 2 +- views/partials/memeFodderMaker.handlebars | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/public/assets/js/memePublish.js b/public/assets/js/memePublish.js index b7b6a66c..216809bc 100644 --- a/public/assets/js/memePublish.js +++ b/public/assets/js/memePublish.js @@ -129,7 +129,7 @@ socket.on('publish-complete', function(msg){ document.getElementById('tweet-meme-button'), { text: 'Check out my meme creation on the LBRY blockchain!', - hashtags: 'LBRYMemeFodder', + hashtags: 'MemeFodder', via: 'lbryio' }) .then( function( el ) { diff --git a/views/partials/memeFodderMaker.handlebars b/views/partials/memeFodderMaker.handlebars index 4cfe31fb..35aca513 100644 --- a/views/partials/memeFodderMaker.handlebars +++ b/views/partials/memeFodderMaker.handlebars @@ -1,14 +1,14 @@
-

#LBRYMemeFodder

+

#MemeFodder

Congratulations, you found the /meme-fodder game

Here's how it's played...

-

Create a meme based on the current lbry://meme-fodder claim using the tools below. Got a masterpiece? Share it with the community and see what they think!

+

Create a meme based on the current lbry://meme-fodder claim using the tools below. Got a masterpiece? Share it with the community and see what they think!

Spee.ch/meme-fodder/play will always use the public, free image that owns the claim lbry://meme-fodder. Want to put a different image on the chopping block? Go publish it!

From b4e6a6662e5c335e3c7688a1393e67389cbfb786 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 21 Jun 2017 20:07:53 -0700 Subject: [PATCH 5/9] twitter updated url --- public/assets/js/claimPublish.js | 2 +- public/assets/js/memePublish.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/public/assets/js/claimPublish.js b/public/assets/js/claimPublish.js index f195d90b..c1981ddd 100644 --- a/public/assets/js/claimPublish.js +++ b/public/assets/js/claimPublish.js @@ -146,10 +146,10 @@ socket.on('publish-complete', function(msg){ // add a tweet button twttr.widgets .createShareButton( - 'https://spee.ch/' + directUrl, document.getElementById('tweet-meme-button'), { text: 'Check out my image, hosted for free on the distributed awesomeness that is the LBRY blockchain!', + url: 'https://spee.ch/' + directUrl, hashtags: 'LBRY', via: 'lbryio' }) diff --git a/public/assets/js/memePublish.js b/public/assets/js/memePublish.js index 216809bc..cf7998cc 100644 --- a/public/assets/js/memePublish.js +++ b/public/assets/js/memePublish.js @@ -125,10 +125,10 @@ socket.on('publish-complete', function(msg){ // add a tweet button twttr.widgets .createShareButton( - 'https://spee.ch/' + directUrl, document.getElementById('tweet-meme-button'), { text: 'Check out my meme creation on the LBRY blockchain!', + url: 'https://spee.ch/' + directUrl, hashtags: 'MemeFodder', via: 'lbryio' }) From 15322c36391fa6f2389b61d0ec412182dc1cf76d Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 21 Jun 2017 23:33:03 -0700 Subject: [PATCH 6/9] added height to db --- controllers/publishController.js | 1 + controllers/serveController.js | 36 ++++++++++++--------- helpers/functions/getAllFreePublicClaims.js | 6 ++-- helpers/libraries/errorHandlers.js | 6 ++-- models/file.js | 7 +++- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/controllers/publishController.js b/controllers/publishController.js index 64c97c3c..e124bddc 100644 --- a/controllers/publishController.js +++ b/controllers/publishController.js @@ -74,6 +74,7 @@ module.exports = { name, claimId : result.claim_id, outpoint: `${result.txid}:${result.nout}`, + height : 0, fileName, filePath, fileType, diff --git a/controllers/serveController.js b/controllers/serveController.js index fb63cef2..0e21b58d 100644 --- a/controllers/serveController.js +++ b/controllers/serveController.js @@ -4,10 +4,10 @@ const logger = require('winston'); const getAllFreePublicClaims = require('../helpers/functions/getAllFreePublicClaims.js'); const isFreePublicClaim = require('../helpers/functions/isFreePublicClaim.js'); -function getClaimAndHandleResponse (claimUri, resolve, reject) { +function getClaimAndHandleResponse (claimUri, height, resolve, reject) { lbryApi .getClaim(claimUri) - .then(({ name, outpoint, claim_id, file_name, download_path, mime_type, metadata }) => { + .then(({ name, claim_id, outpoint, file_name, download_path, mime_type, metadata }) => { // create entry in the db logger.debug('creating new record in db'); db.File @@ -15,6 +15,7 @@ function getClaimAndHandleResponse (claimUri, resolve, reject) { name, claimId : claim_id, outpoint, + height, fileName: file_name, filePath: download_path, fileType: mime_type, @@ -35,7 +36,7 @@ function getClaimAndHandleResponse (claimUri, resolve, reject) { }); } -function resolveAndUpdateIfNeeded (uri, claimName, claimId, outpoint) { +function resolveAndUpdateIfNeeded (uri, claimName, claimId, localOutpoint, localHeight) { logger.debug('initiating resolve on local record to check outpoint'); // 1. resolve claim lbryApi @@ -43,19 +44,23 @@ function resolveAndUpdateIfNeeded (uri, claimName, claimId, outpoint) { .then(result => { // logger.debug('resolved result:', result); const resolvedOutpoint = `${result[uri].claim.txid}:${result[uri].claim.nout}`; - logger.debug('database outpoint:', outpoint); + const resolvedHeight = result[uri].claim.height; + logger.debug('database outpoint:', localOutpoint); logger.debug('resolved outpoint:', resolvedOutpoint); // 2. if the outpoint's match, no further work needed - if (outpoint === resolvedOutpoint) { - logger.debug(`local outpoint matched`); - // 2. if the outpoints don't match, get claim and update records + if (localOutpoint === resolvedOutpoint) { + logger.debug('local outpoint matched'); + // 2. if the outpoints don't match, check the height + } else if (localHeight > resolvedHeight) { + logger.debug('local height was greater than resolve height'); + // 2. get the resolved claim } else { logger.debug(`local outpoint did not match for ${uri}. Initiating update.`); getClaimAndUpdate(uri, claimName, claimId); } }) .catch(error => { - logger.error(`error resolving ${uri}`, error); + logger.error(`error resolving "${uri}" >> `, error); }); } @@ -98,8 +103,9 @@ module.exports = { .then(freePublicClaimList => { const claimId = freePublicClaimList[0].claim_id; const name = freePublicClaimList[0].name; - const freePublicClaimOutpoint = `${freePublicClaimList[0].txid}:${freePublicClaimList[0].nout}`; - const freePublicClaimUri = `${name}#${claimId}`; + const outpoint = `${freePublicClaimList[0].txid}:${freePublicClaimList[0].nout}`; + const uri = `${name}#${claimId}`; + const height = freePublicClaimList[0].height; // 2. check to see if the file is available locally db.File .findOne({ where: { name: name, claimId: claimId } }) // note: consolidate for es6? @@ -108,18 +114,18 @@ module.exports = { if (claim) { logger.debug(`A mysql record was found for ${claimId}`); // trigger update if needed - if (claim.dataValues.outpoint === freePublicClaimOutpoint) { + if (claim.dataValues.outpoint === outpoint) { logger.debug(`local outpoint matched for ${claimId}`); } else { logger.debug(`local outpoint did not match for ${claimId}`); - getClaimAndUpdate(freePublicClaimUri, name, claimId); + getClaimAndUpdate(uri, name, claimId); } // return the claim resolve(claim.dataValues); // 3. otherwise use daemon to retrieve it } else { // 4. get the claim and serve it - getClaimAndHandleResponse(freePublicClaimUri, resolve, reject); + getClaimAndHandleResponse(uri, height, resolve, reject); } }) .catch(error => { @@ -144,7 +150,7 @@ module.exports = { if (claim) { logger.debug(`A mysql record was found for ${claimId}`); // trigger an update if needed - resolveAndUpdateIfNeeded(uri, claimName, claimId, claim.dataValues.outpoint); // ok to just start asynch function, or need to add to a task cue? + resolveAndUpdateIfNeeded(uri, claimName, claimId, claim.dataValues.outpoint, claim.dataValues.outpoint); // ok to just start asynch function, or need to add to a task cue? // resolve and send resolve(claim.dataValues); // 2. otherwise use daemon to retrieve it @@ -156,7 +162,7 @@ module.exports = { // 4. check to see if the claim is free & public if (isFreePublicClaim(result[uri].claim)) { // 5. get claim and serve - getClaimAndHandleResponse(uri, resolve, reject); + getClaimAndHandleResponse(uri, result[uri].claim.height, resolve, reject); } else { reject('NO_FREE_PUBLIC_CLAIMS'); } diff --git a/helpers/functions/getAllFreePublicClaims.js b/helpers/functions/getAllFreePublicClaims.js index 4d3e39ec..0f9c30a2 100644 --- a/helpers/functions/getAllFreePublicClaims.js +++ b/helpers/functions/getAllFreePublicClaims.js @@ -16,8 +16,8 @@ function filterForFreePublicClaims (claimsListArray) { return freePublicClaims; } -function orderTopClaims (claimsListArray) { - logger.debug('ordering the top claims'); +function orderClaims (claimsListArray) { + logger.debug('ordering the free public claims'); claimsListArray.sort((a, b) => { if (a.amount === b.amount) { return a.height < b.height; @@ -51,7 +51,7 @@ module.exports = claimName => { return; } // order the claims - const orderedPublicClaims = orderTopClaims(freePublicClaims); + const orderedPublicClaims = orderClaims(freePublicClaims); // resolve the promise resolve(orderedPublicClaims); }) diff --git a/helpers/libraries/errorHandlers.js b/helpers/libraries/errorHandlers.js index b0e8757f..f23c5fa4 100644 --- a/helpers/libraries/errorHandlers.js +++ b/helpers/libraries/errorHandlers.js @@ -2,7 +2,7 @@ const logger = require('winston'); module.exports = { handleRequestError (error, res) { - logger.error('Request Error,', error); + logger.error('Request Error >>', error); if (error === 'NO_CLAIMS' || error === 'NO_FREE_PUBLIC_CLAIMS') { res.status(307).render('noClaims'); } else if (error.response) { @@ -10,11 +10,11 @@ module.exports = { } else if (error.code === 'ECONNREFUSED') { res.status(400).send('Connection refused. The daemon may not be running.'); } else { - res.status(400).send(error.toString()); + res.status(400).send(JSON.stringify(error)); } }, handlePublishError (error) { - logger.error('Publish Error,', error); + logger.error('Publish Error >>', error); if (error.code === 'ECONNREFUSED') { return 'Connection refused. The daemon may not be running.'; } else if (error.response.data.error) { diff --git a/models/file.js b/models/file.js index acadd0c9..cc6cd325 100644 --- a/models/file.js +++ b/models/file.js @@ -1,4 +1,4 @@ -module.exports = (sequelize, { STRING, BOOLEAN }) => { +module.exports = (sequelize, { STRING, BOOLEAN, INTEGER }) => { const File = sequelize.define( 'File', { @@ -14,6 +14,11 @@ module.exports = (sequelize, { STRING, BOOLEAN }) => { type : STRING, allowNull: false, }, + height: { + type : INTEGER, + allowNull: false, + default : 0, + }, fileName: { type : STRING, allowNull: false, From 0af0ffb2da1c36917c18a13e9ec53d912dcc9e61 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 22 Jun 2017 00:16:51 -0700 Subject: [PATCH 7/9] updated meme-fodder selection rules --- public/assets/js/claimPublish.js | 3 +-- public/assets/js/memeDraw.js | 16 ++++++++++++++-- public/assets/js/memePublish.js | 3 +-- views/partials/memeFodderMaker.handlebars | 5 ++--- views/partials/memeFodderResults.handlebars | 5 ++--- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/public/assets/js/claimPublish.js b/public/assets/js/claimPublish.js index c1981ddd..8d329507 100644 --- a/public/assets/js/claimPublish.js +++ b/public/assets/js/claimPublish.js @@ -137,8 +137,7 @@ socket.on('publish-complete', function(msg){ var publishResults; var directUrl = '/' + msg.name + '/' + msg.result.claim_id; // build new publish area - publishResults = '

Your publish is complete! Go ahead, share it with the world!

'; - publishResults += '

Check it out, here: view it here!

'; + publishResults = '

Your publish is complete! View it here!

'; publishResults += '

View the transaction details

'; publishResults += '

'; // update publish area diff --git a/public/assets/js/memeDraw.js b/public/assets/js/memeDraw.js index db1cf2c5..dbfb4f31 100644 --- a/public/assets/js/memeDraw.js +++ b/public/assets/js/memeDraw.js @@ -22,6 +22,18 @@ img.onload = function() { drawMeme() } +function newCanvas(image){ + // hide start image + img = image; + // get dimensions of the start img + canvasHeight = canvasWidth * (img.height / img.width); + // size the canvas + canvas.width = canvasWidth; + canvas.height = canvasHeight; + // draw the meme + drawMeme() +} + // if the text changes, re-draw the meme topText.addEventListener('keyup', drawMeme); bottomText.addEventListener('keyup', drawMeme); @@ -40,14 +52,14 @@ function drawMeme() { var text1 = topText.value; text1 = text1.toUpperCase(); x = canvasWidth / 2; - y = 0; + y = 5; wrapText(ctx, text1, x, y, canvasWidth, fontSize, false); ctx.textBaseline = 'bottom'; var text2 = bottomText.value; text2 = text2.toUpperCase(); - y = canvasHeight; + y = canvasHeight - 5; wrapText(ctx, text2, x, y, canvasHeight, fontSize, true); diff --git a/public/assets/js/memePublish.js b/public/assets/js/memePublish.js index cf7998cc..452d616c 100644 --- a/public/assets/js/memePublish.js +++ b/public/assets/js/memePublish.js @@ -116,8 +116,7 @@ socket.on('publish-complete', function(msg){ var publishResults; var directUrl = '/' + msg.name + '/' + msg.result.claim_id; // build new publish area - publishResults = '

Your publish is complete! Go ahead, share it with the world!

'; - publishResults += '

Check it out, here: view it here!

'; + publishResults = '

Your publish is complete! View it here!

'; publishResults += '

View the transaction details

'; publishResults += '

'; // update publish area diff --git a/views/partials/memeFodderMaker.handlebars b/views/partials/memeFodderMaker.handlebars index 35aca513..2828fd1a 100644 --- a/views/partials/memeFodderMaker.handlebars +++ b/views/partials/memeFodderMaker.handlebars @@ -7,9 +7,8 @@

Congratulations, you found the /meme-fodder game

-

Here's how it's played...

-

Create a meme based on the current lbry://meme-fodder claim using the tools below. Got a masterpiece? Share it with the community and see what they think!

-

Spee.ch/meme-fodder/play will always use the public, free image that owns the claim lbry://meme-fodder. Want to put a different image on the chopping block? Go publish it!

+

Create a meme based on the current lbry://meme-fodder claims using the tool below. Got a masterpiece? Share it with the community and see what they think!

+

Spee.ch/meme-fodder/play uses the free, public images at the claim lbry://meme-fodder. Want to put a different image on the chopping block? Go publish it!

diff --git a/views/partials/memeFodderResults.handlebars b/views/partials/memeFodderResults.handlebars index b611a31a..70c41190 100644 --- a/views/partials/memeFodderResults.handlebars +++ b/views/partials/memeFodderResults.handlebars @@ -6,14 +6,13 @@
-

Below are some of the most recent images that have been fuel for our enjoyment on /meme-fodder

+

Below are the images published to /meme-fodder. Click one to choose it as your canvas.

{{#each claims}}
- - +

{{/each}} From 232591fdb3f25dbee53b2024c190e3e11944672b Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 22 Jun 2017 10:08:41 -0700 Subject: [PATCH 8/9] consolidated the resolve-and-update code --- controllers/publishController.js | 7 +- controllers/serveController.js | 154 +++++++++++----------- public/assets/js/claimPublish.js | 2 +- public/assets/js/memePublish.js | 2 +- views/partials/memeFodderMaker.handlebars | 4 +- views/partials/publish.handlebars | 38 +++--- 6 files changed, 104 insertions(+), 103 deletions(-) diff --git a/controllers/publishController.js b/controllers/publishController.js index e124bddc..abf3dca8 100644 --- a/controllers/publishController.js +++ b/controllers/publishController.js @@ -50,9 +50,10 @@ function upsert (Model, values, condition) { module.exports = { publish (name, fileName, filePath, fileType, license, nsfw, socket, visitor) { + console.log('nsfw:', nsfw); // validate nsfw if (typeof nsfw === 'string') { - nsfw = (nsfw.toLowerCase() === 'on'); + nsfw = (nsfw.toLowerCase() === 'true'); } // update the client socket.emit('publish-status', 'Your image is being published (this might take a second)...'); @@ -60,14 +61,14 @@ module.exports = { visitor.event('Publish Route', 'Publish Request', filePath).send(); // create the publish object const publishParams = createPublishParams(name, filePath, license, nsfw); - // get a promise to publish + // 1. publish the file lbryApi .publishClaim(publishParams, fileName, fileType) .then(result => { logger.info(`Successfully published ${fileName}`, result); // google analytics visitor.event('Publish Route', 'Publish Success', filePath).send(); - // update old record of create new one + // 2. update old record of create new one (update is in case the claim has been published before by this daemon) upsert( db.File, { diff --git a/controllers/serveController.js b/controllers/serveController.js index 0e21b58d..63b4ab10 100644 --- a/controllers/serveController.js +++ b/controllers/serveController.js @@ -4,9 +4,71 @@ const logger = require('winston'); const getAllFreePublicClaims = require('../helpers/functions/getAllFreePublicClaims.js'); const isFreePublicClaim = require('../helpers/functions/isFreePublicClaim.js'); -function getClaimAndHandleResponse (claimUri, height, resolve, reject) { +function updateFileIfNeeded (uri, claimName, claimId, localOutpoint, localHeight) { + logger.debug(`A mysql record was found for ${claimId}`); + logger.debug('initiating resolve on claim to check outpoint'); + // 1. resolve claim lbryApi - .getClaim(claimUri) + .resolveUri(uri) + .then(result => { + // logger.debug('resolved result:', result); + const resolvedOutpoint = `${result[uri].claim.txid}:${result[uri].claim.nout}`; + const resolvedHeight = result[uri].claim.height; + logger.debug('database outpoint:', localOutpoint); + logger.debug('resolved outpoint:', resolvedOutpoint); + // 2. if the outpoint's match, no further work needed + if (localOutpoint === resolvedOutpoint) { + logger.debug('local outpoint matched'); + // 2. if the outpoints don't match, check the height + } else if (localHeight > resolvedHeight) { + logger.debug('local height was greater than resolved height'); + // 2. get the resolved claim + } else { + logger.debug(`local outpoint did not match for ${uri}. Initiating update.`); + getClaimAndUpdate(uri, resolvedHeight); + } + }) + .catch(error => { + logger.error(`error resolving "${uri}" >> `, error); + }); +} + +function getClaimAndUpdate (uri, height) { + // 1. get the claim + lbryApi + .getClaim(uri) + .then(({ name, claim_id, outpoint, file_name, download_path, mime_type, metadata }) => { + logger.debug(' Get returned outpoint: ', outpoint); + // 2. update the entry in db + db.File + .update({ + outpoint, + height, // note: height is coming from 'resolve', not 'get'. + fileName: file_name, + filePath: download_path, + fileType: mime_type, + nsfw : metadata.stream.metadata.nsfw, + }, { + where: { + name, + claimId: claim_id, + }, + }) + .then(result => { + logger.debug('successfully updated mysql record', result); + }) + .catch(error => { + logger.error('sequelize error', error); + }); + }) + .catch(error => { + logger.error(`error while getting claim for ${uri} >> `, error); + }); +} + +function getClaimAndHandleResponse (uri, height, resolve, reject) { + lbryApi + .getClaim(uri) .then(({ name, claim_id, outpoint, file_name, download_path, mime_type, metadata }) => { // create entry in the db logger.debug('creating new record in db'); @@ -21,6 +83,9 @@ function getClaimAndHandleResponse (claimUri, height, resolve, reject) { fileType: mime_type, nsfw : metadata.stream.metadata.nsfw, }) + .then(result => { + logger.debug('successfully created mysql record', result); + }) .catch(error => { logger.error('sequelize create error', error); }); @@ -36,95 +101,29 @@ function getClaimAndHandleResponse (claimUri, height, resolve, reject) { }); } -function resolveAndUpdateIfNeeded (uri, claimName, claimId, localOutpoint, localHeight) { - logger.debug('initiating resolve on local record to check outpoint'); - // 1. resolve claim - lbryApi - .resolveUri(uri) - .then(result => { - // logger.debug('resolved result:', result); - const resolvedOutpoint = `${result[uri].claim.txid}:${result[uri].claim.nout}`; - const resolvedHeight = result[uri].claim.height; - logger.debug('database outpoint:', localOutpoint); - logger.debug('resolved outpoint:', resolvedOutpoint); - // 2. if the outpoint's match, no further work needed - if (localOutpoint === resolvedOutpoint) { - logger.debug('local outpoint matched'); - // 2. if the outpoints don't match, check the height - } else if (localHeight > resolvedHeight) { - logger.debug('local height was greater than resolve height'); - // 2. get the resolved claim - } else { - logger.debug(`local outpoint did not match for ${uri}. Initiating update.`); - getClaimAndUpdate(uri, claimName, claimId); - } - }) - .catch(error => { - logger.error(`error resolving "${uri}" >> `, error); - }); -} - -function getClaimAndUpdate (uri, claimName, claimId) { - // 1. get the claim - lbryApi - .getClaim(uri) - .then(({ outpoint, file_name, download_path, mime_type }) => { - logger.debug('getClaim outpoint', outpoint); - // 2. update the entry in db - db.File - .update({ - outpoint: outpoint, - fileName: file_name, - filePath: download_path, - fileType: mime_type, - }, { - where: { - name : claimName, - claimId: claimId, - }, - }) - .then(result => { - logger.debug('successfully updated mysql record', result); - }) - .catch(error => { - logger.error('sequelize error', error); - }); - }) - .catch(error => { - logger.error(`error while getting claim for ${uri}`, error); - }); -} - module.exports = { getClaimByName (claimName) { const deferred = new Promise((resolve, reject) => { - // 1. get all free public claims + // 1. get the top free, public claims getAllFreePublicClaims(claimName) .then(freePublicClaimList => { - const claimId = freePublicClaimList[0].claim_id; const name = freePublicClaimList[0].name; - const outpoint = `${freePublicClaimList[0].txid}:${freePublicClaimList[0].nout}`; + const claimId = freePublicClaimList[0].claim_id; const uri = `${name}#${claimId}`; const height = freePublicClaimList[0].height; // 2. check to see if the file is available locally db.File - .findOne({ where: { name: name, claimId: claimId } }) // note: consolidate for es6? + .findOne({ where: { name: name, claimId: claimId } }) // note: destructure for es6? .then(claim => { // 3. if a matching claim_id is found locally, serve it if (claim) { - logger.debug(`A mysql record was found for ${claimId}`); // trigger update if needed - if (claim.dataValues.outpoint === outpoint) { - logger.debug(`local outpoint matched for ${claimId}`); - } else { - logger.debug(`local outpoint did not match for ${claimId}`); - getClaimAndUpdate(uri, name, claimId); - } - // return the claim + updateFileIfNeeded(uri, name, claimId, claim.dataValues.outpoint, claim.dataValues.height); + // serve the file resolve(claim.dataValues); // 3. otherwise use daemon to retrieve it } else { - // 4. get the claim and serve it + // get the claim and serve it getClaimAndHandleResponse(uri, height, resolve, reject); } }) @@ -144,14 +143,13 @@ module.exports = { const uri = `${claimName}#${claimId}`; // 1. check locally for the claim db.File - .findOne({ where: { name: claimName, claimId: claimId } }) // note: consolidate for es6? + .findOne({ where: { name: claimName, claimId: claimId } }) // note: destructure? .then(claim => { // 2. if a match is found locally, serve it if (claim) { - logger.debug(`A mysql record was found for ${claimId}`); // trigger an update if needed - resolveAndUpdateIfNeeded(uri, claimName, claimId, claim.dataValues.outpoint, claim.dataValues.outpoint); // ok to just start asynch function, or need to add to a task cue? - // resolve and send + updateFileIfNeeded(uri, claimName, claimId, claim.dataValues.outpoint, claim.dataValues.outpoint); + // serve the file resolve(claim.dataValues); // 2. otherwise use daemon to retrieve it } else { diff --git a/public/assets/js/claimPublish.js b/public/assets/js/claimPublish.js index 8d329507..97ffc829 100644 --- a/public/assets/js/claimPublish.js +++ b/public/assets/js/claimPublish.js @@ -110,7 +110,7 @@ document.getElementById('publish-submit').addEventListener('click', function(eve uploader.addEventListener('start', function(event){ var name = document.getElementById('publish-name').value; var license = document.getElementById('publish-license').value; - var nsfw = document.getElementById('publish-nsfw').value; + var nsfw = document.getElementById('publish-nsfw').checked; event.file.meta.name = name; event.file.meta.license = license; event.file.meta.nsfw = nsfw; diff --git a/public/assets/js/memePublish.js b/public/assets/js/memePublish.js index 452d616c..7f69cd6b 100644 --- a/public/assets/js/memePublish.js +++ b/public/assets/js/memePublish.js @@ -128,7 +128,7 @@ socket.on('publish-complete', function(msg){ { text: 'Check out my meme creation on the LBRY blockchain!', url: 'https://spee.ch/' + directUrl, - hashtags: 'MemeFodder', + hashtags: 'LBRYMemeFodder', via: 'lbryio' }) .then( function( el ) { diff --git a/views/partials/memeFodderMaker.handlebars b/views/partials/memeFodderMaker.handlebars index 2828fd1a..0990a84b 100644 --- a/views/partials/memeFodderMaker.handlebars +++ b/views/partials/memeFodderMaker.handlebars @@ -1,13 +1,13 @@
-

#MemeFodder

+

#LBRYMemeFodder

Congratulations, you found the /meme-fodder game

-

Create a meme based on the current lbry://meme-fodder claims using the tool below. Got a masterpiece? Share it with the community and see what they think!

+

Create a meme based on the current lbry://meme-fodder claims using the tool below. Got a masterpiece? Share it with the community and see what they think!

Spee.ch/meme-fodder/play uses the free, public images at the claim lbry://meme-fodder. Want to put a different image on the chopping block? Go publish it!

diff --git a/views/partials/publish.handlebars b/views/partials/publish.handlebars index 25a1cc9e..361cd621 100644 --- a/views/partials/publish.handlebars +++ b/views/partials/publish.handlebars @@ -13,25 +13,27 @@ Image preview...
-
- -
-
- License: - -
-
- - -
-

By clicking 'Publish' I attest that I have read and agree to the LBRY terms of service.

- - +
+
+ +
+
+ License: + +
+
+ + +
+

By clicking 'Publish' I attest that I have read and agree to the LBRY terms of service.

+ + +
-
\ No newline at end of file +
From 88d217cb2c5a604911555f6ae044e9a277208011 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 22 Jun 2017 10:28:34 -0700 Subject: [PATCH 9/9] switched resolve and update functions --- controllers/serveController.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/controllers/serveController.js b/controllers/serveController.js index 63b4ab10..4017bd33 100644 --- a/controllers/serveController.js +++ b/controllers/serveController.js @@ -84,7 +84,7 @@ function getClaimAndHandleResponse (uri, height, resolve, reject) { nsfw : metadata.stream.metadata.nsfw, }) .then(result => { - logger.debug('successfully created mysql record', result); + logger.debug('successfully created mysql record'); }) .catch(error => { logger.error('sequelize create error', error); @@ -113,14 +113,14 @@ module.exports = { const height = freePublicClaimList[0].height; // 2. check to see if the file is available locally db.File - .findOne({ where: { name: name, claimId: claimId } }) // note: destructure for es6? + .findOne({ where: { name, claimId } }) .then(claim => { // 3. if a matching claim_id is found locally, serve it if (claim) { - // trigger update if needed - updateFileIfNeeded(uri, name, claimId, claim.dataValues.outpoint, claim.dataValues.height); // serve the file resolve(claim.dataValues); + // trigger update if needed + updateFileIfNeeded(uri, name, claimId, claim.dataValues.outpoint, claim.dataValues.height); // 3. otherwise use daemon to retrieve it } else { // get the claim and serve it @@ -138,19 +138,19 @@ module.exports = { }); return deferred; }, - getClaimByClaimId (claimName, claimId) { + getClaimByClaimId (name, claimId) { const deferred = new Promise((resolve, reject) => { - const uri = `${claimName}#${claimId}`; + const uri = `${name}#${claimId}`; // 1. check locally for the claim db.File - .findOne({ where: { name: claimName, claimId: claimId } }) // note: destructure? + .findOne({ where: { name, claimId } }) .then(claim => { // 2. if a match is found locally, serve it if (claim) { - // trigger an update if needed - updateFileIfNeeded(uri, claimName, claimId, claim.dataValues.outpoint, claim.dataValues.outpoint); // serve the file resolve(claim.dataValues); + // trigger an update if needed + updateFileIfNeeded(uri, name, claimId, claim.dataValues.outpoint, claim.dataValues.outpoint); // 2. otherwise use daemon to retrieve it } else { // 3. resolve the Uri