diff --git a/dist/bundle.es.js b/dist/bundle.es.js index acca6d9..fbd32c8 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -5,7 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true }); function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } require('proxy-polyfill'); -var mime = _interopDefault(require('mime')); var reselect = require('reselect'); var uuid = _interopDefault(require('uuid/v4')); @@ -692,29 +691,22 @@ const Lbry = { // Returns a human readable media type based on the content type or extension of a file that is returned by the sdk getMediaType: (contentType, fileName) => { - 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']]; + if (fileName) { + 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 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 [regex, mediaType] = testpair; - - return regex.test(ret) ? mediaType : ret; - }, testString); - - if (res !== testString) return res; - } - - // Get mediaType from contentType - if (contentType) { - const matches = /^[^/]+/.exec(contentType); - if (matches) { - return matches[0]; - } + switch (testpair[0].test(ret)) { + case true: + return testpair[1]; + default: + return ret; + } + }, fileName); + return res === fileName ? 'unknown' : res; + } else if (contentType) { + // $FlowFixMe + return (/^[^/]+/.exec(contentType)[0] + ); } return 'unknown'; @@ -1233,156 +1225,6 @@ function doDismissError() { }; } -const selectState$1 = state => state.wallet || {}; - -const selectWalletState = selectState$1; - -const selectWalletIsEncrypted = reselect.createSelector(selectState$1, state => state.walletIsEncrypted); - -const selectWalletEncryptPending = reselect.createSelector(selectState$1, state => state.walletEncryptPending); - -const selectWalletEncryptSucceeded = reselect.createSelector(selectState$1, state => state.walletEncryptSucceded); - -const selectWalletEncryptResult = reselect.createSelector(selectState$1, state => state.walletEncryptResult); - -const selectWalletDecryptPending = reselect.createSelector(selectState$1, state => state.walletDecryptPending); - -const selectWalletDecryptSucceeded = reselect.createSelector(selectState$1, state => state.walletDecryptSucceded); - -const selectWalletDecryptResult = reselect.createSelector(selectState$1, state => state.walletDecryptResult); - -const selectWalletUnlockPending = reselect.createSelector(selectState$1, state => state.walletUnlockPending); - -const selectWalletUnlockSucceeded = reselect.createSelector(selectState$1, state => state.walletUnlockSucceded); - -const selectWalletUnlockResult = reselect.createSelector(selectState$1, state => state.walletUnlockResult); - -const selectWalletLockPending = reselect.createSelector(selectState$1, state => state.walletLockPending); - -const selectWalletLockSucceeded = reselect.createSelector(selectState$1, state => state.walletLockSucceded); - -const selectWalletLockResult = reselect.createSelector(selectState$1, state => state.walletLockResult); - -const selectBalance = reselect.createSelector(selectState$1, state => state.balance); - -const selectTotalBalance = reselect.createSelector(selectState$1, state => state.totalBalance); - -const selectTransactionsById = reselect.createSelector(selectState$1, state => state.transactions || {}); - -const selectSupportsByOutpoint = reselect.createSelector(selectState$1, state => state.supports || {}); - -const selectTotalSupports = reselect.createSelector(selectSupportsByOutpoint, byOutpoint => { - let total = parseFloat("0.0"); - - Object.values(byOutpoint).forEach(support => { - const { amount } = support; - total = amount ? total + parseFloat(amount) : total; - }); - - return total; -}); - -const selectTransactionItems = reselect.createSelector(selectTransactionsById, byId => { - const items = []; - - Object.keys(byId).forEach(txid => { - const tx = byId[txid]; - - // ignore dust/fees - // it is fee only txn if all infos are also empty - if (Math.abs(tx.value) === Math.abs(tx.fee) && tx.claim_info.length === 0 && tx.support_info.length === 0 && tx.update_info.length === 0 && tx.abandon_info.length === 0) { - return; - } - - const append = []; - - append.push(...tx.claim_info.map(item => Object.assign({}, tx, item, { - type: item.claim_name[0] === '@' ? CHANNEL$1 : PUBLISH$1 - }))); - append.push(...tx.support_info.map(item => Object.assign({}, tx, item, { - type: !item.is_tip ? SUPPORT : TIP - }))); - append.push(...tx.update_info.map(item => Object.assign({}, tx, item, { type: UPDATE }))); - append.push(...tx.abandon_info.map(item => Object.assign({}, tx, item, { type: ABANDON }))); - - if (!append.length) { - append.push(Object.assign({}, tx, { - type: tx.value < 0 ? SPEND : RECEIVE - })); - } - - items.push(...append.map(item => { - // value on transaction, amount on outpoint - // amount is always positive, but should match sign of value - const balanceDelta = parseFloat(item.balance_delta); - const value = parseFloat(item.value); - const amount = balanceDelta || value; - const fee = parseFloat(tx.fee); - - return { - txid, - timestamp: tx.timestamp, - date: tx.timestamp ? new Date(Number(tx.timestamp) * 1000) : null, - amount, - fee, - claim_id: item.claim_id, - claim_name: item.claim_name, - type: item.type || SPEND, - nout: item.nout, - confirmations: tx.confirmations - }; - })); - }); - - return items.sort((tx1, tx2) => { - if (!tx1.timestamp && !tx2.timestamp) { - return 0; - } else if (!tx1.timestamp && tx2.timestamp) { - return -1; - } else if (tx1.timestamp && !tx2.timestamp) { - return 1; - } - - return tx2.timestamp - tx1.timestamp; - }); -}); - -const selectRecentTransactions = reselect.createSelector(selectTransactionItems, transactions => { - const threshold = new Date(); - threshold.setDate(threshold.getDate() - 7); - return transactions.filter(transaction => { - if (!transaction.date) { - return true; // pending transaction - } - - return transaction.date > threshold; - }); -}); - -const selectHasTransactions = reselect.createSelector(selectTransactionItems, transactions => transactions && transactions.length > 0); - -const selectIsFetchingTransactions = reselect.createSelector(selectState$1, state => state.fetchingTransactions); - -const selectIsSendingSupport = reselect.createSelector(selectState$1, state => state.sendingSupport); - -const selectReceiveAddress = reselect.createSelector(selectState$1, state => state.receiveAddress); - -const selectGettingNewAddress = reselect.createSelector(selectState$1, state => state.gettingNewAddress); - -const selectDraftTransaction = reselect.createSelector(selectState$1, state => state.draftTransaction || {}); - -const selectDraftTransactionAmount = reselect.createSelector(selectDraftTransaction, draft => draft.amount); - -const selectDraftTransactionAddress = reselect.createSelector(selectDraftTransaction, draft => draft.address); - -const selectDraftTransactionError = reselect.createSelector(selectDraftTransaction, draft => draft.error); - -const selectBlocks = reselect.createSelector(selectState$1, state => state.blocks); - -const selectCurrentHeight = reselect.createSelector(selectState$1, state => state.latestBlock); - -const selectTransactionListFilter = reselect.createSelector(selectState$1, state => state.transactionListFilter || ''); - var _extends$2 = 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 _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } @@ -1419,13 +1261,13 @@ function createNormalizedClaimSearchKey(options) { // -const selectState$2 = state => state.claims || {}; +const selectState$1 = state => state.claims || {}; -const selectClaimsById = reselect.createSelector(selectState$2, state => state.byId || {}); +const selectClaimsById = reselect.createSelector(selectState$1, state => state.byId || {}); -const selectCurrentChannelPage = reselect.createSelector(selectState$2, state => state.currentChannelPage || 1); +const selectCurrentChannelPage = reselect.createSelector(selectState$1, state => state.currentChannelPage || 1); -const selectClaimsByUri = reselect.createSelector(selectState$2, selectClaimsById, (state, byId) => { +const selectClaimsByUri = reselect.createSelector(selectState$1, selectClaimsById, (state, byId) => { const byUri = state.claimsByUri || {}; const claims = {}; @@ -1445,11 +1287,11 @@ const selectClaimsByUri = reselect.createSelector(selectState$2, selectClaimsByI return claims; }); -const selectAllClaimsByChannel = reselect.createSelector(selectState$2, state => state.claimsByChannel || {}); +const selectAllClaimsByChannel = reselect.createSelector(selectState$1, state => state.claimsByChannel || {}); -const selectPendingById = reselect.createSelector(selectState$2, state => state.pendingById || {}); +const selectPendingById = reselect.createSelector(selectState$1, state => state.pendingById || {}); -const selectPendingClaims = reselect.createSelector(selectState$2, state => Object.values(state.pendingById || [])); +const selectPendingClaims = reselect.createSelector(selectState$1, state => Object.values(state.pendingById || [])); const makeSelectClaimIsPending = uri => reselect.createSelector(selectPendingById, pendingById => { let claimId; @@ -1489,9 +1331,9 @@ const makeSelectClaimForUri = uri => reselect.createSelector(selectClaimsByUri, } }); -const selectMyClaimsRaw = reselect.createSelector(selectState$2, state => state.myClaims); +const selectMyClaimsRaw = reselect.createSelector(selectState$1, state => state.myClaims); -const selectAbandoningIds = reselect.createSelector(selectState$2, state => Object.keys(state.abandoningById || {})); +const selectAbandoningIds = reselect.createSelector(selectState$1, state => Object.keys(state.abandoningById || {})); const selectMyActiveClaims = reselect.createSelector(selectMyClaimsRaw, selectAbandoningIds, (claims, abandoningIds) => new Set(claims && claims.map(claim => claim.claim_id).filter(claimId => Object.keys(abandoningIds).indexOf(claimId) === -1))); @@ -1512,7 +1354,7 @@ const makeSelectClaimIsMine = rawUri => { }); }; -const selectAllFetchingChannelClaims = reselect.createSelector(selectState$2, state => state.fetchingChannelClaims || {}); +const selectAllFetchingChannelClaims = reselect.createSelector(selectState$1, state => state.fetchingChannelClaims || {}); const makeSelectFetchingChannelClaims = uri => reselect.createSelector(selectAllFetchingChannelClaims, fetching => fetching && fetching[uri]); @@ -1577,7 +1419,7 @@ const makeSelectCoverForUri = uri => reselect.createSelector(makeSelectClaimForU return cover ? cover.url : undefined; }); -const selectIsFetchingClaimListMine = reselect.createSelector(selectState$2, state => state.isFetchingClaimListMine); +const selectIsFetchingClaimListMine = reselect.createSelector(selectState$1, state => state.isFetchingClaimListMine); const selectMyClaims = reselect.createSelector(selectMyActiveClaims, selectClaimsById, selectAbandoningIds, selectPendingClaims, (myClaimIds, byId, abandoningIds, pendingClaims) => { const claims = []; @@ -1613,9 +1455,9 @@ const selectMyClaimsOutpoints = reselect.createSelector(selectMyClaims, myClaims return outpoints; }); -const selectFetchingMyChannels = reselect.createSelector(selectState$2, state => state.fetchingMyChannels); +const selectFetchingMyChannels = reselect.createSelector(selectState$1, state => state.fetchingMyChannels); -const selectMyChannelClaims = reselect.createSelector(selectState$2, selectClaimsById, (state, byId) => { +const selectMyChannelClaims = reselect.createSelector(selectState$1, selectClaimsById, (state, byId) => { const ids = state.myChannelClaims || []; const claims = []; @@ -1629,13 +1471,13 @@ const selectMyChannelClaims = reselect.createSelector(selectState$2, selectClaim return claims; }); -const selectResolvingUris = reselect.createSelector(selectState$2, state => state.resolvingUris || []); +const selectResolvingUris = reselect.createSelector(selectState$1, state => state.resolvingUris || []); const makeSelectIsUriResolving = uri => reselect.createSelector(selectResolvingUris, resolvingUris => resolvingUris && resolvingUris.indexOf(uri) !== -1); -const selectPlayingUri = reselect.createSelector(selectState$2, state => state.playingUri); +const selectPlayingUri = reselect.createSelector(selectState$1, state => state.playingUri); -const selectChannelClaimCounts = reselect.createSelector(selectState$2, state => state.channelClaimCounts || {}); +const selectChannelClaimCounts = reselect.createSelector(selectState$1, state => state.channelClaimCounts || {}); const makeSelectTotalItemsForChannel = uri => reselect.createSelector(selectChannelClaimCounts, byUri => byUri && byUri[uri]); @@ -1718,32 +1560,155 @@ const makeSelectTagsForUri = uri => reselect.createSelector(makeSelectMetadataFo return metadata && metadata.tags || []; }); -const selectFetchingClaimSearchByQuery = reselect.createSelector(selectState$2, state => state.fetchingClaimSearchByQuery || {}); +const selectFetchingClaimSearchByQuery = reselect.createSelector(selectState$1, state => state.fetchingClaimSearchByQuery || {}); const selectFetchingClaimSearch = reselect.createSelector(selectFetchingClaimSearchByQuery, fetchingClaimSearchByQuery => Boolean(Object.keys(fetchingClaimSearchByQuery).length)); -const selectClaimSearchByQuery = reselect.createSelector(selectState$2, state => state.claimSearchByQuery || {}); +const selectClaimSearchByQuery = reselect.createSelector(selectState$1, state => state.claimSearchByQuery || {}); const selectClaimSearchByQueryLastPageReached = reselect.createSelector(selectState$1, state => state.claimSearchByQueryLastPageReached || {}); const makeSelectShortUrlForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => claim && claim.short_url); -const makeSelectSupportsForUri = uri => reselect.createSelector(selectSupportsByOutpoint, makeSelectClaimForUri(uri), (byOutpoint, claim) => { - if (!claim || !claim.is_mine) { - return null; - } +const selectState$2 = state => state.wallet || {}; - const { claim_id: claimId } = claim; - let total = parseFloat("0.0"); +const selectWalletState = selectState$2; - Object.values(byOutpoint).forEach(support => { - const { claim_id, amount } = support; - total = claim_id === claimId && amount ? total + parseFloat(amount) : total; +const selectWalletIsEncrypted = reselect.createSelector(selectState$2, state => state.walletIsEncrypted); + +const selectWalletEncryptPending = reselect.createSelector(selectState$2, state => state.walletEncryptPending); + +const selectWalletEncryptSucceeded = reselect.createSelector(selectState$2, state => state.walletEncryptSucceded); + +const selectWalletEncryptResult = reselect.createSelector(selectState$2, state => state.walletEncryptResult); + +const selectWalletDecryptPending = reselect.createSelector(selectState$2, state => state.walletDecryptPending); + +const selectWalletDecryptSucceeded = reselect.createSelector(selectState$2, state => state.walletDecryptSucceded); + +const selectWalletDecryptResult = reselect.createSelector(selectState$2, state => state.walletDecryptResult); + +const selectWalletUnlockPending = reselect.createSelector(selectState$2, state => state.walletUnlockPending); + +const selectWalletUnlockSucceeded = reselect.createSelector(selectState$2, state => state.walletUnlockSucceded); + +const selectWalletUnlockResult = reselect.createSelector(selectState$2, state => state.walletUnlockResult); + +const selectWalletLockPending = reselect.createSelector(selectState$2, state => state.walletLockPending); + +const selectWalletLockSucceeded = reselect.createSelector(selectState$2, state => state.walletLockSucceded); + +const selectWalletLockResult = reselect.createSelector(selectState$2, state => state.walletLockResult); + +const selectBalance = reselect.createSelector(selectState$2, state => state.balance); + +const selectTotalBalance = reselect.createSelector(selectState$2, state => state.totalBalance); + +const selectTransactionsById = reselect.createSelector(selectState$2, state => state.transactions || {}); + +const selectSupportsByOutpoint = reselect.createSelector(selectState$2, state => state.supports || {}); + +const selectTransactionItems = reselect.createSelector(selectTransactionsById, byId => { + const items = []; + + Object.keys(byId).forEach(txid => { + const tx = byId[txid]; + + // ignore dust/fees + // it is fee only txn if all infos are also empty + if (Math.abs(tx.value) === Math.abs(tx.fee) && tx.claim_info.length === 0 && tx.support_info.length === 0 && tx.update_info.length === 0 && tx.abandon_info.length === 0) { + return; + } + + const append = []; + + append.push(...tx.claim_info.map(item => Object.assign({}, tx, item, { + type: item.claim_name[0] === '@' ? CHANNEL$1 : PUBLISH$1 + }))); + append.push(...tx.support_info.map(item => Object.assign({}, tx, item, { + type: !item.is_tip ? SUPPORT : TIP + }))); + append.push(...tx.update_info.map(item => Object.assign({}, tx, item, { type: UPDATE }))); + append.push(...tx.abandon_info.map(item => Object.assign({}, tx, item, { type: ABANDON }))); + + if (!append.length) { + append.push(Object.assign({}, tx, { + type: tx.value < 0 ? SPEND : RECEIVE + })); + } + + items.push(...append.map(item => { + // value on transaction, amount on outpoint + // amount is always positive, but should match sign of value + const balanceDelta = parseFloat(item.balance_delta); + const value = parseFloat(item.value); + const amount = balanceDelta || value; + const fee = parseFloat(tx.fee); + + return { + txid, + timestamp: tx.timestamp, + date: tx.timestamp ? new Date(Number(tx.timestamp) * 1000) : null, + amount, + fee, + claim_id: item.claim_id, + claim_name: item.claim_name, + type: item.type || SPEND, + nout: item.nout, + confirmations: tx.confirmations + }; + })); }); - return total; + return items.sort((tx1, tx2) => { + if (!tx1.timestamp && !tx2.timestamp) { + return 0; + } else if (!tx1.timestamp && tx2.timestamp) { + return -1; + } else if (tx1.timestamp && !tx2.timestamp) { + return 1; + } + + return tx2.timestamp - tx1.timestamp; + }); }); +const selectRecentTransactions = reselect.createSelector(selectTransactionItems, transactions => { + const threshold = new Date(); + threshold.setDate(threshold.getDate() - 7); + return transactions.filter(transaction => { + if (!transaction.date) { + return true; // pending transaction + } + + return transaction.date > threshold; + }); +}); + +const selectHasTransactions = reselect.createSelector(selectTransactionItems, transactions => transactions && transactions.length > 0); + +const selectIsFetchingTransactions = reselect.createSelector(selectState$2, state => state.fetchingTransactions); + +const selectIsSendingSupport = reselect.createSelector(selectState$2, state => state.sendingSupport); + +const selectReceiveAddress = reselect.createSelector(selectState$2, state => state.receiveAddress); + +const selectGettingNewAddress = reselect.createSelector(selectState$2, state => state.gettingNewAddress); + +const selectDraftTransaction = reselect.createSelector(selectState$2, state => state.draftTransaction || {}); + +const selectDraftTransactionAmount = reselect.createSelector(selectDraftTransaction, draft => draft.amount); + +const selectDraftTransactionAddress = reselect.createSelector(selectDraftTransaction, draft => draft.address); + +const selectDraftTransactionError = reselect.createSelector(selectDraftTransaction, draft => draft.error); + +const selectBlocks = reselect.createSelector(selectState$2, state => state.blocks); + +const selectCurrentHeight = reselect.createSelector(selectState$2, state => state.latestBlock); + +const selectTransactionListFilter = reselect.createSelector(selectState$2, state => state.transactionListFilter || ''); + function formatCredits(amount, precision) { if (Number.isNaN(parseFloat(amount))) return '0'; return parseFloat(amount).toFixed(precision || 1).replace(/\.?0+$/, ''); @@ -1777,8 +1742,8 @@ function doUpdateBalance() { const { wallet: { balance: balanceInStore } } = getState(); - lbryProxy.account_balance().then(({ available }) => { - const balance = parseFloat(available); + lbryProxy.account_balance().then(balanceAsString => { + const balance = parseFloat(balanceAsString); if (balanceInStore !== balance) { dispatch({ type: UPDATE_BALANCE, @@ -2757,7 +2722,7 @@ function doPurchaseUri(uri, costInfo, saveFile = true, onSuccess) { const alreadyDownloading = fileInfo && !!downloadingByOutpoint[fileInfo.outpoint]; const alreadyStreaming = makeSelectStreamingUrlForUri(uri)(state); - if (!saveFile && (alreadyDownloading || alreadyStreaming)) { + if (alreadyDownloading || alreadyStreaming) { dispatch({ type: PURCHASE_URI_FAILED, data: { uri, error: `Already fetching uri: ${uri}` } @@ -3068,8 +3033,7 @@ const doPrepareEdit = (claim, uri, fileInfo, fs) => dispatch => { license, license_url: licenseUrl, thumbnail, - title, - tags + title } = value; const publishData = { @@ -3085,8 +3049,7 @@ const doPrepareEdit = (claim, uri, fileInfo, fs) => dispatch => { uri, uploadThumbnailStatus: thumbnail ? MANUAL : undefined, licenseUrl, - nsfw: isClaimNsfw(claim), - tags: tags ? tags.map(tag => ({ name: tag })) : [] + nsfw: isClaimNsfw(claim) }; // Make sure custom licenses are mapped properly @@ -3108,6 +3071,15 @@ const doPrepareEdit = (claim, uri, fileInfo, fs) => dispatch => { publishData['channel'] = channelName; } + if (fs && fileInfo && fileInfo.download_path) { + try { + fs.accessSync(fileInfo.download_path, fs.constants.R_OK); + publishData.filePath = fileInfo.download_path; + } catch (e) { + console.error(e.name, e.message); + } + } + dispatch({ type: DO_PREPARE_EDIT, data: publishData }); }; @@ -4920,7 +4892,6 @@ exports.makeSelectRecommendedContentForUri = makeSelectRecommendedContentForUri; exports.makeSelectSearchUris = makeSelectSearchUris; exports.makeSelectShortUrlForUri = makeSelectShortUrlForUri; exports.makeSelectStreamingUrlForUri = makeSelectStreamingUrlForUri; -exports.makeSelectSupportsForUri = makeSelectSupportsForUri; exports.makeSelectTagsForUri = makeSelectTagsForUri; exports.makeSelectThumbnailForUri = makeSelectThumbnailForUri; exports.makeSelectTitleForUri = makeSelectTitleForUri; @@ -5008,7 +4979,6 @@ exports.selectTakeOverAmount = selectTakeOverAmount; exports.selectToast = selectToast; exports.selectTotalBalance = selectTotalBalance; exports.selectTotalDownloadProgress = selectTotalDownloadProgress; -exports.selectTotalSupports = selectTotalSupports; exports.selectTransactionItems = selectTransactionItems; exports.selectTransactionListFilter = selectTransactionListFilter; exports.selectTransactionsById = selectTransactionsById; diff --git a/flow-typed/mime.js b/flow-typed/mime.js deleted file mode 100644 index 476b179..0000000 --- a/flow-typed/mime.js +++ /dev/null @@ -1,4 +0,0 @@ -// @flow -declare module 'mime' { - declare module.exports: any; -} diff --git a/package.json b/package.json index 8cba56d..21b595f 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ "format": "prettier 'src/**/*.{js,json}' --write" }, "dependencies": { - "mime": "^2.4.4", "proxy-polyfill": "0.1.6", "reselect": "^3.0.0", "uuid": "^3.3.2" diff --git a/src/index.js b/src/index.js index 88bdf74..d47feb8 100644 --- a/src/index.js +++ b/src/index.js @@ -172,7 +172,6 @@ export { makeSelectPendingByUri, makeSelectClaimsInChannelForCurrentPageState, makeSelectShortUrlForUri, - makeSelectSupportsForUri, selectPendingById, selectClaimsById, selectClaimsByUri, @@ -251,7 +250,6 @@ export { selectTotalBalance, selectTransactionsById, selectSupportsByOutpoint, - selectTotalSupports, selectTransactionItems, selectRecentTransactions, selectHasTransactions, diff --git a/src/lbry.js b/src/lbry.js index b87a8a2..6313063 100644 --- a/src/lbry.js +++ b/src/lbry.js @@ -1,6 +1,5 @@ // @flow import 'proxy-polyfill'; -import mime from 'mime'; const CHECK_DAEMON_STARTED_TRY_NUMBER = 200; // @@ -34,37 +33,29 @@ 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 getMediaType: (contentType?: string, fileName: ?string) => { - 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'], - ]; + if (fileName) { + 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 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 [regex, mediaType] = testpair; - - return regex.test(ret) ? mediaType : ret; - }, testString); - - if (res !== testString) return res; - } - - // Get mediaType from contentType - if (contentType) { - const matches = /^[^/]+/.exec(contentType); - if (matches) { - return matches[0]; - } + switch (testpair[0].test(ret)) { + case true: + return testpair[1]; + default: + return ret; + } + }, fileName); + return res === fileName ? 'unknown' : res; + } else if (contentType) { + // $FlowFixMe + return /^[^/]+/.exec(contentType)[0]; } return 'unknown'; diff --git a/src/redux/actions/file.js b/src/redux/actions/file.js index f6befff..79d9b99 100644 --- a/src/redux/actions/file.js +++ b/src/redux/actions/file.js @@ -95,7 +95,7 @@ export function doPurchaseUri( const alreadyDownloading = fileInfo && !!downloadingByOutpoint[fileInfo.outpoint]; const alreadyStreaming = makeSelectStreamingUrlForUri(uri)(state); - if (!saveFile && (alreadyDownloading || alreadyStreaming)) { + if (alreadyDownloading || alreadyStreaming) { dispatch({ type: ACTIONS.PURCHASE_URI_FAILED, data: { uri, error: `Already fetching uri: ${uri}` }, diff --git a/src/redux/actions/publish.js b/src/redux/actions/publish.js index 5db20c9..6c23373 100644 --- a/src/redux/actions/publish.js +++ b/src/redux/actions/publish.js @@ -189,7 +189,6 @@ export const doPrepareEdit = (claim: StreamClaim, uri: string, fileInfo: FileLis license_url: licenseUrl, thumbnail, title, - tags, } = value; const publishData: UpdatePublishFormData = { @@ -206,7 +205,6 @@ export const doPrepareEdit = (claim: StreamClaim, uri: string, fileInfo: FileLis uploadThumbnailStatus: thumbnail ? THUMBNAIL_STATUSES.MANUAL : undefined, licenseUrl, nsfw: isClaimNsfw(claim), - tags: tags ? tags.map(tag => ({ name: tag })) : [], }; // Make sure custom licenses are mapped properly @@ -228,6 +226,15 @@ export const doPrepareEdit = (claim: StreamClaim, uri: string, fileInfo: FileLis publishData['channel'] = channelName; } + if (fs && fileInfo && fileInfo.download_path) { + try { + fs.accessSync(fileInfo.download_path, fs.constants.R_OK); + publishData.filePath = fileInfo.download_path; + } catch (e) { + console.error(e.name, e.message); + } + } + dispatch({ type: ACTIONS.DO_PREPARE_EDIT, data: publishData }); }; diff --git a/src/redux/actions/wallet.js b/src/redux/actions/wallet.js index 8757422..475436f 100644 --- a/src/redux/actions/wallet.js +++ b/src/redux/actions/wallet.js @@ -10,8 +10,8 @@ export function doUpdateBalance() { const { wallet: { balance: balanceInStore }, } = getState(); - Lbry.account_balance().then(({ available }) => { - const balance = parseFloat(available); + Lbry.account_balance().then(balanceAsString => { + const balance = parseFloat(balanceAsString); if (balanceInStore !== balance) { dispatch({ type: ACTIONS.UPDATE_BALANCE, diff --git a/src/redux/selectors/claims.js b/src/redux/selectors/claims.js index 5a38364..896fb76 100644 --- a/src/redux/selectors/claims.js +++ b/src/redux/selectors/claims.js @@ -1,7 +1,6 @@ // @flow import { normalizeURI, buildURI, parseURI } from 'lbryURI'; import { selectSearchUrisByQuery } from 'redux/selectors/search'; -import { selectSupportsByOutpoint } from 'redux/selectors/wallet'; import { createSelector } from 'reselect'; import { isClaimNsfw, createNormalizedClaimSearchKey } from 'util/claim'; import { getSearchQueryString } from 'util/query-params'; @@ -537,24 +536,3 @@ export const makeSelectShortUrlForUri = (uri: string) => makeSelectClaimForUri(uri), claim => claim && claim.short_url ); - -export const makeSelectSupportsForUri = (uri: string) => - createSelector( - selectSupportsByOutpoint, - makeSelectClaimForUri(uri), - (byOutpoint, claim: ?StreamClaim) => { - if (!claim || !claim.is_mine) { - return null; - } - - const { claim_id: claimId } = claim; - let total = parseFloat("0.0"); - - Object.values(byOutpoint).forEach(support => { - const { claim_id, amount } = support - total = (claim_id === claimId && amount) ? total + parseFloat(amount) : total; - }); - - return total; - } - ); diff --git a/src/redux/selectors/wallet.js b/src/redux/selectors/wallet.js index 6ca8b77..654836d 100644 --- a/src/redux/selectors/wallet.js +++ b/src/redux/selectors/wallet.js @@ -90,20 +90,6 @@ export const selectSupportsByOutpoint = createSelector( state => state.supports || {} ); -export const selectTotalSupports = createSelector( - selectSupportsByOutpoint, - byOutpoint => { - let total = parseFloat("0.0"); - - Object.values(byOutpoint).forEach(support => { - const { amount } = support; - total = amount ? total + parseFloat(amount) : total; - }); - - return total; - } -); - export const selectTransactionItems = createSelector( selectTransactionsById, byId => { diff --git a/yarn.lock b/yarn.lock index 182afdc..49dc513 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3523,11 +3523,6 @@ mime-types@^2.1.12, mime-types@~2.1.17: dependencies: 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: version "1.2.0" resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"