added api routes for getting short ids
This commit is contained in:
parent
bd2a48f883
commit
65b5384330
5 changed files with 34 additions and 4 deletions
|
@ -150,7 +150,7 @@ module.exports = {
|
||||||
// 2. get all claims for that channel
|
// 2. get all claims for that channel
|
||||||
.then(result => {
|
.then(result => {
|
||||||
longChannelId = result;
|
longChannelId = result;
|
||||||
return db.getShortChannelIdFromLongChannelId(channelName, longChannelId);
|
return db.getShortChannelIdFromLongChannelId(longChannelId, channelName);
|
||||||
})
|
})
|
||||||
// 3. get all Claim records for this channel
|
// 3. get all Claim records for this channel
|
||||||
.then(result => {
|
.then(result => {
|
||||||
|
|
|
@ -190,7 +190,7 @@ db['getShortClaimIdFromLongClaimId'] = (claimId, claimName) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
db['getShortChannelIdFromLongChannelId'] = (channelName, longChannelId) => {
|
db['getShortChannelIdFromLongChannelId'] = (longChannelId, channelName) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
logger.debug('finding short channel id');
|
logger.debug('finding short channel id');
|
||||||
db
|
db
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
const multipart = require('connect-multiparty');
|
const multipart = require('connect-multiparty');
|
||||||
const multipartMiddleware = multipart();
|
const multipartMiddleware = multipart();
|
||||||
|
const db = require('../models');
|
||||||
const { publish } = require('../controllers/publishController.js');
|
const { publish } = require('../controllers/publishController.js');
|
||||||
const { getClaimList, resolveUri } = require('../helpers/lbryApi.js');
|
const { getClaimList, resolveUri } = require('../helpers/lbryApi.js');
|
||||||
const { createPublishParams, validateFile, checkClaimNameAvailability, checkChannelAvailability } = require('../helpers/publishHelpers.js');
|
const { createPublishParams, validateFile, checkClaimNameAvailability, checkChannelAvailability } = require('../helpers/publishHelpers.js');
|
||||||
|
@ -69,7 +70,6 @@ module.exports = (app) => {
|
||||||
errorHandlers.handleRequestError('publish', originalUrl, ip, error, res);
|
errorHandlers.handleRequestError('publish', originalUrl, ip, error, res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// route to run a publish request on the daemon
|
// route to run a publish request on the daemon
|
||||||
app.post('/api/publish', multipartMiddleware, ({ body, files, headers, ip, originalUrl }, res) => {
|
app.post('/api/publish', multipartMiddleware, ({ body, files, headers, ip, originalUrl }, res) => {
|
||||||
// google analytics
|
// google analytics
|
||||||
|
@ -104,9 +104,11 @@ module.exports = (app) => {
|
||||||
}
|
}
|
||||||
return createPublishParams(name, filePath, title, description, license, nsfw, channelName);
|
return createPublishParams(name, filePath, title, description, license, nsfw, channelName);
|
||||||
})
|
})
|
||||||
|
// create publish parameters object
|
||||||
.then(publishParams => {
|
.then(publishParams => {
|
||||||
return publish(publishParams, fileName, fileType);
|
return publish(publishParams, fileName, fileType);
|
||||||
})
|
})
|
||||||
|
// publish the asset
|
||||||
.then(result => {
|
.then(result => {
|
||||||
postToStats('publish', originalUrl, ip, null, null, 'success');
|
postToStats('publish', originalUrl, ip, null, null, 'success');
|
||||||
res.status(200).json(result);
|
res.status(200).json(result);
|
||||||
|
@ -115,4 +117,28 @@ module.exports = (app) => {
|
||||||
logger.error('publish api error', error);
|
logger.error('publish api error', error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
// route to get a short claim id from long claim Id
|
||||||
|
app.get('/api/shortClaimId/:longId/:name', ({ originalUrl, ip, params }, res) => {
|
||||||
|
// serve content
|
||||||
|
db.getShortClaimIdFromLongClaimId(params.longId, params.name)
|
||||||
|
.then(shortId => {
|
||||||
|
res.status(200).json(shortId);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
logger.error('api error getting short channel id', error);
|
||||||
|
res.status(400).json(error.message);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// route to get a short channel id from long channel Id
|
||||||
|
app.get('/api/shortChannelId/:longId/:name', ({ params }, res) => {
|
||||||
|
// serve content
|
||||||
|
db.getShortChannelIdFromLongChannelId(params.longId, params.name)
|
||||||
|
.then(shortId => {
|
||||||
|
res.status(200).json(shortId);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
logger.error('api error getting short channel id', error);
|
||||||
|
res.status(400).json(error.message);
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -55,6 +55,9 @@
|
||||||
if (selectedOption === 'none'){
|
if (selectedOption === 'none'){
|
||||||
urlChannel.innerText = '';
|
urlChannel.innerText = '';
|
||||||
} else {
|
} else {
|
||||||
|
// retrieve short url from db
|
||||||
|
|
||||||
|
// update url text
|
||||||
urlChannel.innerText = `${selectedOption}/`;
|
urlChannel.innerText = `${selectedOption}/`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,4 +10,5 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue