This commit is contained in:
zeppi 2021-09-16 15:50:37 -04:00
parent 783d7d2d73
commit 22906b5857
3 changed files with 11 additions and 274 deletions

87
dist/bundle.es.js vendored
View file

@ -219,7 +219,8 @@ const Lbryio = {
CONNECTION_STRING: 'https://api.lbry.com/' CONNECTION_STRING: 'https://api.lbry.com/'
}; };
const EXCHANGE_RATE_TIMEOUT = 20 * 60 * 1000; const EXCHANGE_RATE_TIMEOUT = 20 * 60 * 1000;
const INTERNAL_APIS_DOWN = 'internal_apis_down'; // We can't use env's because they aren't passed into node_modules const INTERNAL_APIS_DOWN = 'internal_apis_down';
Lbryio.fetchingUser = false; // We can't use env's because they aren't passed into node_modules
Lbryio.setLocalApi = endpoint => { Lbryio.setLocalApi = endpoint => {
Lbryio.CONNECTION_STRING = endpoint.replace(/\/*$/, '/'); // exactly one slash at the end; Lbryio.CONNECTION_STRING = endpoint.replace(/\/*$/, '/'); // exactly one slash at the end;
@ -260,11 +261,10 @@ Lbryio.call = (resource, action, params = {}, method = 'get') => {
function makeRequest(url, options) { function makeRequest(url, options) {
return fetch(url, options).then(checkAndParse); return fetch(url, options).then(checkAndParse);
} // TOKENS = { auth_token, access_token } }
return Lbryio.getTokens().then(tokens => { return Lbryio.getTokens().then(tokens => {
// string -=> { auth_token: xyz, authorization: abc } // TOKENS = { auth_token, access_token }
const fullParams = { ...params const fullParams = { ...params
}; };
const headers = { const headers = {
@ -315,12 +315,8 @@ Lbryio.call = (resource, action, params = {}, method = 'get') => {
}); });
}; };
Lbryio.fetchingUser = false; // Lbryio.authToken = null;
Lbryio.getAuthToken = () => new Promise(resolve => { Lbryio.getAuthToken = () => new Promise(resolve => {
Lbryio.overrides.getAuthToken().then(token => { Lbryio.overrides.getAuthToken().then(token => {
// now { auth_token: <token>, authorization: <token> }
// Lbryio.authTokens = token;
resolve(token); resolve(token);
}); });
}); });
@ -384,81 +380,6 @@ Lbryio.fetchNewUser = async (domain, language) => {
} }
}; };
Lbryio.authenticate = (domain, language) => {
if (!Lbryio.enabled) {
const params = {
id: 1,
primary_email: 'disabled@lbry.io',
has_verified_email: true,
is_identity_verified: true,
is_reward_approved: false,
language: language || 'en'
};
return new Promise(resolve => {
resolve(params);
});
}
if (Lbryio.authenticationPromise === null) {
Lbryio.authenticationPromise = new Promise((resolve, reject) => {
// see if we already have a token
Lbryio.getTokens().then(tokens => {
if (!tokens) {
return false;
} // check that token works
return Lbryio.fetchCurrentUser().then(user => user).catch(error => {
if (error === INTERNAL_APIS_DOWN) {
throw new Error('Internal APIS down');
}
return false;
});
}).then(user => {
if (user) {
return user;
}
return lbryRedux.Lbry.status().then(status => new Promise((res, rej) => {
const appId = domain && domain !== 'lbry.tv' ? (domain.replace(/[.]/gi, '') + status.installation_id).slice(0, 66) : status.installation_id;
Lbryio.call('user', 'new', {
auth_token: '',
language: language || 'en',
app_id: appId
}, 'post').then(response => {
if (!response.auth_token) {
throw new Error('auth_token was not set in the response');
} // const { store } = window;
// Not setting new "auth_tokens"
// if (Lbryio.overrides.setAuthToken) {
// Lbryio.overrides.setAuthToken(response.auth_token);
// }
// if (store) {
// store.dispatch({
// type: ACTIONS.GENERATE_AUTH_TOKEN_SUCCESS,
// data: { authToken: response.auth_token },
// });
// }
// Lbryio.authToken = response.auth_token;
return res(response);
}).catch(error => rej(error));
})).then(newUser => {
if (!newUser) {
return Lbryio.fetchCurrentUser();
}
return newUser;
});
}).then(resolve, reject);
});
}
return Lbryio.authenticationPromise;
};
Lbryio.getStripeToken = () => Lbryio.CONNECTION_STRING.startsWith('http://localhost:') ? 'pk_test_NoL1JWL7i1ipfhVId5KfDZgo' : 'pk_live_e8M4dRNnCCbmpZzduEUZBgJO'; Lbryio.getStripeToken = () => Lbryio.CONNECTION_STRING.startsWith('http://localhost:') ? 'pk_test_NoL1JWL7i1ipfhVId5KfDZgo' : 'pk_live_e8M4dRNnCCbmpZzduEUZBgJO';
Lbryio.getExchangeRates = () => { Lbryio.getExchangeRates = () => {

93
dist/bundle.js vendored
View file

@ -523,7 +523,8 @@ var Lbryio = {
CONNECTION_STRING: 'https://api.lbry.com/' CONNECTION_STRING: 'https://api.lbry.com/'
}; };
var EXCHANGE_RATE_TIMEOUT = 20 * 60 * 1000; var EXCHANGE_RATE_TIMEOUT = 20 * 60 * 1000;
var INTERNAL_APIS_DOWN = 'internal_apis_down'; // We can't use env's because they aren't passed into node_modules var INTERNAL_APIS_DOWN = 'internal_apis_down';
Lbryio.fetchingUser = false; // We can't use env's because they aren't passed into node_modules
Lbryio.setLocalApi = function (endpoint) { Lbryio.setLocalApi = function (endpoint) {
Lbryio.CONNECTION_STRING = endpoint.replace(/\/*$/, '/'); // exactly one slash at the end; Lbryio.CONNECTION_STRING = endpoint.replace(/\/*$/, '/'); // exactly one slash at the end;
@ -567,11 +568,10 @@ Lbryio.call = function (resource, action) {
function makeRequest(url, options) { function makeRequest(url, options) {
return fetch(url, options).then(checkAndParse); return fetch(url, options).then(checkAndParse);
} // TOKENS = { auth_token, access_token } }
return Lbryio.getTokens().then(function (tokens) { return Lbryio.getTokens().then(function (tokens) {
// string -=> { auth_token: xyz, authorization: abc } // TOKENS = { auth_token, access_token }
var fullParams = _objectSpread({}, params); var fullParams = _objectSpread({}, params);
var headers = { var headers = {
@ -624,13 +624,9 @@ Lbryio.call = function (resource, action) {
}); });
}; };
Lbryio.fetchingUser = false; // Lbryio.authToken = null;
Lbryio.getAuthToken = function () { Lbryio.getAuthToken = function () {
return new Promise(function (resolve) { return new Promise(function (resolve) {
Lbryio.overrides.getAuthToken().then(function (token) { Lbryio.overrides.getAuthToken().then(function (token) {
// now { auth_token: <token>, authorization: <token> }
// Lbryio.authTokens = token;
resolve(token); resolve(token);
}); });
}); });
@ -790,87 +786,6 @@ function () {
}; };
}(); }();
Lbryio.authenticate = function (domain, language) {
if (!Lbryio.enabled) {
var params = {
id: 1,
primary_email: 'disabled@lbry.io',
has_verified_email: true,
is_identity_verified: true,
is_reward_approved: false,
language: language || 'en'
};
return new Promise(function (resolve) {
resolve(params);
});
}
if (Lbryio.authenticationPromise === null) {
Lbryio.authenticationPromise = new Promise(function (resolve, reject) {
// see if we already have a token
Lbryio.getTokens().then(function (tokens) {
if (!tokens) {
return false;
} // check that token works
return Lbryio.fetchCurrentUser().then(function (user) {
return user;
})["catch"](function (error) {
if (error === INTERNAL_APIS_DOWN) {
throw new Error('Internal APIS down');
}
return false;
});
}).then(function (user) {
if (user) {
return user;
}
return lbry_redux__WEBPACK_IMPORTED_MODULE_0__["Lbry"].status().then(function (status) {
return new Promise(function (res, rej) {
var appId = domain && domain !== 'lbry.tv' ? (domain.replace(/[.]/gi, '') + status.installation_id).slice(0, 66) : status.installation_id;
Lbryio.call('user', 'new', {
auth_token: '',
language: language || 'en',
app_id: appId
}, 'post').then(function (response) {
if (!response.auth_token) {
throw new Error('auth_token was not set in the response');
} // const { store } = window;
// Not setting new "auth_tokens"
// if (Lbryio.overrides.setAuthToken) {
// Lbryio.overrides.setAuthToken(response.auth_token);
// }
// if (store) {
// store.dispatch({
// type: ACTIONS.GENERATE_AUTH_TOKEN_SUCCESS,
// data: { authToken: response.auth_token },
// });
// }
// Lbryio.authToken = response.auth_token;
return res(response);
})["catch"](function (error) {
return rej(error);
});
});
}).then(function (newUser) {
if (!newUser) {
return Lbryio.fetchCurrentUser();
}
return newUser;
});
}).then(resolve, reject);
});
}
return Lbryio.authenticationPromise;
};
Lbryio.getStripeToken = function () { Lbryio.getStripeToken = function () {
return Lbryio.CONNECTION_STRING.startsWith('http://localhost:') ? 'pk_test_NoL1JWL7i1ipfhVId5KfDZgo' : 'pk_live_e8M4dRNnCCbmpZzduEUZBgJO'; return Lbryio.CONNECTION_STRING.startsWith('http://localhost:') ? 'pk_test_NoL1JWL7i1ipfhVId5KfDZgo' : 'pk_live_e8M4dRNnCCbmpZzduEUZBgJO';
}; };

View file

@ -12,6 +12,7 @@ const Lbryio = {
const EXCHANGE_RATE_TIMEOUT = 20 * 60 * 1000; const EXCHANGE_RATE_TIMEOUT = 20 * 60 * 1000;
const INTERNAL_APIS_DOWN = 'internal_apis_down'; const INTERNAL_APIS_DOWN = 'internal_apis_down';
Lbryio.fetchingUser = false;
// We can't use env's because they aren't passed into node_modules // We can't use env's because they aren't passed into node_modules
Lbryio.setLocalApi = endpoint => { Lbryio.setLocalApi = endpoint => {
Lbryio.CONNECTION_STRING = endpoint.replace(/\/*$/, '/'); // exactly one slash at the end; Lbryio.CONNECTION_STRING = endpoint.replace(/\/*$/, '/'); // exactly one slash at the end;
@ -51,9 +52,9 @@ Lbryio.call = (resource, action, params = {}, method = 'get') => {
function makeRequest(url, options) { function makeRequest(url, options) {
return fetch(url, options).then(checkAndParse); return fetch(url, options).then(checkAndParse);
} }
// TOKENS = { auth_token, access_token }
return Lbryio.getTokens().then(tokens => { return Lbryio.getTokens().then(tokens => {
// string -=> { auth_token: xyz, authorization: abc } // TOKENS = { auth_token, access_token }
const fullParams = { ...params }; const fullParams = { ...params };
const headers = { const headers = {
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
@ -105,13 +106,9 @@ Lbryio.call = (resource, action, params = {}, method = 'get') => {
}); });
}; };
Lbryio.fetchingUser = false;
// Lbryio.authToken = null;
Lbryio.getAuthToken = () => Lbryio.getAuthToken = () =>
new Promise(resolve => { new Promise(resolve => {
Lbryio.overrides.getAuthToken().then(token => { Lbryio.overrides.getAuthToken().then(token => {
// now { auth_token: <token>, authorization: <token> }
// Lbryio.authTokens = token;
resolve(token); resolve(token);
}); });
}); });
@ -180,102 +177,6 @@ Lbryio.fetchNewUser = async (domain, language) => {
} }
}; };
Lbryio.authenticate = (domain, language) => {
if (!Lbryio.enabled) {
const params = {
id: 1,
primary_email: 'disabled@lbry.io',
has_verified_email: true,
is_identity_verified: true,
is_reward_approved: false,
language: language || 'en',
};
return new Promise(resolve => {
resolve(params);
});
}
if (Lbryio.authenticationPromise === null) {
Lbryio.authenticationPromise = new Promise((resolve, reject) => {
// see if we already have a token
Lbryio.getTokens()
.then(tokens => {
if (!tokens) {
return false;
}
// check that token works
return Lbryio.fetchCurrentUser()
.then(user => user)
.catch(error => {
if (error === INTERNAL_APIS_DOWN) {
throw new Error('Internal APIS down');
}
return false;
});
})
.then(user => {
if (user) {
return user;
}
return Lbry.status()
.then(
status =>
new Promise((res, rej) => {
const appId =
domain && domain !== 'lbry.tv'
? (domain.replace(/[.]/gi, '') + status.installation_id).slice(0, 66)
: status.installation_id;
Lbryio.call(
'user',
'new',
{
auth_token: '',
language: language || 'en',
app_id: appId,
},
'post'
)
.then(response => {
if (!response.auth_token) {
throw new Error('auth_token was not set in the response');
}
// const { store } = window;
// Not setting new "auth_tokens"
// if (Lbryio.overrides.setAuthToken) {
// Lbryio.overrides.setAuthToken(response.auth_token);
// }
// if (store) {
// store.dispatch({
// type: ACTIONS.GENERATE_AUTH_TOKEN_SUCCESS,
// data: { authToken: response.auth_token },
// });
// }
// Lbryio.authToken = response.auth_token;
return res(response);
})
.catch(error => rej(error));
})
)
.then(newUser => {
if (!newUser) {
return Lbryio.fetchCurrentUser();
}
return newUser;
});
})
.then(resolve, reject);
});
}
return Lbryio.authenticationPromise;
};
Lbryio.getStripeToken = () => Lbryio.getStripeToken = () =>
Lbryio.CONNECTION_STRING.startsWith('http://localhost:') Lbryio.CONNECTION_STRING.startsWith('http://localhost:')
? 'pk_test_NoL1JWL7i1ipfhVId5KfDZgo' ? 'pk_test_NoL1JWL7i1ipfhVId5KfDZgo'