Development #287

Merged
bones7242 merged 58 commits from development into master 2017-12-11 20:53:02 +01:00
4 changed files with 9 additions and 10 deletions
Showing only changes of commit 5deaf7375d - Show all commits

View file

@ -26,8 +26,8 @@ spee.ch is a single-serving site that reads and publishes images and videos to a
#### GET
* /api/resolve/:name
* example: `curl https://spee.ch/api/resolve/doitlive`
* /api/claim_list/:name
* example: `curl https://spee.ch/api/claim_list/doitlive`
* /api/claim-list/:name
* example: `curl https://spee.ch/api/claim-list/doitlive`
* /api/isClaimAvailable/:name (returns `true`/`false` for whether a name is available through spee.ch)
* example: `curl https://spee.ch/api/isClaimAvailable/doitlive`

View file

@ -32,7 +32,7 @@ function createFileData ({ name, claimId, outpoint, height, address, nsfw, conte
module.exports = (app) => {
// route to run a claim_list request on the daemon
app.get('/api/claim_list/:name', ({ ip, originalUrl, params }, res) => {
app.get('/api/claim-list/:name', ({ ip, originalUrl, params }, res) => {
getClaimList(params.name)
.then(claimsList => {
postToStats('serve', originalUrl, ip, null, null, 'success');
@ -43,7 +43,7 @@ module.exports = (app) => {
});
});
// route to see if asset is available locally
app.get('/api/check_local_claim/:name/:claimId', ({ ip, originalUrl, params }, res) => {
app.get('/api/check-local-claim/:name/:claimId', ({ ip, originalUrl, params }, res) => {
const name = params.name;
const claimId = params.claimId;
let isLocalFileAvailable = false;
@ -59,7 +59,7 @@ module.exports = (app) => {
});
});
// route to get an asset
app.get('/api/get_claim/:name/:claimId', ({ ip, originalUrl, params }, res) => {
app.get('/api/get-claim/:name/:claimId', ({ ip, originalUrl, params }, res) => {
// resolve the claim
db.Claim.resolveClaim(params.name, params.claimId)
.then(resolveResult => {
@ -73,11 +73,10 @@ module.exports = (app) => {
})
.then(([ fileData, getResult ]) => {
fileData = addGetResultsToFileData(fileData, getResult);
return Promise.all([db.File.create(fileData), getResult]); // insert a record for the claim into the File table
return Promise.all([db.File.create(fileData), getResult]); // note: should be upsert
})
.then(([ fileRecord, {message, completed} ]) => {
res.status(200).json({ status: 'success', message, completed });
logger.debug('File record successfully created');
})
.catch(error => {
errorHandlers.handleApiError('get', originalUrl, ip, error, res);

View file

@ -200,7 +200,7 @@ function serveAssetToClient (claimId, name, res) {
.then(fileInfo => {
logger.debug('fileInfo:', fileInfo);
if (fileInfo === NO_FILE) {
res.status(307).redirect(`/api/get_claim/${name}/${claimId}`);
res.status(307).redirect(`/api/get-claim/${name}/${claimId}`);
} else {
return serveHelpers.serveFile(fileInfo, claimId, name, res);
}

View file

@ -67,7 +67,7 @@
},
checkClaimAvailability: function (claimName, claimId) {
console.log(`checking local availability for ${claimName}#${claimId}`)
var uri = `/api/check_local_claim/${claimName}/${claimId}`;
var uri = `/api/check-local-claim/${claimName}/${claimId}`;
var xhr = new XMLHttpRequest();
var that = this;
xhr.open("GET", uri, true);
@ -95,7 +95,7 @@
},
getAsset: function(claimName, claimId) {
console.log(`getting ${claimName}#${claimId}`)
var uri = `/api/get_claim/${claimName}/${claimId}`;
var uri = `/api/get-claim/${claimName}/${claimId}`;
var xhr = new XMLHttpRequest();
var that = this;
xhr.open("GET", uri, true);