2017-04-23 11:56:50 +02:00
|
|
|
import * as types from 'constants/action_types'
|
|
|
|
import lbry from 'lbry'
|
|
|
|
import lbryio from 'lbryio';
|
2017-04-24 09:25:27 +02:00
|
|
|
import {
|
|
|
|
selectCurrentUri,
|
|
|
|
} from 'selectors/app'
|
|
|
|
import {
|
|
|
|
selectCurrentResolvedUriClaimOutpoint,
|
|
|
|
} from 'selectors/content'
|
2017-04-23 11:56:50 +02:00
|
|
|
|
2017-04-23 16:01:00 +02:00
|
|
|
export function doResolveUri(dispatch, uri) {
|
|
|
|
dispatch({
|
|
|
|
type: types.RESOLVE_URI_STARTED,
|
|
|
|
data: { uri }
|
|
|
|
})
|
|
|
|
|
|
|
|
lbry.resolve({uri: uri}).then((resolutionInfo) => {
|
|
|
|
const {
|
|
|
|
claim,
|
|
|
|
certificate,
|
|
|
|
} = resolutionInfo
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: types.RESOLVE_URI_COMPLETED,
|
|
|
|
data: {
|
|
|
|
uri,
|
|
|
|
claim,
|
|
|
|
certificate,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-24 09:25:27 +02:00
|
|
|
export function doFetchCurrentUriFileInfo() {
|
|
|
|
return function(dispatch, getState) {
|
|
|
|
const state = getState()
|
|
|
|
const uri = selectCurrentUri(state)
|
|
|
|
const outpoint = selectCurrentResolvedUriClaimOutpoint(state)
|
|
|
|
|
|
|
|
console.log(outpoint)
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_FILE_INFO_STARTED,
|
|
|
|
data: {
|
|
|
|
uri,
|
|
|
|
outpoint,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
lbry.file_list({ outpoint }).then(fileInfo => {
|
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_FILE_INFO_COMPLETED,
|
|
|
|
data: {
|
|
|
|
uri,
|
|
|
|
fileInfo,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-23 18:10:45 +02:00
|
|
|
export function doFetchDownloadedContent() {
|
|
|
|
return function(dispatch, getState) {
|
|
|
|
const state = getState()
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_DOWNLOADED_CONTENT_STARTED,
|
|
|
|
})
|
|
|
|
|
|
|
|
lbry.claim_list_mine().then((myClaimInfos) => {
|
|
|
|
lbry.file_list().then((fileInfos) => {
|
|
|
|
const myClaimOutpoints = myClaimInfos.map(({txid, nout}) => txid + ':' + nout);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_DOWNLOADED_CONTENT_COMPLETED,
|
|
|
|
data: {
|
|
|
|
fileInfos: fileInfos.filter(({outpoint}) => !myClaimOutpoints.includes(outpoint)),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function doFetchPublishedContent() {
|
|
|
|
return function(dispatch, getState) {
|
|
|
|
const state = getState()
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_PUBLISHED_CONTENT_STARTED,
|
|
|
|
})
|
|
|
|
|
|
|
|
lbry.claim_list_mine().then((claimInfos) => {
|
|
|
|
lbry.file_list().then((fileInfos) => {
|
|
|
|
const myClaimOutpoints = claimInfos.map(({txid, nout}) => txid + ':' + nout)
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_PUBLISHED_CONTENT_COMPLETED,
|
|
|
|
data: {
|
|
|
|
fileInfos: fileInfos.filter(({outpoint}) => myClaimOutpoints.includes(outpoint)),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-23 11:56:50 +02:00
|
|
|
export function doFetchFeaturedContent() {
|
|
|
|
return function(dispatch, getState) {
|
|
|
|
const state = getState()
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_FEATURED_CONTENT_STARTED,
|
|
|
|
})
|
|
|
|
|
|
|
|
const success = ({ Categories, Uris }) => {
|
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_FEATURED_CONTENT_COMPLETED,
|
|
|
|
data: {
|
|
|
|
categories: Categories,
|
|
|
|
uris: Uris,
|
|
|
|
}
|
|
|
|
})
|
2017-04-23 16:01:00 +02:00
|
|
|
|
|
|
|
Object.keys(Uris).forEach((category) => {
|
|
|
|
Uris[category].forEach((uri) => doResolveUri(dispatch, uri))
|
|
|
|
})
|
2017-04-23 11:56:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const failure = () => {
|
|
|
|
}
|
|
|
|
|
|
|
|
lbryio.call('discover', 'list', { version: "early-access" } )
|
|
|
|
.then(success, failure)
|
|
|
|
}
|
|
|
|
}
|
2017-04-24 09:25:27 +02:00
|
|
|
|
|
|
|
export function doFetchCurrentUriCostInfo() {
|
|
|
|
return function(dispatch, getState) {
|
|
|
|
const state = getState()
|
|
|
|
const uri = selectCurrentUri(state)
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_COST_INFO_STARTED,
|
|
|
|
data: {
|
|
|
|
uri,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
lbry.getCostInfo(uri).then(costInfo => {
|
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_COST_INFO_COMPLETED,
|
|
|
|
data: {
|
|
|
|
uri,
|
|
|
|
costInfo,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|