updated route names

This commit is contained in:
bill bittner 2017-11-29 12:41:53 -08:00
parent 8bdbf05251
commit 5deaf7375d
4 changed files with 9 additions and 10 deletions

View file

@ -26,8 +26,8 @@ spee.ch is a single-serving site that reads and publishes images and videos to a
#### GET #### GET
* /api/resolve/:name * /api/resolve/:name
* example: `curl https://spee.ch/api/resolve/doitlive` * example: `curl https://spee.ch/api/resolve/doitlive`
* /api/claim_list/:name * /api/claim-list/:name
* example: `curl https://spee.ch/api/claim_list/doitlive` * example: `curl https://spee.ch/api/claim-list/doitlive`
* /api/isClaimAvailable/:name (returns `true`/`false` for whether a name is available through spee.ch) * /api/isClaimAvailable/:name (returns `true`/`false` for whether a name is available through spee.ch)
* example: `curl https://spee.ch/api/isClaimAvailable/doitlive` * 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) => { module.exports = (app) => {
// route to run a claim_list request on the daemon // 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) getClaimList(params.name)
.then(claimsList => { .then(claimsList => {
postToStats('serve', originalUrl, ip, null, null, 'success'); postToStats('serve', originalUrl, ip, null, null, 'success');
@ -43,7 +43,7 @@ module.exports = (app) => {
}); });
}); });
// route to see if asset is available locally // 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 name = params.name;
const claimId = params.claimId; const claimId = params.claimId;
let isLocalFileAvailable = false; let isLocalFileAvailable = false;
@ -59,7 +59,7 @@ module.exports = (app) => {
}); });
}); });
// route to get an asset // 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 // resolve the claim
db.Claim.resolveClaim(params.name, params.claimId) db.Claim.resolveClaim(params.name, params.claimId)
.then(resolveResult => { .then(resolveResult => {
@ -73,11 +73,10 @@ module.exports = (app) => {
}) })
.then(([ fileData, getResult ]) => { .then(([ fileData, getResult ]) => {
fileData = addGetResultsToFileData(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} ]) => { .then(([ fileRecord, {message, completed} ]) => {
res.status(200).json({ status: 'success', message, completed }); res.status(200).json({ status: 'success', message, completed });
logger.debug('File record successfully created');
}) })
.catch(error => { .catch(error => {
errorHandlers.handleApiError('get', originalUrl, ip, error, res); errorHandlers.handleApiError('get', originalUrl, ip, error, res);

View file

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

View file

@ -67,7 +67,7 @@
}, },
checkClaimAvailability: function (claimName, claimId) { checkClaimAvailability: function (claimName, claimId) {
console.log(`checking local availability for ${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 xhr = new XMLHttpRequest();
var that = this; var that = this;
xhr.open("GET", uri, true); xhr.open("GET", uri, true);
@ -95,7 +95,7 @@
}, },
getAsset: function(claimName, claimId) { getAsset: function(claimName, claimId) {
console.log(`getting ${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 xhr = new XMLHttpRequest();
var that = this; var that = this;
xhr.open("GET", uri, true); xhr.open("GET", uri, true);