mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-31 12:10:19 -07:00
Initial Commit Rework
This commit is contained in:
parent
74a4cc048c
commit
95051cbd63
2483 changed files with 101351 additions and 111396 deletions
80
frontend/src/Store/Actions/oAuthActionHandlers.js
Normal file
80
frontend/src/Store/Actions/oAuthActionHandlers.js
Normal file
|
@ -0,0 +1,80 @@
|
|||
import _ from 'lodash';
|
||||
import $ from 'jquery';
|
||||
import requestAction from 'Utilities/requestAction';
|
||||
import * as types from './actionTypes';
|
||||
import { setOAuthValue } from './oAuthActions';
|
||||
|
||||
function showOAuthWindow(url) {
|
||||
const deferred = $.Deferred();
|
||||
const selfWindow = window;
|
||||
|
||||
window.open(url);
|
||||
|
||||
selfWindow.onCompleteOauth = function(query, callback) {
|
||||
delete selfWindow.onCompleteOauth;
|
||||
|
||||
const queryParams = {};
|
||||
const splitQuery = query.substring(1).split('&');
|
||||
|
||||
_.each(splitQuery, (param) => {
|
||||
const paramSplit = param.split('=');
|
||||
|
||||
queryParams[paramSplit[0]] = paramSplit[1];
|
||||
});
|
||||
|
||||
callback();
|
||||
deferred.resolve(queryParams);
|
||||
};
|
||||
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
const oAuthActionHandlers = {
|
||||
|
||||
[types.START_OAUTH]: function(payload) {
|
||||
return (dispatch, getState) => {
|
||||
const actionPayload = {
|
||||
action: 'startOAuth',
|
||||
queryParams: { callbackUrl: `${window.location.origin}/oauth.html` },
|
||||
...payload
|
||||
};
|
||||
|
||||
dispatch(setOAuthValue({
|
||||
authorizing: true
|
||||
}));
|
||||
|
||||
const promise = requestAction(actionPayload)
|
||||
.then((response) => {
|
||||
return showOAuthWindow(response.oauthUrl);
|
||||
})
|
||||
.then((queryParams) => {
|
||||
return requestAction({
|
||||
action: 'getOAuthToken',
|
||||
queryParams,
|
||||
...payload
|
||||
});
|
||||
})
|
||||
.then((response) => {
|
||||
const {
|
||||
accessToken,
|
||||
accessTokenSecret
|
||||
} = response;
|
||||
|
||||
dispatch(setOAuthValue({
|
||||
authorizing: false,
|
||||
accessToken,
|
||||
accessTokenSecret
|
||||
}));
|
||||
});
|
||||
|
||||
promise.fail(() => {
|
||||
dispatch(setOAuthValue({
|
||||
authorizing: false
|
||||
}));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export default oAuthActionHandlers;
|
Loading…
Add table
Add a link
Reference in a new issue