updated /name to serve local first
This commit is contained in:
parent
0e5215a84e
commit
d278c4d4bb
5 changed files with 44 additions and 32 deletions
|
@ -7,7 +7,23 @@ const isFreePublicClaim = require('../helpers/functions/isFreePublicClaim.js');
|
||||||
function getClaimAndHandleResponse (claimUri, resolve, reject) {
|
function getClaimAndHandleResponse (claimUri, resolve, reject) {
|
||||||
lbryApi
|
lbryApi
|
||||||
.getClaim(claimUri)
|
.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({
|
resolve({
|
||||||
fileName: file_name,
|
fileName: file_name,
|
||||||
filePath: download_path,
|
filePath: download_path,
|
||||||
|
@ -77,31 +93,32 @@ function getClaimAndUpdate (uri, claimName, claimId) {
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getClaimByName (claimName) {
|
getClaimByName (claimName) {
|
||||||
const deferred = new Promise((resolve, reject) => {
|
const deferred = new Promise((resolve, reject) => {
|
||||||
// get all free public claims
|
// 1. get all free public claims
|
||||||
getAllFreePublicClaims(claimName)
|
getAllFreePublicClaims(claimName)
|
||||||
.then(freePublicClaimList => {
|
.then(freePublicClaimList => {
|
||||||
const claimId = freePublicClaimList[0].claim_id;
|
const claimId = freePublicClaimList[0].claim_id;
|
||||||
const name = freePublicClaimList[0].name;
|
const name = freePublicClaimList[0].name;
|
||||||
const freePublicClaimOutpoint = `${freePublicClaimList[0].txid}:${freePublicClaimList[0].nout}`;
|
const freePublicClaimOutpoint = `${freePublicClaimList[0].txid}:${freePublicClaimList[0].nout}`;
|
||||||
const freePublicClaimUri = `${name}#${claimId}`;
|
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
|
db.File
|
||||||
.findOne({ where: { name: name, claimId: claimId } })
|
.findOne({ where: { name: name, claimId: claimId } }) // note: consolidate for es6?
|
||||||
.then(claim => {
|
.then(claim => {
|
||||||
// if a matching claim is found locally...
|
// 3. if a matching claim_id is found locally, serve it
|
||||||
if (claim) {
|
if (claim) {
|
||||||
logger.debug(`A mysql record was found for ${claimId}`);
|
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) {
|
if (claim.dataValues.outpoint === freePublicClaimOutpoint) {
|
||||||
logger.debug(`local outpoint matched for ${claimId}`);
|
logger.debug(`local outpoint matched for ${claimId}`);
|
||||||
resolve(claim.dataValues);
|
|
||||||
// if the outpoint's don't match, fetch updated claim
|
|
||||||
} else {
|
} else {
|
||||||
logger.debug(`local outpoint did not match for ${claimId}`);
|
logger.debug(`local outpoint did not match for ${claimId}`);
|
||||||
getClaimAndHandleResponse(freePublicClaimUri, resolve, reject);
|
getClaimAndUpdate(freePublicClaimUri, name, claimId);
|
||||||
}
|
}
|
||||||
// ... otherwise use daemon to retrieve it
|
// return the claim
|
||||||
} else {
|
resolve(claim.dataValues);
|
||||||
|
// 3. otherwise use daemon to retrieve it
|
||||||
|
} else {
|
||||||
|
// 4. get the claim and serve it
|
||||||
getClaimAndHandleResponse(freePublicClaimUri, resolve, reject);
|
getClaimAndHandleResponse(freePublicClaimUri, resolve, reject);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -121,9 +138,9 @@ module.exports = {
|
||||||
const uri = `${claimName}#${claimId}`;
|
const uri = `${claimName}#${claimId}`;
|
||||||
// 1. check locally for the claim
|
// 1. check locally for the claim
|
||||||
db.File
|
db.File
|
||||||
.findOne({ where: { name: claimName, claimId: claimId } })
|
.findOne({ where: { name: claimName, claimId: claimId } }) // note: consolidate for es6?
|
||||||
.then(claim => {
|
.then(claim => {
|
||||||
// 2. if a found locally, serve
|
// 2. if a match is found locally, serve it
|
||||||
if (claim) {
|
if (claim) {
|
||||||
logger.debug(`A mysql record was found for ${claimId}`);
|
logger.debug(`A mysql record was found for ${claimId}`);
|
||||||
// trigger an update if needed
|
// trigger an update if needed
|
||||||
|
|
|
@ -114,12 +114,10 @@ socket.on('publish-failure', function(msg){
|
||||||
});
|
});
|
||||||
socket.on('publish-complete', function(msg){
|
socket.on('publish-complete', function(msg){
|
||||||
var publishResults;
|
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
|
// build new publish area
|
||||||
publishResults = '<p><span id="tweet-meme-button"></span>Your publish is complete! Go ahead, share it with the world!</p>';
|
publishResults = '<p><span id="tweet-meme-button"></span>Your publish is complete! Go ahead, share it with the world!</p>';
|
||||||
publishResults += '<p><strong>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.</strong></p>';
|
publishResults += '<p>Check it out, here: <a target="_blank" href="' + directUrl + '">spee.ch/' + directUrl + '</a>!</p>';
|
||||||
publishResults += '<p>Your meme has been published to <a target="_blank" href="/' + msg.name + '">http://spee.ch/' + msg.name + '</a></p>';
|
|
||||||
publishResults += '<p>Here is a direct link to where your meme will be stored: <a target="_blank" href="' + directUrl + '">' + directUrl + '</a></p>';
|
|
||||||
publishResults += '<p>Your Transaction ID is: <a target="_blank" href="https://explorer.lbry.io/#!/transaction?id=' + msg.result.txid + '">' + msg.result.txid + '</a></p>';
|
publishResults += '<p>Your Transaction ID is: <a target="_blank" href="https://explorer.lbry.io/#!/transaction?id=' + msg.result.txid + '">' + msg.result.txid + '</a></p>';
|
||||||
publishResults += '<p><a href="/meme-fodder/play">Reload to publish another</a></p>';
|
publishResults += '<p><a href="/meme-fodder/play">Reload to publish another</a></p>';
|
||||||
// update publish area
|
// update publish area
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<h3>All Claims</h3>
|
<h3>All Claims</h3>
|
||||||
<p>These are all the free, public assets at that claim. You can publish more at <a href="/">spee.ch</a>.</p>
|
<p>These are all the free, public assets at that claim. You can publish more at <a href="/">spee.ch</a>.</p>
|
||||||
{{#each claims}}
|
{{#each claims}}
|
||||||
<img class="all-claims-img" src="https://spee.ch/{{this.name}}/{{this.claim_id}}" />
|
<img class="all-claims-img" src="/{{this.name}}/{{this.claim_id}}" />
|
||||||
<div class="card card-block">
|
<div class="card card-block">
|
||||||
<p>claim_id: {{this.claim_id}}</p>
|
<p>claim_id: {{this.claim_id}}</p>
|
||||||
<p>direct link <a href="/{{this.name}}/{{this.claim_id}}">here</a></p>
|
<p>direct link <a href="/{{this.name}}/{{this.claim_id}}">here</a></p>
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{{> topBar}}
|
{{> topBar}}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{{> examples}}
|
{{> publish}}
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{{> publish}}
|
{{> examples}}
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{{> documentation}}
|
{{> documentation}}
|
||||||
|
@ -152,13 +152,13 @@
|
||||||
document.getElementById('publish-active-area').innerHTML = '<p>' + JSON.stringify(msg) + '</p><p> --(✖╭╮✖)→ </p><strong>For help, post the above error text in the #speech channel on the <a href="https://lbry.slack.com/" target="_blank">lbry slack</a></strong>';
|
document.getElementById('publish-active-area').innerHTML = '<p>' + JSON.stringify(msg) + '</p><p> --(✖╭╮✖)→ </p><strong>For help, post the above error text in the #speech channel on the <a href="https://lbry.slack.com/" target="_blank">lbry slack</a></strong>';
|
||||||
});
|
});
|
||||||
socket.on('publish-complete', function(msg){
|
socket.on('publish-complete', function(msg){
|
||||||
var publishResults = '<p>Your publish is complete!</p>';
|
var publishResults;
|
||||||
publishResults += '<p><strong>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.</strong></p>';
|
var directUrl = '/' + msg.name + '/' + msg.result.claim_id;
|
||||||
publishResults += '<p>Your Transaction ID is: <a target="_blank" href="https://explorer.lbry.io/#!/transaction?id=' + msg.result.txid + '">' + msg.result.txid + '</a></p>';
|
|
||||||
publishResults += '<p>Your Claim ID is: ' + msg.result.claim_id + '</p>';
|
publishResults = '<p>Your publish is complete!</p>';
|
||||||
publishResults += '<p>Here is a link to the claim where your asset will be published: <a target="_blank" href="https://spee.ch/' + msg.name + '">spee.ch/' + msg.name + '</a></p>';
|
publishResults += '<p>Check it out, here: <a target="_blank" href="' + directUrl + '">view it here!</a></p>';
|
||||||
publishResults += '<p>Here is a direct link to where your asset will be stored: <a target="_blank" href="https://spee.ch/' + msg.name + '/' + msg.result.claim_id + '">spee.ch/' + msg.name + '/' + msg.result.claim_id + '</a></p>';
|
publishResults += '<p><a target="_blank" href="https://explorer.lbry.io/#!/transaction/' + msg.result.txid + '">View the transaction details</a></p>';
|
||||||
publishResults += '<p><a href="/">Reload to publish another asset</a></p>';
|
publishResults += '<a href="/"><button>Reload</button></a></p>';
|
||||||
document.getElementById('publish-active-area').innerHTML = publishResults;
|
document.getElementById('publish-active-area').innerHTML = publishResults;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
<div class="card-title card-block grey lighten-1 white-text">
|
<div class="card-title card-block grey lighten-1 white-text">
|
||||||
<h2>Publish Your Own</h2>
|
<h2>Publish Your Own</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-block" id="publish-active-area">
|
<div class="card-block">
|
||||||
<form id="publish-form" action="" method="" enctype="multipart/form-data">
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<div id="drop-zone" ondrop="drop_handler(event);" ondragover="dragover_handler(event);" ondragend="dragend_handler(event)">
|
<div id="drop-zone" ondrop="drop_handler(event);" ondragover="dragover_handler(event);" ondragend="dragend_handler(event)">
|
||||||
|
@ -13,7 +12,7 @@
|
||||||
</div>
|
</div>
|
||||||
<img id="image-preview" src="" height="200" alt="Image preview..."/>
|
<img id="image-preview" src="" height="200" alt="Image preview..."/>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div id="publish-active-area" class="col-md-6">
|
||||||
<div class="md-form">
|
<div class="md-form">
|
||||||
<input type="text" id="publish-name" value="Name" class="form-control">
|
<input type="text" id="publish-name" value="Name" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
|
@ -33,8 +32,6 @@
|
||||||
<button id="publish-reset">Reset</button>
|
<button id="publish-reset">Reset</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
Loading…
Reference in a new issue