update type

This commit is contained in:
Akinwale Ariwodola 2020-03-18 18:11:03 +01:00
parent 81f58e3ac7
commit 69ffd110db
5 changed files with 34 additions and 26 deletions

26
dist/bundle.es.js vendored
View file

@ -884,6 +884,8 @@ const Lbry = {
isConnected: false,
connectPromise: null,
daemonConnectionString: 'http://localhost:5279',
alternateConnectionString: '',
methodsUsingAlternateConnectionString: [],
apiRequestHeaders: { 'Content-Type': 'application/json-rpc' },
// Allow overriding daemon connection string (e.g. to `/api/proxy` for lbryweb)
@ -937,9 +939,9 @@ const Lbry = {
version: () => daemonCallWithResult('version', {}),
// Claim fetching and manipulation
resolve: (params, connectionStringOverride = null) => daemonCallWithResult('resolve', params, connectionStringOverride),
resolve: params => daemonCallWithResult('resolve', params),
get: params => daemonCallWithResult('get', params),
claim_search: (params, connectionStringOverride = null) => daemonCallWithResult('claim_search', params, connectionStringOverride),
claim_search: params => daemonCallWithResult('claim_search', params),
claim_list: params => daemonCallWithResult('claim_list', params),
channel_create: params => daemonCallWithResult('channel_create', params),
channel_update: params => daemonCallWithResult('channel_update', params),
@ -1039,7 +1041,7 @@ function checkAndParse(response) {
});
}
function apiCall(method, params, resolve, reject, connectionStringOverride = null) {
function apiCall(method, params, resolve, reject) {
const counter = new Date().getTime();
const options = {
method: 'POST',
@ -1052,7 +1054,7 @@ function apiCall(method, params, resolve, reject, connectionStringOverride = nul
})
};
const connectionString = connectionStringOverride ? connectionStringOverride : Lbry.daemonConnectionString;
const connectionString = Lbry.methodsUsingAlternateConnectionString.includes(method) ? Lbry.alternateConnectionString : Lbry.daemonConnectionString;
return fetch(connectionString + '?m=' + method, options).then(checkAndParse).then(response => {
const error = response.error || response.result && response.result.error;
@ -1063,11 +1065,11 @@ function apiCall(method, params, resolve, reject, connectionStringOverride = nul
}).catch(reject);
}
function daemonCallWithResult(name, params = {}, connectionStringOverride = null) {
function daemonCallWithResult(name, params = {}) {
return new Promise((resolve, reject) => {
apiCall(name, params, result => {
resolve(result);
}, reject, connectionStringOverride);
}, reject);
});
}
@ -2871,7 +2873,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, connectionStringOverride = null) {
function doResolveUris(uris, returnCachedClaims = false) {
return (dispatch, getState) => {
const normalizedUris = uris.map(normalizeURI);
const state = getState();
@ -2897,7 +2899,7 @@ function doResolveUris(uris, returnCachedClaims = false, connectionStringOverrid
const resolveInfo = {};
lbryProxy.resolve({ urls: urisToResolve }, connectionStringOverride).then(result => {
lbryProxy.resolve({ urls: urisToResolve }).then(result => {
Object.entries(result).forEach(([uri, uriResolveInfo]) => {
const fallbackResolveInfo = {
stream: null,
@ -2937,8 +2939,8 @@ function doResolveUris(uris, returnCachedClaims = false, connectionStringOverrid
};
}
function doResolveUri(uri, connectionStringOverride = null) {
return doResolveUris([uri], connectionStringOverride);
function doResolveUri(uri) {
return doResolveUris([uri]);
}
function doFetchClaimListMine(page = 1, pageSize = 99999, resolve = true) {
@ -3224,7 +3226,7 @@ function doClaimSearch(options = {
no_totals: true,
page_size: 10,
page: 1
}, connectionStringOverride = null) {
}) {
const query = createNormalizedClaimSearchKey(options);
return dispatch => {
dispatch({
@ -3260,7 +3262,7 @@ function doClaimSearch(options = {
});
};
lbryProxy.claim_search(options, connectionStringOverride).then(success, failure);
lbryProxy.claim_search(options).then(success, failure);
};
}

View file

@ -221,6 +221,8 @@ declare type LbryTypes = {
connectPromise: ?Promise<any>,
connect: () => void,
daemonConnectionString: string,
alternateConnectionString: string,
methodsUsingAlternateConnectionString: Array<string>,
apiRequestHeaders: { [key: string]: string },
setDaemonConnectionString: string => void,
setApiHeader: (string, string) => void,

2
flow-typed/Lbry.js vendored
View file

@ -221,6 +221,8 @@ declare type LbryTypes = {
connectPromise: ?Promise<any>,
connect: () => void,
daemonConnectionString: string,
alternateConnectionString: string,
methodsUsingAlternateConnectionString: Array<string>,
apiRequestHeaders: { [key: string]: string },
setDaemonConnectionString: string => void,
setApiHeader: (string, string) => void,

View file

@ -11,6 +11,8 @@ const Lbry: LbryTypes = {
isConnected: false,
connectPromise: null,
daemonConnectionString: 'http://localhost:5279',
alternateConnectionString: '',
methodsUsingAlternateConnectionString: [],
apiRequestHeaders: { 'Content-Type': 'application/json-rpc' },
// Allow overriding daemon connection string (e.g. to `/api/proxy` for lbryweb)
@ -73,9 +75,9 @@ const Lbry: LbryTypes = {
version: () => daemonCallWithResult('version', {}),
// Claim fetching and manipulation
resolve: (params, connectionStringOverride = null) => daemonCallWithResult('resolve', params, connectionStringOverride),
resolve: params => daemonCallWithResult('resolve', params),
get: params => daemonCallWithResult('get', params),
claim_search: (params, connectionStringOverride = null) => daemonCallWithResult('claim_search', params, connectionStringOverride),
claim_search: params => daemonCallWithResult('claim_search', params),
claim_list: params => daemonCallWithResult('claim_list', params),
channel_create: params => daemonCallWithResult('channel_create', params),
channel_update: params => daemonCallWithResult('channel_update', params),
@ -178,7 +180,7 @@ function checkAndParse(response) {
});
}
export function apiCall(method: string, params: ?{}, resolve: Function, reject: Function, connectionStringOverride = null) {
export function apiCall(method: string, params: ?{}, resolve: Function, reject: Function) {
const counter = new Date().getTime();
const options = {
method: 'POST',
@ -191,7 +193,9 @@ export function apiCall(method: string, params: ?{}, resolve: Function, reject:
}),
};
const connectionString = connectionStringOverride ? connectionStringOverride : Lbry.daemonConnectionString;
const connectionString = Lbry.methodsUsingAlternateConnectionString.includes(method)
? Lbry.alternateConnectionString
: Lbry.daemonConnectionString;
return fetch(connectionString + '?m=' + method, options)
.then(checkAndParse)
.then(response => {
@ -205,7 +209,7 @@ export function apiCall(method: string, params: ?{}, resolve: Function, reject:
.catch(reject);
}
function daemonCallWithResult(name: string, params: ?{} = {}, connectionStringOverride = null) {
function daemonCallWithResult(name: string, params: ?{} = {}) {
return new Promise((resolve, reject) => {
apiCall(
name,
@ -213,8 +217,7 @@ function daemonCallWithResult(name: string, params: ?{} = {}, connectionStringOv
result => {
resolve(result);
},
reject,
connectionStringOverride
reject
);
});
}

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, connectionStringOverride: string = null) {
export function doResolveUris(uris: Array<string>, returnCachedClaims: boolean = false) {
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 }, connectionStringOverride).then((result: ResolveResponse) => {
Lbry.resolve({ urls: urisToResolve }).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, connectionStringOverride: string = null) {
return doResolveUris([uri], connectionStringOverride);
export function doResolveUri(uri: string) {
return doResolveUris([uri]);
}
export function doFetchClaimListMine(
@ -426,8 +426,7 @@ export function doClaimSearch(
no_totals: true,
page_size: 10,
page: 1,
},
connectionStringOverride: string = null
}
) {
const query = createNormalizedClaimSearchKey(options);
return (dispatch: Dispatch) => {
@ -464,7 +463,7 @@ export function doClaimSearch(
});
};
Lbry.claim_search(options, connectionStringOverride).then(success, failure);
Lbry.claim_search(options).then(success, failure);
};
}