Connection string override #291

Merged
akinwale merged 2 commits from connection-string-override into master 2020-03-20 15:39:27 +01:00
3 changed files with 28 additions and 24 deletions
Showing only changes of commit 81f58e3ac7 - Show all commits

25
dist/bundle.es.js vendored
View file

@ -937,9 +937,9 @@ const Lbry = {
version: () => daemonCallWithResult('version', {}),
// Claim fetching and manipulation
resolve: params => daemonCallWithResult('resolve', params),
resolve: (params, connectionStringOverride = null) => daemonCallWithResult('resolve', params, connectionStringOverride),
get: params => daemonCallWithResult('get', params),
claim_search: params => daemonCallWithResult('claim_search', params),
claim_search: (params, connectionStringOverride = null) => daemonCallWithResult('claim_search', params, connectionStringOverride),
claim_list: params => daemonCallWithResult('claim_list', params),
channel_create: params => daemonCallWithResult('channel_create', params),
channel_update: params => daemonCallWithResult('channel_update', params),
@ -1039,7 +1039,7 @@ function checkAndParse(response) {
});
}
function apiCall(method, params, resolve, reject) {
function apiCall(method, params, resolve, reject, connectionStringOverride = null) {
const counter = new Date().getTime();
const options = {
method: 'POST',
@ -1052,7 +1052,8 @@ function apiCall(method, params, resolve, reject) {
})
};
return fetch(Lbry.daemonConnectionString + '?m=' + method, options).then(checkAndParse).then(response => {
const connectionString = connectionStringOverride ? connectionStringOverride : Lbry.daemonConnectionString;
return fetch(connectionString + '?m=' + method, options).then(checkAndParse).then(response => {
const error = response.error || response.result && response.result.error;
if (error) {
@ -1062,11 +1063,11 @@ function apiCall(method, params, resolve, reject) {
}).catch(reject);
}
function daemonCallWithResult(name, params = {}) {
function daemonCallWithResult(name, params = {}, connectionStringOverride = null) {
return new Promise((resolve, reject) => {
apiCall(name, params, result => {
resolve(result);
}, reject);
}, reject, connectionStringOverride);
});
}
@ -2870,7 +2871,7 @@ function batchActions(...actions) {
var _extends$5 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function doResolveUris(uris, returnCachedClaims = false) {
function doResolveUris(uris, returnCachedClaims = false, connectionStringOverride = null) {
return (dispatch, getState) => {
const normalizedUris = uris.map(normalizeURI);
const state = getState();
@ -2896,7 +2897,7 @@ function doResolveUris(uris, returnCachedClaims = false) {
const resolveInfo = {};
lbryProxy.resolve({ urls: urisToResolve }).then(result => {
lbryProxy.resolve({ urls: urisToResolve }, connectionStringOverride).then(result => {
Object.entries(result).forEach(([uri, uriResolveInfo]) => {
const fallbackResolveInfo = {
stream: null,
@ -2936,8 +2937,8 @@ function doResolveUris(uris, returnCachedClaims = false) {
};
}
function doResolveUri(uri) {
return doResolveUris([uri]);
function doResolveUri(uri, connectionStringOverride = null) {
return doResolveUris([uri], connectionStringOverride);
}
function doFetchClaimListMine(page = 1, pageSize = 99999, resolve = true) {
@ -3223,7 +3224,7 @@ function doClaimSearch(options = {
no_totals: true,
page_size: 10,
page: 1
}) {
}, connectionStringOverride = null) {
const query = createNormalizedClaimSearchKey(options);
return dispatch => {
dispatch({
@ -3259,7 +3260,7 @@ function doClaimSearch(options = {
});
};
lbryProxy.claim_search(options).then(success, failure);
lbryProxy.claim_search(options, connectionStringOverride).then(success, failure);
};
}

View file

@ -73,9 +73,9 @@ const Lbry: LbryTypes = {
version: () => daemonCallWithResult('version', {}),
// Claim fetching and manipulation
resolve: params => daemonCallWithResult('resolve', params),
resolve: (params, connectionStringOverride = null) => daemonCallWithResult('resolve', params, connectionStringOverride),
get: params => daemonCallWithResult('get', params),
claim_search: params => daemonCallWithResult('claim_search', params),
claim_search: (params, connectionStringOverride = null) => daemonCallWithResult('claim_search', params, connectionStringOverride),
claim_list: params => daemonCallWithResult('claim_list', params),
channel_create: params => daemonCallWithResult('channel_create', params),
channel_update: params => daemonCallWithResult('channel_update', params),
@ -178,7 +178,7 @@ function checkAndParse(response) {
});
}
export function apiCall(method: string, params: ?{}, resolve: Function, reject: Function) {
export function apiCall(method: string, params: ?{}, resolve: Function, reject: Function, connectionStringOverride = null) {
const counter = new Date().getTime();
const options = {
method: 'POST',
@ -191,7 +191,8 @@ export function apiCall(method: string, params: ?{}, resolve: Function, reject:
}),
};
return fetch(Lbry.daemonConnectionString + '?m=' + method, options)
const connectionString = connectionStringOverride ? connectionStringOverride : Lbry.daemonConnectionString;
return fetch(connectionString + '?m=' + method, options)
.then(checkAndParse)
.then(response => {
const error = response.error || (response.result && response.result.error);
@ -204,7 +205,7 @@ export function apiCall(method: string, params: ?{}, resolve: Function, reject:
.catch(reject);
}
function daemonCallWithResult(name: string, params: ?{} = {}) {
function daemonCallWithResult(name: string, params: ?{} = {}, connectionStringOverride = null) {
return new Promise((resolve, reject) => {
apiCall(
name,
@ -212,7 +213,8 @@ function daemonCallWithResult(name: string, params: ?{} = {}) {
result => {
resolve(result);
},
reject
reject,
connectionStringOverride
);
});
}

View file

@ -15,7 +15,7 @@ import { creditsToString } from 'util/format-credits';
import { batchActions } from 'util/batch-actions';
import { createNormalizedClaimSearchKey } from 'util/claim';
export function doResolveUris(uris: Array<string>, returnCachedClaims: boolean = false) {
export function doResolveUris(uris: Array<string>, returnCachedClaims: boolean = false, connectionStringOverride: string = null) {
return (dispatch: Dispatch, getState: GetState) => {
const normalizedUris = uris.map(normalizeURI);
const state = getState();
@ -47,7 +47,7 @@ export function doResolveUris(uris: Array<string>, returnCachedClaims: boolean =
},
} = {};
Lbry.resolve({ urls: urisToResolve }).then((result: ResolveResponse) => {
Lbry.resolve({ urls: urisToResolve }, connectionStringOverride).then((result: ResolveResponse) => {
Object.entries(result).forEach(([uri, uriResolveInfo]) => {
const fallbackResolveInfo = {
stream: null,
@ -90,8 +90,8 @@ export function doResolveUris(uris: Array<string>, returnCachedClaims: boolean =
};
}
export function doResolveUri(uri: string) {
return doResolveUris([uri]);
export function doResolveUri(uri: string, connectionStringOverride: string = null) {
return doResolveUris([uri], connectionStringOverride);
}
export function doFetchClaimListMine(
@ -426,7 +426,8 @@ export function doClaimSearch(
no_totals: true,
page_size: 10,
page: 1,
}
},
connectionStringOverride: string = null
) {
const query = createNormalizedClaimSearchKey(options);
return (dispatch: Dispatch) => {
@ -463,7 +464,7 @@ export function doClaimSearch(
});
};
Lbry.claim_search(options).then(success, failure);
Lbry.claim_search(options, connectionStringOverride).then(success, failure);
};
}