Block used claims #68

Merged
bones7242 merged 6 commits from block-used-claims into master 2017-07-04 18:17:28 +02:00
3 changed files with 68 additions and 23 deletions
Showing only changes of commit c3b679636d - Show all commits

View file

@ -63,4 +63,18 @@ module.exports = {
});
return deferred;
},
checkNameAvailability: (name) => {
const deferred = new Promise((resolve, reject) => {
// find any records where the name is used
db.File
.findAll({ where: { name } })
.then(result => {
resolve(result);
})
.catch(error => {
reject(error);
});
});
return deferred;
},
};

View file

@ -83,7 +83,7 @@ document.getElementById('publish-submit').addEventListener('click', function(eve
event.preventDefault();
var name = document.getElementById('publish-name').value;
var invalidCharacters = /[^A-Za-z0-9,-]/.exec(name);
// validate 'name'
// validate 'name' field
if (invalidCharacters) {
alert(invalidCharacters + ' is not allowed. A-Z, a-z, 0-9, and "-" only.');
return;
@ -91,10 +91,11 @@ document.getElementById('publish-submit').addEventListener('click', function(eve
alert("You must enter a name for your claim");
return;
}
// make sure a file was selected
if (stagedFiles) {
// make sure only 1 file was selected
if (stagedFiles.length > 1) {
if (!stagedFiles) {
alert("Please select a file");
return;
} else if (stagedFiles.length > 1) {
alert("Only one file is allowed at a time");
return;
}
@ -104,15 +105,27 @@ document.getElementById('publish-submit').addEventListener('click', function(eve
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;
return;
}
// make sure the name is available
var xhttp;
xhttp = new XMLHttpRequest();
xhttp.open('GET', '/api/isClaimAvailable/' + name, true);
xhttp.responseType = 'json';
xhttp.onreadystatechange = function() {
if (this.readyState == 4 ) {
if ( this.status == 200) {
console.log(this.response);
//uploader.submitFiles(stagedFiles);
} else {
alert("Please select a file");
console.log("request to check claim name failed with status:", this.status);
};
}
};
xhttp.send();
})
/* socketio-file-upload listeners */

View file

@ -9,14 +9,14 @@ const { postToStats, sendGoogleAnalytics } = require('../controllers/statsContro
module.exports = app => {
// route to run a claim_list request on the daemon
app.get('/api/claim_list/:claim', ({ ip, originalUrl, params }, res) => {
app.get('/api/claim_list/:name', ({ ip, originalUrl, params }, res) => {
// google analytics
sendGoogleAnalytics('serve', ip, originalUrl);
// log
logger.verbose(`GET request on ${originalUrl} from ${ip}`);
// serve the content
lbryApi
.getClaimsList(params.claim)
.getClaimsList(params.name)
.then(claimsList => {
postToStats('serve', originalUrl, ip, 'success');
res.status(200).json(claimsList);
@ -25,6 +25,24 @@ module.exports = app => {
errorHandlers.handleRequestError('publish', originalUrl, ip, error, res);
});
});
// route to check whether spee.ch has published to a claim
app.get('/api/isClaimAvailable/:name', ({ ip, originalUrl, params }, res) => {
// log
logger.verbose(`GET request on ${originalUrl} from ${ip}`);
// send response
publishController
.checkNameAvailability(params.name)
.then(result => {
if (result.length >= 1) {
res.status(200).json(false);
} else {
res.status(200).json(true);
}
})
.catch(error => {
res.status(500).json(error);
});
});
// route to run a resolve request on the daemon
app.get('/api/resolve/:uri', ({ ip, originalUrl, params }, res) => {
// google analytics