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) {
|
||||
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
|
||||
|
|
|
@ -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 = '<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>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>Check it out, here: <a target="_blank" href="' + directUrl + '">spee.ch/' + 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><a href="/meme-fodder/play">Reload to publish another</a></p>';
|
||||
// update publish area
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<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>
|
||||
{{#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">
|
||||
<p>claim_id: {{this.claim_id}}</p>
|
||||
<p>direct link <a href="/{{this.name}}/{{this.claim_id}}">here</a></p>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<div class="container">
|
||||
{{> topBar}}
|
||||
<div class="row">
|
||||
{{> examples}}
|
||||
{{> publish}}
|
||||
</div>
|
||||
<div class="row">
|
||||
{{> publish}}
|
||||
{{> examples}}
|
||||
</div>
|
||||
<div class="row">
|
||||
{{> 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>';
|
||||
});
|
||||
socket.on('publish-complete', function(msg){
|
||||
var publishResults = '<p>Your publish is complete!</p>';
|
||||
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>';
|
||||
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>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>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 href="/">Reload to publish another asset</a></p>';
|
||||
var publishResults;
|
||||
var directUrl = '/' + msg.name + '/' + msg.result.claim_id;
|
||||
|
||||
publishResults = '<p>Your publish is complete!</p>';
|
||||
publishResults += '<p>Check it out, here: <a target="_blank" href="' + directUrl + '">view it here!</a></p>';
|
||||
publishResults += '<p><a target="_blank" href="https://explorer.lbry.io/#!/transaction/' + msg.result.txid + '">View the transaction details</a></p>';
|
||||
publishResults += '<a href="/"><button>Reload</button></a></p>';
|
||||
document.getElementById('publish-active-area').innerHTML = publishResults;
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
<div class="card-title card-block grey lighten-1 white-text">
|
||||
<h2>Publish Your Own</h2>
|
||||
</div>
|
||||
<div class="card-block" id="publish-active-area">
|
||||
<form id="publish-form" action="" method="" enctype="multipart/form-data">
|
||||
<div class="card-block">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div id="drop-zone" ondrop="drop_handler(event);" ondragover="dragover_handler(event);" ondragend="dragend_handler(event)">
|
||||
|
@ -13,7 +12,7 @@
|
|||
</div>
|
||||
<img id="image-preview" src="" height="200" alt="Image preview..."/>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div id="publish-active-area" class="col-md-6">
|
||||
<div class="md-form">
|
||||
<input type="text" id="publish-name" value="Name" class="form-control">
|
||||
</div>
|
||||
|
@ -33,8 +32,6 @@
|
|||
<button id="publish-reset">Reset</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in a new issue