working?
This commit is contained in:
parent
9d71be9b1b
commit
faf4402309
10 changed files with 181 additions and 52 deletions
92
dist/bundle.es.js
vendored
92
dist/bundle.es.js
vendored
|
@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
||||||
|
|
||||||
require('proxy-polyfill');
|
require('proxy-polyfill');
|
||||||
|
var mime = _interopDefault(require('mime'));
|
||||||
var reselect = require('reselect');
|
var reselect = require('reselect');
|
||||||
var uuid = _interopDefault(require('uuid/v4'));
|
var uuid = _interopDefault(require('uuid/v4'));
|
||||||
var fs = _interopDefault(require('fs'));
|
var fs = _interopDefault(require('fs'));
|
||||||
|
@ -696,23 +697,30 @@ const Lbry = {
|
||||||
},
|
},
|
||||||
|
|
||||||
// Returns a human readable media type based on the content type or extension of a file that is returned by the sdk
|
// Returns a human readable media type based on the content type or extension of a file that is returned by the sdk
|
||||||
getMediaType: (contentType, extname) => {
|
getMediaType: (contentType, fileName) => {
|
||||||
if (extname) {
|
const formats = [[/\.(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'], [/\.(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'], [/\.(h|go|ja|java|js|jsx|c|cpp|cs|css|rb|scss|sh|php|py)$/i, 'script'], [/\.(json|csv|txt|log|md|markdown|docx|pdf|xml|yml|yaml)$/i, 'document'], [/\.(pdf|odf|doc|docx|epub|org|rtf)$/i, 'e-book'], [/\.(stl|obj|fbx|gcode)$/i, '3D-file'], [/\.(cbr|cbt|cbz)$/i, 'comic-book']];
|
||||||
const formats = [[/^(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'], [/^(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'], [/^(html|htm|xml|pdf|odf|doc|docx|md|markdown|txt|epub|org)$/i, 'document'], [/^(stl|obj|fbx|gcode)$/i, '3D-file']];
|
|
||||||
|
const extName = mime.getExtension(contentType);
|
||||||
|
const fileExt = extName ? `.${extName}` : null;
|
||||||
|
const testString = fileName || fileExt;
|
||||||
|
|
||||||
|
// Get mediaType from file extension
|
||||||
|
if (testString) {
|
||||||
const res = formats.reduce((ret, testpair) => {
|
const res = formats.reduce((ret, testpair) => {
|
||||||
switch (testpair[0].test(ret)) {
|
const [regex, mediaType] = testpair;
|
||||||
case true:
|
|
||||||
return testpair[1];
|
return regex.test(ret) ? mediaType : ret;
|
||||||
default:
|
}, testString);
|
||||||
return ret;
|
|
||||||
|
if (res !== testString) return res;
|
||||||
}
|
}
|
||||||
}, extname);
|
|
||||||
return res === extname ? 'unknown' : res;
|
// Get mediaType from contentType
|
||||||
} else if (contentType) {
|
if (contentType) {
|
||||||
// $FlowFixMe
|
|
||||||
return (/^[^/]+/.exec(contentType)[0]
|
return (/^[^/]+/.exec(contentType)[0]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'unknown';
|
return 'unknown';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -2447,7 +2455,7 @@ const makeSelectLoadingForUri = uri => reselect.createSelector(selectUrisLoading
|
||||||
const selectFileInfosDownloaded = reselect.createSelector(selectFileInfosByOutpoint, selectMyClaims, (byOutpoint, myClaims) => Object.values(byOutpoint).filter(fileInfo => {
|
const selectFileInfosDownloaded = reselect.createSelector(selectFileInfosByOutpoint, selectMyClaims, (byOutpoint, myClaims) => Object.values(byOutpoint).filter(fileInfo => {
|
||||||
const myClaimIds = myClaims.map(claim => claim.claim_id);
|
const myClaimIds = myClaims.map(claim => claim.claim_id);
|
||||||
|
|
||||||
return fileInfo && myClaimIds.indexOf(fileInfo.claim_id) === -1 && (fileInfo.completed || fileInfo.written_bytes);
|
return fileInfo && myClaimIds.indexOf(fileInfo.claim_id) === -1 && (fileInfo.completed || fileInfo.written_bytes > 0 || fileInfo.blobs_completed > 0);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// export const selectFileInfoForUri = (state, props) => {
|
// export const selectFileInfoForUri = (state, props) => {
|
||||||
|
@ -2586,6 +2594,27 @@ const selectDownloadedUris = reselect.createSelector(selectFileInfosDownloaded,
|
||||||
// We should use permament_url but it doesn't exist in file_list
|
// We should use permament_url but it doesn't exist in file_list
|
||||||
info => info.slice().reverse().map(claim => `lbry://${claim.claim_name}#${claim.claim_id}`));
|
info => info.slice().reverse().map(claim => `lbry://${claim.claim_name}#${claim.claim_id}`));
|
||||||
|
|
||||||
|
const makeSelectMediaTypeForUri = uri => reselect.createSelector(makeSelectFileInfoForUri(uri), makeSelectContentTypeForUri(uri), (fileInfo, contentType) => {
|
||||||
|
if (!fileInfo && !contentType) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileName = fileInfo && fileInfo.file_name;
|
||||||
|
return lbryProxy.getMediaType(contentType, fileName);
|
||||||
|
});
|
||||||
|
|
||||||
|
const makeSelectUriIsStreamable = uri => reselect.createSelector(makeSelectMediaTypeForUri(uri), mediaType => {
|
||||||
|
const isStreamable = ['audio', 'video', 'image'].indexOf(mediaType) !== -1;
|
||||||
|
return isStreamable;
|
||||||
|
});
|
||||||
|
|
||||||
|
const makeSelectDownloadPathForUri = uri => reselect.createSelector(makeSelectFileInfoForUri(uri), fileInfo => {
|
||||||
|
return fileInfo && fileInfo.download_path;
|
||||||
|
});
|
||||||
|
const makeSelectFileNameForUri = uri => reselect.createSelector(makeSelectFileInfoForUri(uri), fileInfo => {
|
||||||
|
return fileInfo && fileInfo.file_name;
|
||||||
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
const selectState$4 = state => state.file || {};
|
const selectState$4 = state => state.file || {};
|
||||||
|
@ -2600,11 +2629,13 @@ const selectPurchasedStreamingUrls = reselect.createSelector(selectState$4, stat
|
||||||
|
|
||||||
const selectLastPurchasedUri = reselect.createSelector(selectState$4, state => state.purchasedUris.length > 0 ? state.purchasedUris[state.purchasedUris.length - 1] : null);
|
const selectLastPurchasedUri = reselect.createSelector(selectState$4, state => state.purchasedUris.length > 0 ? state.purchasedUris[state.purchasedUris.length - 1] : null);
|
||||||
|
|
||||||
const makeSelectStreamingUrlForUri = uri => reselect.createSelector(selectPurchasedStreamingUrls, streamingUrls => streamingUrls && streamingUrls[uri]);
|
const makeSelectStreamingUrlForUri = uri => reselect.createSelector(makeSelectFileInfoForUri(uri), fileInfo => {
|
||||||
|
return fileInfo && fileInfo.streaming_url;
|
||||||
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
function doFileGet(uri, saveFile = true) {
|
function doFileGet(uri, saveFile = true, onSuccess) {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: LOADING_FILE_STARTED,
|
type: LOADING_FILE_STARTED,
|
||||||
|
@ -2615,7 +2646,7 @@ function doFileGet(uri, saveFile = true) {
|
||||||
|
|
||||||
// set save_file argument to True to save the file (old behaviour)
|
// set save_file argument to True to save the file (old behaviour)
|
||||||
lbryProxy.get({ uri, save_file: saveFile }).then(streamInfo => {
|
lbryProxy.get({ uri, save_file: saveFile }).then(streamInfo => {
|
||||||
const timeout = streamInfo === null || typeof streamInfo !== 'object';
|
const timeout = streamInfo === null || typeof streamInfo !== 'object' || streamInfo.error === 'Timeout';
|
||||||
|
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
dispatch({
|
dispatch({
|
||||||
|
@ -2633,8 +2664,19 @@ function doFileGet(uri, saveFile = true) {
|
||||||
const { streaming_url: streamingUrl } = streamInfo;
|
const { streaming_url: streamingUrl } = streamInfo;
|
||||||
dispatch({
|
dispatch({
|
||||||
type: PURCHASE_URI_COMPLETED,
|
type: PURCHASE_URI_COMPLETED,
|
||||||
data: { uri, streamingUrl: !saveFile && streamingUrl ? streamingUrl : null }
|
data: { uri, streamingUrl }
|
||||||
});
|
});
|
||||||
|
dispatch({
|
||||||
|
type: FETCH_FILE_INFO_COMPLETED,
|
||||||
|
data: {
|
||||||
|
fileInfo: streamInfo,
|
||||||
|
outpoint: streamInfo.outpoint
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (onSuccess) {
|
||||||
|
onSuccess(streamInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
dispatch({
|
dispatch({
|
||||||
|
@ -2647,14 +2689,14 @@ function doFileGet(uri, saveFile = true) {
|
||||||
});
|
});
|
||||||
|
|
||||||
dispatch(doToast({
|
dispatch(doToast({
|
||||||
message: `Failed to download ${uri}, please try again. If this problem persists, visit https://lbry.com/faq/support for support.`,
|
message: `Failed to view ${uri}, please try again. If this problem persists, visit https://lbry.com/faq/support for support.`,
|
||||||
isError: true
|
isError: true
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function doPurchaseUri(uri, costInfo, saveFile = true) {
|
function doPurchaseUri(uri, costInfo, saveFile = true, onSuccess) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: PURCHASE_URI_STARTED,
|
type: PURCHASE_URI_STARTED,
|
||||||
|
@ -2685,7 +2727,7 @@ function doPurchaseUri(uri, costInfo, saveFile = true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(doFileGet(uri, saveFile));
|
dispatch(doFileGet(uri, saveFile, onSuccess));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3921,13 +3963,15 @@ reducers$2[DOWNLOADING_PROGRESSED] = (state, action) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
reducers$2[DOWNLOADING_CANCELED] = (state, action) => {
|
reducers$2[DOWNLOADING_CANCELED] = (state, action) => {
|
||||||
const { outpoint } = action.data;
|
const { uri, outpoint } = action.data;
|
||||||
|
|
||||||
const newDownloading = Object.assign({}, state.downloadingByOutpoint);
|
const newDownloading = Object.assign({}, state.downloadingByOutpoint);
|
||||||
delete newDownloading[outpoint];
|
delete newDownloading[outpoint];
|
||||||
|
delete newLoading[uri];
|
||||||
|
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
downloadingByOutpoint: newDownloading
|
downloadingByOutpoint: newDownloading,
|
||||||
|
urisLoading: newLoading
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4842,12 +4886,15 @@ exports.makeSelectContentPositionForUri = makeSelectContentPositionForUri;
|
||||||
exports.makeSelectContentTypeForUri = makeSelectContentTypeForUri;
|
exports.makeSelectContentTypeForUri = makeSelectContentTypeForUri;
|
||||||
exports.makeSelectCoverForUri = makeSelectCoverForUri;
|
exports.makeSelectCoverForUri = makeSelectCoverForUri;
|
||||||
exports.makeSelectDateForUri = makeSelectDateForUri;
|
exports.makeSelectDateForUri = makeSelectDateForUri;
|
||||||
|
exports.makeSelectDownloadPathForUri = makeSelectDownloadPathForUri;
|
||||||
exports.makeSelectDownloadingForUri = makeSelectDownloadingForUri;
|
exports.makeSelectDownloadingForUri = makeSelectDownloadingForUri;
|
||||||
exports.makeSelectFetchingChannelClaims = makeSelectFetchingChannelClaims;
|
exports.makeSelectFetchingChannelClaims = makeSelectFetchingChannelClaims;
|
||||||
exports.makeSelectFileInfoForUri = makeSelectFileInfoForUri;
|
exports.makeSelectFileInfoForUri = makeSelectFileInfoForUri;
|
||||||
|
exports.makeSelectFileNameForUri = makeSelectFileNameForUri;
|
||||||
exports.makeSelectFirstRecommendedFileForUri = makeSelectFirstRecommendedFileForUri;
|
exports.makeSelectFirstRecommendedFileForUri = makeSelectFirstRecommendedFileForUri;
|
||||||
exports.makeSelectIsUriResolving = makeSelectIsUriResolving;
|
exports.makeSelectIsUriResolving = makeSelectIsUriResolving;
|
||||||
exports.makeSelectLoadingForUri = makeSelectLoadingForUri;
|
exports.makeSelectLoadingForUri = makeSelectLoadingForUri;
|
||||||
|
exports.makeSelectMediaTypeForUri = makeSelectMediaTypeForUri;
|
||||||
exports.makeSelectMetadataForUri = makeSelectMetadataForUri;
|
exports.makeSelectMetadataForUri = makeSelectMetadataForUri;
|
||||||
exports.makeSelectMetadataItemForUri = makeSelectMetadataItemForUri;
|
exports.makeSelectMetadataItemForUri = makeSelectMetadataItemForUri;
|
||||||
exports.makeSelectNsfwCountForChannel = makeSelectNsfwCountForChannel;
|
exports.makeSelectNsfwCountForChannel = makeSelectNsfwCountForChannel;
|
||||||
|
@ -4864,6 +4911,7 @@ exports.makeSelectThumbnailForUri = makeSelectThumbnailForUri;
|
||||||
exports.makeSelectTitleForUri = makeSelectTitleForUri;
|
exports.makeSelectTitleForUri = makeSelectTitleForUri;
|
||||||
exports.makeSelectTotalItemsForChannel = makeSelectTotalItemsForChannel;
|
exports.makeSelectTotalItemsForChannel = makeSelectTotalItemsForChannel;
|
||||||
exports.makeSelectTotalPagesForChannel = makeSelectTotalPagesForChannel;
|
exports.makeSelectTotalPagesForChannel = makeSelectTotalPagesForChannel;
|
||||||
|
exports.makeSelectUriIsStreamable = makeSelectUriIsStreamable;
|
||||||
exports.normalizeURI = normalizeURI;
|
exports.normalizeURI = normalizeURI;
|
||||||
exports.notificationsReducer = notificationsReducer;
|
exports.notificationsReducer = notificationsReducer;
|
||||||
exports.parseQueryParams = parseQueryParams;
|
exports.parseQueryParams = parseQueryParams;
|
||||||
|
|
2
dist/flow-typed/Lbry.js
vendored
2
dist/flow-typed/Lbry.js
vendored
|
@ -68,7 +68,7 @@ declare type ResolveResponse = {
|
||||||
[string]: Claim | { error?: {} },
|
[string]: Claim | { error?: {} },
|
||||||
};
|
};
|
||||||
|
|
||||||
declare type GetResponse = FileListItem;
|
declare type GetResponse = FileListItem & { error?: string };
|
||||||
|
|
||||||
declare type GenericTxResponse = {
|
declare type GenericTxResponse = {
|
||||||
height: number,
|
height: number,
|
||||||
|
|
2
flow-typed/Lbry.js
vendored
2
flow-typed/Lbry.js
vendored
|
@ -68,7 +68,7 @@ declare type ResolveResponse = {
|
||||||
[string]: Claim | { error?: {} },
|
[string]: Claim | { error?: {} },
|
||||||
};
|
};
|
||||||
|
|
||||||
declare type GetResponse = FileListItem;
|
declare type GetResponse = FileListItem & { error?: string };
|
||||||
|
|
||||||
declare type GenericTxResponse = {
|
declare type GenericTxResponse = {
|
||||||
height: number,
|
height: number,
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
"format": "prettier 'src/**/*.{js,json}' --write"
|
"format": "prettier 'src/**/*.{js,json}' --write"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"mime": "^2.4.4",
|
||||||
"proxy-polyfill": "0.1.6",
|
"proxy-polyfill": "0.1.6",
|
||||||
"reselect": "^3.0.0",
|
"reselect": "^3.0.0",
|
||||||
"uuid": "^3.3.2"
|
"uuid": "^3.3.2"
|
||||||
|
|
|
@ -217,6 +217,10 @@ export {
|
||||||
selectFileListDownloadedSort,
|
selectFileListDownloadedSort,
|
||||||
selectFileListPublishedSort,
|
selectFileListPublishedSort,
|
||||||
selectDownloadedUris,
|
selectDownloadedUris,
|
||||||
|
makeSelectMediaTypeForUri,
|
||||||
|
makeSelectUriIsStreamable,
|
||||||
|
makeSelectDownloadPathForUri,
|
||||||
|
makeSelectFileNameForUri,
|
||||||
} from 'redux/selectors/file_info';
|
} from 'redux/selectors/file_info';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|
41
src/lbry.js
41
src/lbry.js
|
@ -1,5 +1,6 @@
|
||||||
// @flow
|
// @flow
|
||||||
import 'proxy-polyfill';
|
import 'proxy-polyfill';
|
||||||
|
import mime from 'mime';
|
||||||
|
|
||||||
const CHECK_DAEMON_STARTED_TRY_NUMBER = 200;
|
const CHECK_DAEMON_STARTED_TRY_NUMBER = 200;
|
||||||
//
|
//
|
||||||
|
@ -32,27 +33,37 @@ const Lbry: LbryTypes = {
|
||||||
},
|
},
|
||||||
|
|
||||||
// Returns a human readable media type based on the content type or extension of a file that is returned by the sdk
|
// Returns a human readable media type based on the content type or extension of a file that is returned by the sdk
|
||||||
getMediaType: (contentType: string, extname: ?string) => {
|
getMediaType: (contentType?: string, fileName: ?string) => {
|
||||||
if (extname) {
|
|
||||||
const formats = [
|
const formats = [
|
||||||
[/^(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'],
|
[/\.(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'],
|
||||||
[/^(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'],
|
[/\.(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'],
|
||||||
[/^(html|htm|xml|pdf|odf|doc|docx|md|markdown|txt|epub|org)$/i, 'document'],
|
[/\.(h|go|ja|java|js|jsx|c|cpp|cs|css|rb|scss|sh|php|py)$/i, 'script'],
|
||||||
[/^(stl|obj|fbx|gcode)$/i, '3D-file'],
|
[/\.(json|csv|txt|log|md|markdown|docx|pdf|xml|yml|yaml)$/i, 'document'],
|
||||||
|
[/\.(pdf|odf|doc|docx|epub|org|rtf)$/i, 'e-book'],
|
||||||
|
[/\.(stl|obj|fbx|gcode)$/i, '3D-file'],
|
||||||
|
[/\.(cbr|cbt|cbz)$/i, 'comic-book'],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const extName = mime.getExtension(contentType);
|
||||||
|
const fileExt = extName ? `.${extName}` : null;
|
||||||
|
const testString = fileName || fileExt;
|
||||||
|
|
||||||
|
// Get mediaType from file extension
|
||||||
|
if (testString) {
|
||||||
const res = formats.reduce((ret, testpair) => {
|
const res = formats.reduce((ret, testpair) => {
|
||||||
switch (testpair[0].test(ret)) {
|
const [regex, mediaType] = testpair;
|
||||||
case true:
|
|
||||||
return testpair[1];
|
return regex.test(ret) ? mediaType : ret;
|
||||||
default:
|
}, testString);
|
||||||
return ret;
|
|
||||||
|
if (res !== testString) return res;
|
||||||
}
|
}
|
||||||
}, extname);
|
|
||||||
return res === extname ? 'unknown' : res;
|
// Get mediaType from contentType
|
||||||
} else if (contentType) {
|
if (contentType) {
|
||||||
// $FlowFixMe
|
|
||||||
return /^[^/]+/.exec(contentType)[0];
|
return /^[^/]+/.exec(contentType)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'unknown';
|
return 'unknown';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { makeSelectStreamingUrlForUri } from 'redux/selectors/file';
|
||||||
type Dispatch = (action: any) => any;
|
type Dispatch = (action: any) => any;
|
||||||
type GetState = () => { file: FileState };
|
type GetState = () => { file: FileState };
|
||||||
|
|
||||||
export function doFileGet(uri: string, saveFile: boolean = true) {
|
export function doFileGet(uri: string, saveFile: boolean = true, onSuccess?: GetResponse => any) {
|
||||||
return (dispatch: Dispatch) => {
|
return (dispatch: Dispatch) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.LOADING_FILE_STARTED,
|
type: ACTIONS.LOADING_FILE_STARTED,
|
||||||
|
@ -21,7 +21,8 @@ export function doFileGet(uri: string, saveFile: boolean = true) {
|
||||||
// set save_file argument to True to save the file (old behaviour)
|
// set save_file argument to True to save the file (old behaviour)
|
||||||
Lbry.get({ uri, save_file: saveFile })
|
Lbry.get({ uri, save_file: saveFile })
|
||||||
.then((streamInfo: GetResponse) => {
|
.then((streamInfo: GetResponse) => {
|
||||||
const timeout = streamInfo === null || typeof streamInfo !== 'object';
|
const timeout =
|
||||||
|
streamInfo === null || typeof streamInfo !== 'object' || streamInfo.error === 'Timeout';
|
||||||
|
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
dispatch({
|
dispatch({
|
||||||
|
@ -39,8 +40,19 @@ export function doFileGet(uri: string, saveFile: boolean = true) {
|
||||||
const { streaming_url: streamingUrl } = streamInfo;
|
const { streaming_url: streamingUrl } = streamInfo;
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.PURCHASE_URI_COMPLETED,
|
type: ACTIONS.PURCHASE_URI_COMPLETED,
|
||||||
data: { uri, streamingUrl: !saveFile && streamingUrl ? streamingUrl : null },
|
data: { uri, streamingUrl },
|
||||||
});
|
});
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.FETCH_FILE_INFO_COMPLETED,
|
||||||
|
data: {
|
||||||
|
fileInfo: streamInfo,
|
||||||
|
outpoint: streamInfo.outpoint,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (onSuccess) {
|
||||||
|
onSuccess(streamInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
@ -63,7 +75,12 @@ export function doFileGet(uri: string, saveFile: boolean = true) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doPurchaseUri(uri: string, costInfo: { cost: number }, saveFile: boolean = true) {
|
export function doPurchaseUri(
|
||||||
|
uri: string,
|
||||||
|
costInfo: { cost: number },
|
||||||
|
saveFile: boolean = true,
|
||||||
|
onSuccess?: GetResponse => any
|
||||||
|
) {
|
||||||
return (dispatch: Dispatch, getState: GetState) => {
|
return (dispatch: Dispatch, getState: GetState) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.PURCHASE_URI_STARTED,
|
type: ACTIONS.PURCHASE_URI_STARTED,
|
||||||
|
@ -98,7 +115,7 @@ export function doPurchaseUri(uri: string, costInfo: { cost: number }, saveFile:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(doFileGet(uri, saveFile));
|
dispatch(doFileGet(uri, saveFile, onSuccess));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
|
import { makeSelectFileInfoForUri } from 'redux/selectors/file_info';
|
||||||
|
|
||||||
type State = { file: FileState };
|
type State = { file: FileState };
|
||||||
|
|
||||||
|
@ -31,8 +32,10 @@ export const selectLastPurchasedUri: (state: State) => string = createSelector(
|
||||||
state.purchasedUris.length > 0 ? state.purchasedUris[state.purchasedUris.length - 1] : null
|
state.purchasedUris.length > 0 ? state.purchasedUris[state.purchasedUris.length - 1] : null
|
||||||
);
|
);
|
||||||
|
|
||||||
export const makeSelectStreamingUrlForUri = (uri: string): ((state: State) => {}) =>
|
export const makeSelectStreamingUrlForUri = (uri: string) =>
|
||||||
createSelector(
|
createSelector(
|
||||||
selectPurchasedStreamingUrls,
|
makeSelectFileInfoForUri(uri),
|
||||||
streamingUrls => streamingUrls && streamingUrls[uri]
|
fileInfo => {
|
||||||
|
return fileInfo && fileInfo.streaming_url;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,9 +3,11 @@ import {
|
||||||
selectIsFetchingClaimListMine,
|
selectIsFetchingClaimListMine,
|
||||||
selectMyClaims,
|
selectMyClaims,
|
||||||
selectClaimsById,
|
selectClaimsById,
|
||||||
|
makeSelectContentTypeForUri,
|
||||||
} from 'redux/selectors/claims';
|
} from 'redux/selectors/claims';
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
import { buildURI } from 'lbryURI';
|
import { buildURI } from 'lbryURI';
|
||||||
|
import Lbry from 'lbry';
|
||||||
|
|
||||||
export const selectState = state => state.fileInfo || {};
|
export const selectState = state => state.fileInfo || {};
|
||||||
|
|
||||||
|
@ -238,3 +240,41 @@ export const selectDownloadedUris = createSelector(
|
||||||
.reverse()
|
.reverse()
|
||||||
.map(claim => `lbry://${claim.claim_name}#${claim.claim_id}`)
|
.map(claim => `lbry://${claim.claim_name}#${claim.claim_id}`)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const makeSelectMediaTypeForUri = (uri: string) =>
|
||||||
|
createSelector(
|
||||||
|
makeSelectFileInfoForUri(uri),
|
||||||
|
makeSelectContentTypeForUri(uri),
|
||||||
|
(fileInfo, contentType) => {
|
||||||
|
if (!fileInfo && !contentType) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileName = fileInfo && fileInfo.file_name;
|
||||||
|
return Lbry.getMediaType(contentType, fileName);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const makeSelectUriIsStreamable = (uri: string) =>
|
||||||
|
createSelector(
|
||||||
|
makeSelectMediaTypeForUri(uri),
|
||||||
|
mediaType => {
|
||||||
|
const isStreamable = ['audio', 'video', 'image'].indexOf(mediaType) !== -1;
|
||||||
|
return isStreamable;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const makeSelectDownloadPathForUri = (uri: string) =>
|
||||||
|
createSelector(
|
||||||
|
makeSelectFileInfoForUri(uri),
|
||||||
|
fileInfo => {
|
||||||
|
return fileInfo && fileInfo.download_path;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
export const makeSelectFileNameForUri = (uri: string) =>
|
||||||
|
createSelector(
|
||||||
|
makeSelectFileInfoForUri(uri),
|
||||||
|
fileInfo => {
|
||||||
|
return fileInfo && fileInfo.file_name;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
|
@ -3523,6 +3523,11 @@ mime-types@^2.1.12, mime-types@~2.1.17:
|
||||||
dependencies:
|
dependencies:
|
||||||
mime-db "~1.33.0"
|
mime-db "~1.33.0"
|
||||||
|
|
||||||
|
mime@^2.4.4:
|
||||||
|
version "2.4.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/mime/-/mime-2.4.4.tgz#bd7b91135fc6b01cde3e9bae33d659b63d8857e5"
|
||||||
|
integrity sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA==
|
||||||
|
|
||||||
mimic-fn@^1.0.0:
|
mimic-fn@^1.0.0:
|
||||||
version "1.2.0"
|
version "1.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
|
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
|
||||||
|
|
Loading…
Add table
Reference in a new issue