mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Backport PR #7009
---------
**Commit 1:**
[url shortener] Use kibana.index config value, and fix silent error
* Original sha: 313bfc8ade
* Authored by Jim Unger <bigfunger@gmail.com> on 2016-04-21T21:22:58Z
This commit is contained in:
parent
d3e0e7a8e4
commit
635d4783e0
2 changed files with 18 additions and 8 deletions
|
@ -163,8 +163,12 @@ module.exports = function (kbnServer, server, config) {
|
|||
method: 'GET',
|
||||
path: '/goto/{urlId}',
|
||||
handler: async function (request, reply) {
|
||||
const url = await shortUrlLookup.getUrl(request.params.urlId);
|
||||
reply().redirect(config.get('server.basePath') + url);
|
||||
try {
|
||||
const url = await shortUrlLookup.getUrl(request.params.urlId);
|
||||
reply().redirect(config.get('server.basePath') + url);
|
||||
} catch (err) {
|
||||
reply(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -172,8 +176,12 @@ module.exports = function (kbnServer, server, config) {
|
|||
method: 'POST',
|
||||
path: '/shorten',
|
||||
handler: async function (request, reply) {
|
||||
const urlId = await shortUrlLookup.generateUrlId(request.payload.url);
|
||||
reply(urlId);
|
||||
try {
|
||||
const urlId = await shortUrlLookup.generateUrlId(request.payload.url);
|
||||
reply(urlId);
|
||||
} catch (err) {
|
||||
reply(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -3,10 +3,11 @@ const crypto = require('crypto');
|
|||
export default function (server) {
|
||||
async function updateMetadata(urlId, urlDoc) {
|
||||
const client = server.plugins.elasticsearch.client;
|
||||
const kibanaIndex = server.config().get('kibana.index');
|
||||
|
||||
try {
|
||||
await client.update({
|
||||
index: '.kibana',
|
||||
index: kibanaIndex,
|
||||
type: 'url',
|
||||
id: urlId,
|
||||
body: {
|
||||
|
@ -25,9 +26,10 @@ export default function (server) {
|
|||
async function getUrlDoc(urlId) {
|
||||
const urlDoc = await new Promise((resolve, reject) => {
|
||||
const client = server.plugins.elasticsearch.client;
|
||||
const kibanaIndex = server.config().get('kibana.index');
|
||||
|
||||
client.get({
|
||||
index: '.kibana',
|
||||
index: kibanaIndex,
|
||||
type: 'url',
|
||||
id: urlId
|
||||
})
|
||||
|
@ -45,9 +47,10 @@ export default function (server) {
|
|||
async function createUrlDoc(url, urlId) {
|
||||
const newUrlId = await new Promise((resolve, reject) => {
|
||||
const client = server.plugins.elasticsearch.client;
|
||||
const kibanaIndex = server.config().get('kibana.index');
|
||||
|
||||
client.index({
|
||||
index: '.kibana',
|
||||
index: kibanaIndex,
|
||||
type: 'url',
|
||||
id: urlId,
|
||||
body: {
|
||||
|
@ -79,7 +82,6 @@ export default function (server) {
|
|||
return {
|
||||
async generateUrlId(url) {
|
||||
const urlId = createUrlId(url);
|
||||
|
||||
const urlDoc = await getUrlDoc(urlId);
|
||||
if (urlDoc) return urlId;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue