2020-08-14 08:46:34 +02:00
|
|
|
import datetime from '../../scripts/datetime';
|
|
|
|
import loading from '../../components/loading/loading';
|
|
|
|
import dom from '../../scripts/dom';
|
|
|
|
import globalize from '../../scripts/globalize';
|
|
|
|
import '../../elements/emby-button/emby-button';
|
2020-10-18 15:18:15 +01:00
|
|
|
import confirm from '../../components/confirm/confirm';
|
2020-07-09 11:22:21 +01:00
|
|
|
|
|
|
|
/* eslint-disable indent */
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function revoke(page, key) {
|
2020-10-18 15:18:15 +01:00
|
|
|
confirm(globalize.translate('MessageConfirmRevokeApiKey'), globalize.translate('HeaderConfirmRevokeApiKey')).then(function () {
|
|
|
|
loading.show();
|
|
|
|
ApiClient.ajax({
|
|
|
|
type: 'DELETE',
|
|
|
|
url: ApiClient.getUrl('Auth/Keys/' + key)
|
|
|
|
}).then(function () {
|
|
|
|
loadData(page);
|
2019-06-10 15:25:07 -07:00
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderKeys(page, keys) {
|
2020-07-11 11:56:57 +01:00
|
|
|
const rows = keys.map(function (item) {
|
|
|
|
let html = '';
|
2019-11-06 13:43:39 +03:00
|
|
|
html += '<tr class="detailTableBodyRow detailTableBodyRow-shaded">';
|
|
|
|
html += '<td class="detailTableBodyCell">';
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '<button type="button" is="emby-button" data-token="' + item.AccessToken + '" class="raised raised-mini btnRevoke" data-mini="true" title="' + globalize.translate('ButtonRevoke') + '" style="margin:0;">' + globalize.translate('ButtonRevoke') + '</button>';
|
|
|
|
html += '</td>';
|
2019-11-06 13:43:39 +03:00
|
|
|
html += '<td class="detailTableBodyCell" style="vertical-align:middle;">';
|
|
|
|
html += item.AccessToken;
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '</td>';
|
2019-11-06 13:43:39 +03:00
|
|
|
html += '<td class="detailTableBodyCell" style="vertical-align:middle;">';
|
2020-05-04 12:44:12 +02:00
|
|
|
html += item.AppName || '';
|
|
|
|
html += '</td>';
|
2019-11-06 13:43:39 +03:00
|
|
|
html += '<td class="detailTableBodyCell" style="vertical-align:middle;">';
|
2020-07-11 11:56:57 +01:00
|
|
|
const date = datetime.parseISO8601Date(item.DateCreated, true);
|
2020-05-04 12:44:12 +02:00
|
|
|
html += datetime.toLocaleDateString(date) + ' ' + datetime.getDisplayTime(date);
|
|
|
|
html += '</td>';
|
|
|
|
return html += '</tr>';
|
|
|
|
}).join('');
|
|
|
|
page.querySelector('.resultBody').innerHTML = rows;
|
2019-06-10 15:25:07 -07:00
|
|
|
loading.hide();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadData(page) {
|
2019-06-10 15:25:07 -07:00
|
|
|
loading.show();
|
2020-05-04 12:44:12 +02:00
|
|
|
ApiClient.getJSON(ApiClient.getUrl('Auth/Keys')).then(function (result) {
|
2019-06-10 15:25:07 -07:00
|
|
|
renderKeys(page, result.Items);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function showNewKeyPrompt(page) {
|
2020-08-14 08:46:34 +02:00
|
|
|
import('../../components/prompt/prompt').then(({default: prompt}) => {
|
2018-10-23 01:05:09 +03:00
|
|
|
prompt({
|
2020-05-04 12:44:12 +02:00
|
|
|
title: globalize.translate('HeaderNewApiKey'),
|
|
|
|
label: globalize.translate('LabelAppName'),
|
|
|
|
description: globalize.translate('LabelAppNameExample')
|
2019-11-06 13:43:39 +03:00
|
|
|
}).then(function (value) {
|
2018-10-23 01:05:09 +03:00
|
|
|
ApiClient.ajax({
|
2020-05-04 12:44:12 +02:00
|
|
|
type: 'POST',
|
|
|
|
url: ApiClient.getUrl('Auth/Keys', {
|
2018-10-23 01:05:09 +03:00
|
|
|
App: value
|
|
|
|
})
|
2019-11-06 13:43:39 +03:00
|
|
|
}).then(function () {
|
|
|
|
loadData(page);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
pageIdOn('pageinit', 'apiKeysPage', function () {
|
2020-07-11 11:56:57 +01:00
|
|
|
const page = this;
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('.btnNewKey').addEventListener('click', function () {
|
2019-11-06 13:43:39 +03:00
|
|
|
showNewKeyPrompt(page);
|
2019-06-10 15:25:07 -07:00
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('.tblApiKeys').addEventListener('click', function (e) {
|
2020-07-11 11:56:57 +01:00
|
|
|
const btnRevoke = dom.parentWithClass(e.target, 'btnRevoke');
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
if (btnRevoke) {
|
2020-05-04 12:44:12 +02:00
|
|
|
revoke(page, btnRevoke.getAttribute('data-token'));
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
2019-06-10 15:25:07 -07:00
|
|
|
});
|
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
pageIdOn('pagebeforeshow', 'apiKeysPage', function () {
|
2019-06-10 15:25:07 -07:00
|
|
|
loadData(this);
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
2020-07-09 11:22:21 +01:00
|
|
|
|
|
|
|
/* eslint-enable indent */
|