This commit is contained in:
jessop 2019-09-30 16:11:45 -04:00 committed by Sean Yesmunt
parent 82658618d0
commit bd1d32e5d5
4 changed files with 36 additions and 20 deletions

View file

@ -0,0 +1,23 @@
import { HEADERS, Lbry } from 'lbry-redux';
import apiPublishCallViaWeb from './publish';
export const SDK_API_URL = process.env.SDK_API_URL || 'https://api.lbry.tv/api/v1/proxy';
Lbry.setDaemonConnectionString(SDK_API_URL);
Lbry.setOverride(
'publish',
params =>
new Promise((resolve, reject) => {
apiPublishCallViaWeb(
SDK_API_URL,
Lbry.getApiRequestHeaders() && Object.keys(Lbry.getApiRequestHeaders()).includes(HEADERS.AUTH_TOKEN)
? Lbry.getApiRequestHeaders()[HEADERS.AUTH_TOKEN]
: '',
'publish',
params,
resolve,
reject
);
})
);

View file

@ -1,7 +1,6 @@
// @flow
import { Lbry } from 'lbry-redux';
function checkAndParseFix(response) {
import { HEADERS } from 'lbry-redux';
function checkAndParse(response) {
if (response.status >= 200 && response.status < 300) {
return response.json();
}
@ -19,8 +18,9 @@ function checkAndParseFix(response) {
// A modified version of Lbry.apiCall that allows
// to perform calling methods at arbitrary urls
// and pass form file fields
function apiCallViaWeb(
export default function apiPublishCallViaWeb(
connectionString: string,
token: string,
method: string,
params: { file_path: string },
resolve: Function,
@ -42,11 +42,12 @@ function apiCallViaWeb(
body.append('json_payload', jsonPayload);
const options = {
method: 'POST',
headers: { [HEADERS.AUTH_TOKEN]: token },
body,
};
return fetch(connectionString, options)
.then(checkAndParseFix)
.then(checkAndParse)
.then(response => {
const error = response.error || (response.result && response.result.error);
@ -57,11 +58,3 @@ function apiCallViaWeb(
})
.catch(reject);
}
Lbry.setOverride(
'publish',
params =>
new Promise((resolve, reject) => {
apiCallViaWeb('/storage/content/', 'publish', params, resolve, reject);
})
);

View file

@ -12,7 +12,7 @@ import React, { Fragment, useState, useEffect } from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { doConditionalAuthNavigate, doDaemonReady, doAutoUpdate, doOpenModal, doHideModal } from 'redux/actions/app';
import { Lbry, doToast, isURIValid, setSearchApi } from 'lbry-redux';
import { doToast, isURIValid, setSearchApi } from 'lbry-redux';
import { doUpdateIsNightAsync } from 'redux/actions/settings';
import {
doAuthenticate,
@ -39,6 +39,10 @@ import 'scss/all.scss';
const startTime = Date.now();
analytics.startupEvent();
// @if TARGET='web'
import 'src/platforms/web/api-setup';
// @endif
const APPPAGEURL = 'lbry://?';
// @if TARGET='app'
const { autoUpdater } = remote.require('electron-updater');
@ -53,11 +57,6 @@ if (process.env.SEARCH_API_URL) {
setSearchApi(process.env.SEARCH_API_URL);
}
// @if TARGET='web'
const SDK_API_URL = process.env.SDK_API_URL || 'https://api.lbry.tv/api/v1/proxy';
Lbry.setDaemonConnectionString(SDK_API_URL);
// @endif
// We need to override Lbryio for getting/setting the authToken
// We interact with ipcRenderer to get the auth key from a users keyring
// We keep a local variable for authToken because `ipcRenderer.send` does not

View file

@ -16,6 +16,7 @@ import {
makeSelectClaimIsMine,
doPopulateSharedUserState,
doFetchChannelListMine,
HEADERS,
doClearPublish,
doPreferenceGet,
doToast,
@ -437,7 +438,7 @@ export function doSignIn() {
return (dispatch, getState) => {
// @if TARGET='web'
const authToken = getAuthToken();
Lbry.setApiHeader('X-Lbry-Auth-Token', authToken);
Lbry.setApiHeader(HEADERS.AUTH_TOKEN, authToken);
dispatch(doBalanceSubscribe());
dispatch(doFetchChannelListMine());
// @endif