diff --git a/helpers/errorHandlers.js b/helpers/errorHandlers.js index e170a9aa..8077cfa3 100644 --- a/helpers/errorHandlers.js +++ b/helpers/errorHandlers.js @@ -5,25 +5,25 @@ module.exports = { let status, message; // check for daemon being turned off if (error.code === 'ECONNREFUSED') { - status = 503; + status = 200; message = 'Connection refused. The daemon may not be running.'; - // check for errors from the daemon - } else if (error.response) { - status = error.response.status || 500; - if (error.response.data) { - if (error.response.data.message) { - message = error.response.data.message; - } else if (error.response.data.error) { - message = error.response.data.error.message; - } else { - message = error.response.data; - } - } else { - message = error.response; - } + // // check for errors from the daemon + // } else if (error.response) { + // status = error.response.status || 500; + // if (error.response.data) { + // if (error.response.data.message) { + // message = error.response.data.message; + // } else if (error.response.data.error) { + // message = error.response.data.error.message; + // } else { + // message = error.response.data; + // } + // } else { + // message = error.response; + // } // check for thrown errors } else if (error.message) { - status = 400; + status = 200; message = error.message; // fallback for everything else } else { diff --git a/helpers/lbryApi.js b/helpers/lbryApi.js index 25ee96cd..ac4c3280 100644 --- a/helpers/lbryApi.js +++ b/helpers/lbryApi.js @@ -10,13 +10,13 @@ function handleLbrynetResponse ({ data }, resolve, reject) { // check for an error if (data.result.error) { logger.debug('Lbrynet api error:', data.result.error); - reject(data.result.error); + reject(new Error(data.result.error)); return; }; resolve(data.result); return; } - // fallback in case the just timed out + // fallback in case it just timed out reject(JSON.stringify(data)); } diff --git a/react/actions/show.js b/react/actions/show.js index 1db4e443..ed30d7c2 100644 --- a/react/actions/show.js +++ b/react/actions/show.js @@ -19,29 +19,3 @@ export function updateRequestWithAssetRequest (name, id, channelName, channelId, extension, }; }; - -export function updateChannelData (name, longId, shortId) { - return { - type: actions.CHANNEL_DATA_UPDATE, - name, - longId, - shortId, - }; -}; - -export function updateChannelClaimsData (claims, currentPage, totalPages, totalClaims) { - return { - type: actions.CHANNEL_CLAIMS_DATA_UPDATE, - claims, - currentPage, - totalPages, - totalClaims, - }; -}; - -export function updateAssetData (data) { - return { - type: actions.ASSET_DATA_UPDATE, - data, - }; -}; diff --git a/react/components/AssetDisplay/index.js b/react/components/AssetDisplay/index.js index 8a0ed5cc..0917c260 100644 --- a/react/components/AssetDisplay/index.js +++ b/react/components/AssetDisplay/index.js @@ -39,9 +39,12 @@ class AssetDisplay extends React.Component { const url = `/api/file-is-available/${this.props.name}/${this.props.claimId}`; return new Promise((resolve, reject) => { Request(url) - .then(isAvailable => { - console.log('/api/file-is-available response:', isAvailable); - resolve(isAvailable); + .then(({success, message, data: isAvailable}) => { + if (success) { + console.log('/api/file-is-available response:', isAvailable); + return resolve(isAvailable); + } + reject(new Error(message)); }) .catch(error => { reject(error); @@ -53,9 +56,12 @@ class AssetDisplay extends React.Component { const url = `/api/claim-get/${this.props.name}/${this.props.claimId}`; return new Promise((resolve, reject) => { Request(url) - .then(response => { - console.log('/api/claim-get response:', response); - resolve(true); + .then(({success, message}) => { + console.log('/api/claim-get response:', success, message); + if (success) { + return resolve(true); + } + reject(new Error(message)); }) .catch(error => { reject(error); @@ -65,6 +71,11 @@ class AssetDisplay extends React.Component { render () { return (
+ {(this.state.status === LOCAL_CHECK) && +
+

Checking to see if Spee.ch has your asset locally...

+
+ } {(this.state.status === SEARCHING) &&

Sit tight, we're searching the LBRY blockchain for your asset!

diff --git a/react/components/ChannelClaimsDisplay/index.js b/react/components/ChannelClaimsDisplay/index.js new file mode 100644 index 00000000..8af9ca24 --- /dev/null +++ b/react/components/ChannelClaimsDisplay/index.js @@ -0,0 +1,79 @@ +import React from 'react/index'; +import AssetPreview from 'components/AssetPreview'; +import request from 'utils/request'; + +class ChannelClaimsDisplay extends React.Component { + constructor (props) { + super(props); + this.state = { + error : null, + claims : null, + currentPage: null, + totalPages : null, + totalClaims: null, + }; + this.updateClaimsData = this.updateClaimsData.bind(this); + } + componentDidMount () { + this.updateClaimsData(1); + } + updateClaimsData (page) { + const name = this.props.name; + const longId = this.props.longId; + const url = `/api/channel-claims/${name}/${longId}/${page}`; + const that = this; + return request(url) + .then(({ success, message, data }) => { + console.log('api/channel-claims response:', data); + if (!success) { + return that.setState({error: message}); + } + this.setState({ + claims : data.claims, + currentPage: data.currentPage, + totalPages : data.totalPages, + totalClaims: data.totalResults, + }); + }) + .catch((error) => { + that.setState({error: error.message}); + }); + } + render () { + return ( +
+ {this.state.error ? ( +
+
+

{this.state.error}

+
+
+ ) : ( +
+

total pages: {this.state.totalPages}

+

total claims: {this.state.totalClaims}

+ {this.state.claims && +
+ {this.state.claims.map((claim, index) => )} + {(this.state.currentPage > 1) && } +

current page: {this.state.currentPage}

+ {(this.state.currentPage < this.state.totalPages) && } +
+ } +
+ )} +
+ ); + } +}; + +// PropTypes +// name +// id + +export default ChannelClaimsDisplay; diff --git a/react/constants/show_action_types.js b/react/constants/show_action_types.js index acf89ae5..7e11a190 100644 --- a/react/constants/show_action_types.js +++ b/react/constants/show_action_types.js @@ -1,5 +1,2 @@ export const REQUEST_UPDATE_CHANNEL = 'REQUEST_UPDATE_CHANNEL'; export const REQUEST_UPDATE_CLAIM = 'REQUEST_UPDATE_CLAIM'; -export const CHANNEL_DATA_UPDATE = 'CHANNEL_DATA_UPDATE'; -export const CHANNEL_CLAIMS_DATA_UPDATE = 'CHANNEL_CLAIMS_DATA_UPDATE'; -export const ASSET_DATA_UPDATE = 'ASSET_DATA_UPDATE'; diff --git a/react/containers/ChannelClaimsDisplay/index.js b/react/containers/ChannelClaimsDisplay/index.js deleted file mode 100644 index 2efa8468..00000000 --- a/react/containers/ChannelClaimsDisplay/index.js +++ /dev/null @@ -1,24 +0,0 @@ -import { connect } from 'react-redux'; -import View from './view'; -import {updateChannelClaimsData} from 'actions/show'; - -const mapStateToProps = ({ show }) => { - return { - name : show.channelData.name, - longId : show.channelData.longId, - claims : show.channelClaimsData.claims, - currentPage: show.channelClaimsData.currentPage, - totalPages : show.channelClaimsData.totalPages, - totalClaims: show.channelClaimsData.totalClaims, - }; -}; - -const mapDispatchToProps = dispatch => { - return { - onClaimsDataChange: (claims, currentPage, totalPages, totalClaims) => { - dispatch(updateChannelClaimsData(claims, currentPage, totalPages, totalClaims)); - }, - }; -}; - -export default connect(mapStateToProps, mapDispatchToProps)(View); diff --git a/react/containers/ChannelClaimsDisplay/view.jsx b/react/containers/ChannelClaimsDisplay/view.jsx deleted file mode 100644 index 702794a3..00000000 --- a/react/containers/ChannelClaimsDisplay/view.jsx +++ /dev/null @@ -1,63 +0,0 @@ -import React from 'react'; -import AssetPreview from 'components/AssetPreview/index'; -import request from 'utils/request'; - -class ChannelClaimsDisplay extends React.Component { - constructor (props) { - super(props); - this.state = { - error: null, - }; - this.getAndStoreChannelClaims = this.getAndStoreChannelClaims.bind(this); - } - componentDidMount () { - this.getAndStoreChannelClaims(this.props.name, this.props.longId, this.props.currentPage); - } - getAndStoreChannelClaims (name, id, page) { - if (!id) id = 'none'; - const url = `/api/channel-claims/${name}/${id}/${page}`; - const that = this; - return request(url) - .then(({ success, message, data }) => { - console.log('api/channel-claims response:', data); - if (!success) { - return that.setState({error: message}); - } - this.props.onClaimsDataChange(data.claims, data.currentPage, data.totalPages, data.totalResults); - }) - .catch((error) => { - that.setState({error: error.message}); - }); - } - render () { - return ( -
- {this.state.error ? ( -
-
-

{this.state.error}

-
-
- ) : ( -
- {this.props.claims && -
- {this.props.claims.map((claim, index) => )} -

current page: {this.props.currentPage}

-

total pages: {this.props.totalPages}

-

total claims: {this.props.totalClaims}

-
- } -
- )} -
- ); - } -}; - -export default ChannelClaimsDisplay; diff --git a/react/containers/ShowAsset/index.js b/react/containers/ShowAsset/index.js index 20866911..66c43970 100644 --- a/react/containers/ShowAsset/index.js +++ b/react/containers/ShowAsset/index.js @@ -1,5 +1,4 @@ import { connect } from 'react-redux'; -import { updateAssetData } from 'actions/show'; import View from './view'; const mapStateToProps = ({ show }) => { @@ -7,16 +6,7 @@ const mapStateToProps = ({ show }) => { modifier : show.assetRequest.modifier, claim : show.assetRequest.name, extension: show.assetRequest.extension, - claimData: show.assetData, }; }; -const mapDispatchToProps = dispatch => { - return { - onAssetDataUpdate: (data) => { - dispatch(updateAssetData(data)); - }, - }; -}; - -export default connect(mapStateToProps, mapDispatchToProps)(View); +export default connect(mapStateToProps, null)(View); diff --git a/react/containers/ShowAsset/view.jsx b/react/containers/ShowAsset/view.jsx index ff75100b..1b75753a 100644 --- a/react/containers/ShowAsset/view.jsx +++ b/react/containers/ShowAsset/view.jsx @@ -7,7 +7,8 @@ class ShowAsset extends React.Component { constructor (props) { super(props); this.state = { - error: null, + error : null, + claimData: null, }; this.getLongClaimId = this.getLongClaimId.bind(this); this.getClaimData = this.getClaimData.bind(this); @@ -42,7 +43,7 @@ class ShowAsset extends React.Component { return that.getClaimData(name, claimLongId); }) .then(claimData => { - this.props.onAssetDataUpdate(claimData); + this.setState({claimData}); }) .catch(error => { this.setState({error}); @@ -86,14 +87,14 @@ class ShowAsset extends React.Component { return ( ); } return ( ); } diff --git a/react/containers/ShowChannel/index.js b/react/containers/ShowChannel/index.js index c020cf54..377d47e2 100644 --- a/react/containers/ShowChannel/index.js +++ b/react/containers/ShowChannel/index.js @@ -1,27 +1,11 @@ import { connect } from 'react-redux'; -import { updateChannelData } from 'actions/show'; import View from './view'; const mapStateToProps = ({ show }) => { return { - request: { - name: show.channelRequest.name, - id : show.channelRequest.id, - }, - channel: { - name : show.channelData.name, - shortId: show.channelData.shortId, - longId : show.channelData.longId, - }, + requestName: show.channelRequest.name, + requestId : show.channelRequest.id, }; }; -const mapDispatchToProps = dispatch => { - return { - onChannelDataChange: (name, longId, shortId) => { - dispatch(updateChannelData(name, longId, shortId)); - }, - }; -}; - -export default connect(mapStateToProps, mapDispatchToProps)(View); +export default connect(mapStateToProps, null)(View); diff --git a/react/containers/ShowChannel/view.jsx b/react/containers/ShowChannel/view.jsx index 2f381247..0b15ef32 100644 --- a/react/containers/ShowChannel/view.jsx +++ b/react/containers/ShowChannel/view.jsx @@ -1,18 +1,21 @@ import React from 'react'; import NavBar from 'containers/NavBar'; -import ChannelClaimsDisplay from 'containers/ChannelClaimsDisplay'; +import ChannelClaimsDisplay from 'components/ChannelClaimsDisplay'; import request from 'utils/request'; class ShowChannel extends React.Component { constructor (props) { super(props); this.state = { - error: null, + error : null, + name : null, + shortId: null, + longId : null, }; this.getAndStoreChannelData = this.getAndStoreChannelData.bind(this); } componentDidMount () { - this.getAndStoreChannelData(this.props.request.name, this.props.request.id); + this.getAndStoreChannelData(this.props.requestName, this.props.requestId); } getAndStoreChannelData (name, id) { if (!id) id = 'none'; @@ -24,7 +27,11 @@ class ShowChannel extends React.Component { if (!success) { return that.setState({error: message}); } - this.props.onChannelDataChange(data.channelName, data.longChannelClaimId, data.shortChannelClaimId); + this.setState({ + name : data.channelName, + longId : data.longChannelClaimId, + shortId: data.shortChannelClaimId, + }); }) .catch((error) => { that.setState({error: error.message}); @@ -43,12 +50,17 @@ class ShowChannel extends React.Component { ) : (
-

channel name: {this.props.channel.name}

-

full channel id: {this.props.channel.longId ? this.props.channel.longId : 'loading...'}

-

short channel id: {this.props.channel.shortId ? this.props.channel.shortId : 'loading...'}

+

channel name: {this.state.name ? this.state.name : 'loading...'}

+

full channel id: {this.state.longId ? this.state.longId : 'loading...'}

+

short channel id: {this.state.shortId ? this.state.shortId : 'loading...'}

- {this.props.channel.name && } + {(this.state.name && this.state.longId) && + + }
)} diff --git a/react/reducers/show.js b/react/reducers/show.js index 55be0fce..c29dfb15 100644 --- a/react/reducers/show.js +++ b/react/reducers/show.js @@ -18,18 +18,6 @@ const initialState = { }, extension: null, }, - channelData: { - name : null, - shortId: null, - longId : null, - }, - channelClaimsData: { - claims : null, - currentPage: 1, - totalPages : null, - totalClaims: null, - }, - assetData: null, }; /* @@ -61,27 +49,6 @@ export default function (state = initialState, action) { extension: action.extension, }, }); - case actions.CHANNEL_DATA_UPDATE: - return Object.assign({}, state, { - channelData: Object.assign({}, state.channel, { - name : action.name, - shortId: action.shortId, - longId : action.longId, - }), - }); - case actions.CHANNEL_CLAIMS_DATA_UPDATE: - return Object.assign({}, state, { - channelClaimsData: { - claims : action.claims, - currentPage: action.currentPage, - totalPages : action.totalPages, - totalClaims: action.totalClaims, - }, - }); - case actions.ASSET_DATA_UPDATE: - return Object.assign({}, state, { - assetData: action.data, - }); default: return state; } diff --git a/routes/api-routes.js b/routes/api-routes.js index 4cc20ba9..f8c1eb08 100644 --- a/routes/api-routes.js +++ b/routes/api-routes.js @@ -29,13 +29,13 @@ module.exports = (app) => { app.get('/api/file-is-available/:name/:claimId', ({ ip, originalUrl, params }, res) => { const name = params.name; const claimId = params.claimId; - let isLocalFileAvailable = false; + let isAvailable = false; db.File.findOne({where: {name, claimId}}) .then(result => { if (result) { - isLocalFileAvailable = true; + isAvailable = true; } - res.status(200).json({status: 'success', message: isLocalFileAvailable}); + res.status(200).json({success: true, data: isAvailable}); }) .catch(error => { errorHandlers.handleApiError(originalUrl, ip, error, res); @@ -61,7 +61,7 @@ module.exports = (app) => { return Promise.all([db.upsert(db.File, fileData, {name, claimId}, 'File'), getResult]); }) .then(([ fileRecord, {message, completed} ]) => { - res.status(200).json({ status: 'success', message, completed }); + res.status(200).json({ success: true, message, completed }); }) .catch(error => { errorHandlers.handleApiError(originalUrl, ip, error, res);