mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Modified to work with latest server code
This commit is contained in:
parent
9476edcbe2
commit
28928ead7c
5 changed files with 51 additions and 89 deletions
|
@ -5,21 +5,14 @@ export class QuickConnectSettings {
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
authorize(code) {
|
authorize(code) {
|
||||||
let url = ApiClient.getUrl('/QuickConnect/Authorize');
|
let url = ApiClient.getUrl('/QuickConnect/Authorize?Code=' + code);
|
||||||
ApiClient.ajax({
|
ApiClient.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: url,
|
url: url
|
||||||
data: {
|
|
||||||
'Code': code
|
|
||||||
}
|
|
||||||
}, true).then(() => {
|
}, true).then(() => {
|
||||||
require(['toast'], function (toast) {
|
toast(globalize.translate('QuickConnectAuthorizeSuccess'));
|
||||||
toast(globalize.translate('QuickConnectAuthorizeSuccess'));
|
|
||||||
});
|
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
require(['toast'], function (toast) {
|
toast(globalize.translate('QuickConnectAuthorizeFail'));
|
||||||
toast(globalize.translate('QuickConnectAuthorizeFail'));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// prevent bubbling
|
// prevent bubbling
|
||||||
|
@ -30,28 +23,16 @@ export class QuickConnectSettings {
|
||||||
let url = ApiClient.getUrl('/QuickConnect/Activate');
|
let url = ApiClient.getUrl('/QuickConnect/Activate');
|
||||||
return ApiClient.ajax({
|
return ApiClient.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: url,
|
url: url
|
||||||
contentType: 'application/json',
|
}).then(() => {
|
||||||
dataType: 'json'
|
|
||||||
}).then((json) => {
|
|
||||||
let message = json.Error;
|
|
||||||
|
|
||||||
if (message && message !== '') {
|
|
||||||
console.error('Error activating quick connect. Error: ', json.Error);
|
|
||||||
|
|
||||||
Dashboard.alert({
|
|
||||||
title: 'Unable to activate quick connect',
|
|
||||||
message: message
|
|
||||||
});
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
toast(globalize.translate('QuickConnectActivationSuccessful'));
|
toast(globalize.translate('QuickConnectActivationSuccessful'));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.error('Error activating quick connect. Error:', e);
|
console.error('Error activating quick connect. Error:', e);
|
||||||
|
Dashboard.alert({
|
||||||
|
title: globalize.translate('HeaderError'),
|
||||||
|
message: globalize.translate('DefaultErrorMessage')
|
||||||
|
});
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,10 @@ import loading from 'loading';
|
||||||
|
|
||||||
let newStatus = page.querySelector('#chkQuickConnectAvailable').checked ? 'Available' : 'Unavailable';
|
let newStatus = page.querySelector('#chkQuickConnectAvailable').checked ? 'Available' : 'Unavailable';
|
||||||
|
|
||||||
let url = ApiClient.getUrl('/QuickConnect/Available');
|
let url = ApiClient.getUrl('/QuickConnect/Available?Status=' + newStatus);
|
||||||
|
|
||||||
ApiClient.ajax({
|
ApiClient.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: {
|
|
||||||
'Status': newStatus
|
|
||||||
},
|
|
||||||
url: url
|
url: url
|
||||||
}, true).then(() => {
|
}, true).then(() => {
|
||||||
require(['toast'], function (toast) {
|
require(['toast'], function (toast) {
|
||||||
|
|
|
@ -154,71 +154,56 @@ import 'emby-checkbox';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Clicking ok on the code dialog redirects back to the homepage.
|
||||||
function loginQuickConnect() {
|
function loginQuickConnect() {
|
||||||
let apiClient = getApiClient();
|
let apiClient = getApiClient();
|
||||||
let friendlyName = navigator.userAgent;
|
|
||||||
|
|
||||||
let url = apiClient.getUrl('/QuickConnect/Initiate?FriendlyName=' + friendlyName);
|
let url = apiClient.getUrl('/QuickConnect/Initiate');
|
||||||
apiClient.getJSON(url)
|
apiClient.getJSON(url).then(function (json) {
|
||||||
.then(json => {
|
if (!json.Secret || !json.Code) {
|
||||||
if (!json.Secret || !json.Code) {
|
console.error('Malformed quick connect response', json);
|
||||||
console.error('Malformed quick connect response', json);
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Dashboard.alert({
|
Dashboard.alert({
|
||||||
message: Globalize.translate('QuickConnectAuthorizeCode', json.Code),
|
message: globalize.translate('QuickConnectAuthorizeCode', json.Code),
|
||||||
title: Globalize.translate('QuickConnect')
|
title: globalize.translate('QuickConnect')
|
||||||
});
|
});
|
||||||
|
|
||||||
loading.show();
|
let interval = setInterval(function() {
|
||||||
|
let connectUrl = apiClient.getUrl('/QuickConnect/Connect?Secret=' + json.Secret);
|
||||||
let interval = setInterval(async function() {
|
apiClient.getJSON(connectUrl).then(async function(data) {
|
||||||
try {
|
if (!data.Authenticated) {
|
||||||
let connectUrl = apiClient.getUrl('/QuickConnect/Connect?Secret=' + json.Secret);
|
return;
|
||||||
let data = await apiClient.getJSON(connectUrl);
|
|
||||||
if (data.Authenticated) {
|
|
||||||
let result = await apiClient.quickConnect(data.Authentication);
|
|
||||||
let user = result.User;
|
|
||||||
let serverId = getParameterByName('serverid');
|
|
||||||
let newUrl = 'home.html';
|
|
||||||
|
|
||||||
if (user.Policy.IsAdministrator && !serverId) {
|
|
||||||
newUrl = 'dashboard.html';
|
|
||||||
}
|
|
||||||
|
|
||||||
loading.hide();
|
|
||||||
Dashboard.onServerChanged(user.Id, result.AccessToken, apiClient);
|
|
||||||
Dashboard.navigate(newUrl);
|
|
||||||
clearInterval(interval);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
Dashboard.alert({
|
|
||||||
message: 'Quick connect was deactivated before the login request could be approved',
|
|
||||||
title: 'Unexpected error'
|
|
||||||
});
|
|
||||||
|
|
||||||
console.error('Unable to login with quick connect', e);
|
|
||||||
clearInterval(interval);
|
|
||||||
loading.hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
clearInterval(interval);
|
||||||
}, 5000);
|
|
||||||
|
|
||||||
return true;
|
let result = await apiClient.quickConnect(data.Authentication);
|
||||||
}).catch((e) => {
|
Dashboard.onServerChanged(result.User.Id, result.AccessToken, apiClient);
|
||||||
Dashboard.alert({
|
Dashboard.navigate('home.html');
|
||||||
message: Globalize.translate('QuickConnectNotActive'),
|
}, function (e) {
|
||||||
title: 'Error'
|
clearInterval(interval);
|
||||||
|
|
||||||
|
Dashboard.alert({
|
||||||
|
message: globalize.translate('QuickConnectDeactivated'),
|
||||||
|
title: globalize.translate('HeaderError')
|
||||||
|
});
|
||||||
|
|
||||||
|
console.error('Unable to login with quick connect', e);
|
||||||
});
|
});
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
console.error('Quick connect error: ', e);
|
return true;
|
||||||
|
}, function(e) {
|
||||||
return false;
|
Dashboard.alert({
|
||||||
|
message: globalize.translate('QuickConnectNotActive'),
|
||||||
|
title: globalize.translate('HeaderError')
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.error('Quick connect error: ', e);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
view.querySelector('#divUsers').addEventListener('click', function (e) {
|
view.querySelector('#divUsers').addEventListener('click', function (e) {
|
||||||
|
|
|
@ -73,6 +73,4 @@ export default function (view) {
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
renderPage();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1156,6 +1156,7 @@
|
||||||
"QuickConnectAuthorizeCode": "Authorize request {0} to continue",
|
"QuickConnectAuthorizeCode": "Authorize request {0} to continue",
|
||||||
"QuickConnectAuthorizeSuccess": "Request authorized",
|
"QuickConnectAuthorizeSuccess": "Request authorized",
|
||||||
"QuickConnectAuthorizeFail": "Unknown quick connect code",
|
"QuickConnectAuthorizeFail": "Unknown quick connect code",
|
||||||
|
"QuickConnectDeactivated": "Quick connect was deactivated before the login request could be approved",
|
||||||
"QuickConnectDescription": "To sign in with quick connect, select the Quick Connect button on the device you are logging in from and enter the displayed code below.",
|
"QuickConnectDescription": "To sign in with quick connect, select the Quick Connect button on the device you are logging in from and enter the displayed code below.",
|
||||||
"QuickConnectInvalidCode": "Invalid quick connect code",
|
"QuickConnectInvalidCode": "Invalid quick connect code",
|
||||||
"QuickConnectNotAvailable": "Ask your server administrator to enable quick connect",
|
"QuickConnectNotAvailable": "Ask your server administrator to enable quick connect",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue