diff --git a/package-lock.json b/package-lock.json index 3b9cbbe76..760b5389f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -109,7 +109,7 @@ "eslint-plugin-standard": "^4.0.1", "fake-indexeddb": "^3.1.2", "get-port": "^5.1.1", - "go-ipfs": "0.9.1", + "go-ipfs": "0.12.0", "http-proxy": "^1.18.1", "http-server": "^0.12.3", "ipfs": "0.58.3", @@ -21933,14 +21933,13 @@ } }, "node_modules/go-ipfs": { - "version": "0.9.1", - "resolved": "https://registry.npmjs.org/go-ipfs/-/go-ipfs-0.9.1.tgz", - "integrity": "sha512-69sDGENU7xEPDNytEzE+swKTNSLr+OJEfdEYQ41m91dzNyHyxABB4Rteg4uzsj34lTizjVI1m7Gld3g5Dgf6Ag==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/go-ipfs/-/go-ipfs-0.12.0.tgz", + "integrity": "sha512-rZbU4PsXbqzdqgH57G48MvLveV4i8StKPUHr49Kepm/z+/qwhg8jzHQVpiip/+28qd2gy3Cgiw1MremegHRvPw==", "dev": true, "hasInstallScript": true, "dependencies": { "cachedir": "^2.3.0", - "go-platform": "^1.0.0", "got": "^11.7.0", "gunzip-maybe": "^1.4.2", "hasha": "^5.2.2", @@ -22115,15 +22114,6 @@ "lowercase-keys": "^2.0.0" } }, - "node_modules/go-platform": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/go-platform/-/go-platform-1.0.0.tgz", - "integrity": "sha1-sF/2uSdAB9JGsWQjXwP39qWWJsc=", - "dev": true, - "bin": { - "go-platform": "cli.js" - } - }, "node_modules/good-listener": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/good-listener/-/good-listener-1.2.2.tgz", @@ -67693,13 +67683,12 @@ } }, "go-ipfs": { - "version": "0.9.1", - "resolved": "https://registry.npmjs.org/go-ipfs/-/go-ipfs-0.9.1.tgz", - "integrity": "sha512-69sDGENU7xEPDNytEzE+swKTNSLr+OJEfdEYQ41m91dzNyHyxABB4Rteg4uzsj34lTizjVI1m7Gld3g5Dgf6Ag==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/go-ipfs/-/go-ipfs-0.12.0.tgz", + "integrity": "sha512-rZbU4PsXbqzdqgH57G48MvLveV4i8StKPUHr49Kepm/z+/qwhg8jzHQVpiip/+28qd2gy3Cgiw1MremegHRvPw==", "dev": true, "requires": { "cachedir": "^2.3.0", - "go-platform": "^1.0.0", "got": "^11.7.0", "gunzip-maybe": "^1.4.2", "hasha": "^5.2.2", @@ -67825,12 +67814,6 @@ } } }, - "go-platform": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/go-platform/-/go-platform-1.0.0.tgz", - "integrity": "sha1-sF/2uSdAB9JGsWQjXwP39qWWJsc=", - "dev": true - }, "good-listener": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/good-listener/-/good-listener-1.2.2.tgz", diff --git a/package.json b/package.json index ebbf79c73..a822f4776 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,7 @@ "eslint-plugin-standard": "^4.0.1", "fake-indexeddb": "^3.1.2", "get-port": "^5.1.1", - "go-ipfs": "0.9.1", + "go-ipfs": "0.12.0", "http-proxy": "^1.18.1", "http-server": "^0.12.3", "ipfs": "0.58.3", diff --git a/src/bundles/files/consts.js b/src/bundles/files/consts.js index 60281435c..0bb4818d2 100644 --- a/src/bundles/files/consts.js +++ b/src/bundles/files/consts.js @@ -31,8 +31,6 @@ export const ACTIONS = { PIN_LIST: ('FILES_PIN_LIST'), /** @type {'FILES_SIZE_GET'} */ SIZE_GET: ('FILES_SIZE_GET'), - /** @type {'FILES_PINS_SIZE_GET'} */ - PINS_SIZE_GET: ('FILES_PINS_SIZE_GET'), /** @type {'FILES_DISMISS_ERRORS'} */ DISMISS_ERRORS: ('FILES_DISMISS_ERRORS'), /** @type {'FILES_CLEAR_ALL'} */ @@ -60,8 +58,6 @@ export const IGNORED_FILES = [ export const DEFAULT_STATE = { pageContent: null, mfsSize: -1, - pinsSize: 0, - numberOfPins: 0, pins: [], sorting: { // TODO: cache this by: SORTING.BY_NAME, diff --git a/src/bundles/files/index.js b/src/bundles/files/index.js index 7405e9513..78494e612 100644 --- a/src/bundles/files/index.js +++ b/src/bundles/files/index.js @@ -98,22 +98,6 @@ const createFilesBundle = () => { return state } } - case ACTIONS.PINS_SIZE_GET: { - const { task, type } = action - const pinsSize = task.status === 'Exit' && task.result.ok - ? task.result.value.pinsSize - : 0 - - const numberOfPins = task.status === 'Exit' && task.result.ok - ? task.result.value.numberOfPins - : 0 - - return { - ...updateJob(state, task, type), - pinsSize, - numberOfPins - } - } case ACTIONS.SIZE_GET: { const { task, type } = action const mfsSize = task.status === 'Exit' && task.result.ok diff --git a/src/bundles/files/protocol.ts b/src/bundles/files/protocol.ts index 981bb7a2d..303233646 100644 --- a/src/bundles/files/protocol.ts +++ b/src/bundles/files/protocol.ts @@ -9,8 +9,6 @@ export type Model = { pins: string[] sorting: Sorting mfsSize: number - pinsSize: number - numberOfPins: number pending: PendingJob[] finished: FinishedJob[] diff --git a/src/bundles/files/selectors.js b/src/bundles/files/selectors.js index 1b6cbc387..aa29eb1f5 100644 --- a/src/bundles/files/selectors.js +++ b/src/bundles/files/selectors.js @@ -42,16 +42,6 @@ const selectors = () => ({ */ selectFilesSize: (state) => state.files.mfsSize, - /** - * @param {Model} state - */ - selectPinsSize: (state) => state.files.pinsSize, - - /** - * @param {Model} state - */ - selectNumberOfPins: (state) => state.files.numberOfPins, - /** * @param {Model} state */ diff --git a/src/bundles/pinning.js b/src/bundles/pinning.js index 1cfcde951..d6d30356d 100644 --- a/src/bundles/pinning.js +++ b/src/bundles/pinning.js @@ -2,6 +2,7 @@ import { pinningServiceTemplates } from '../constants/pinning' import memoize from 'p-memoize' import CID from 'cids' +import all from 'it-all' // This bundle leverages createCacheBundle and persistActions for // the persistence layer that keeps pins in IndexDB store @@ -61,6 +62,8 @@ const pinningBundle = { pinningServices: [], remotePins: [], notRemotePins: [], + localPinsSize: 0, + localNumberOfPins: 0, arePinningServicesSupported: false }, action) => { if (action.type === 'UPDATE_REMOTE_PINS') { @@ -70,6 +73,10 @@ const pinningBundle = { const notRemotePins = uniq([...state.notRemotePins, ...removals].filter(p => !adds.some(a => a === p))) return { ...state, remotePins, notRemotePins } } + if (action.type === 'SET_LOCAL_PINS_STATS') { + const { localPinsSize, localNumberOfPins } = action.payload + return { ...state, localNumberOfPins, localPinsSize } + } if (action.type === 'SET_REMOTE_PINNING_SERVICES') { const oldServices = state.pinningServices const newServices = action.payload @@ -148,6 +155,9 @@ const pinningBundle = { selectRemotePins: (state) => state.pinning.remotePins || [], selectNotRemotePins: (state) => state.pinning.notRemotePins || [], + selectLocalPinsSize: (state) => state.pinning.localPinsSize, + selectLocalNumberOfPins: (state) => state.pinning.localNumberOfPins, + doSelectRemotePinsForFile: (file) => ({ store }) => { const pinningServicesNames = store.selectPinningServices().map(remote => remote.name) const remotePinForFile = store.selectRemotePins().filter(pin => cacheId2Cid(pin) === file.cid.toString()) @@ -155,6 +165,18 @@ const pinningBundle = { return servicesBeingUsed }, + // gets the amount of local pins + doFetchLocalPinsStats: () => async ({ getIpfs, dispatch }) => { + const ipfs = getIpfs() + if (!ipfs) return null + + const localPins = await all(ipfs.pin.ls({ type: 'recursive' })) + const localPinsSize = -1 // TODO: right now calculating size of all pins is too expensive (requires ipfs.files.stat per CID) + const localNumberOfPins = localPins.length + + dispatch({ type: 'SET_LOCAL_PINS_STATS', payload: { localPinsSize, localNumberOfPins } }) + }, + // list of services without online check (reads list from config, should be instant) doFetchPinningServices: () => async ({ getIpfs, store, dispatch }) => { const ipfs = getIpfs() diff --git a/src/components/pinning-manager/PinningManager.js b/src/components/pinning-manager/PinningManager.js index 595f87c78..f16b26c7a 100644 --- a/src/components/pinning-manager/PinningManager.js +++ b/src/components/pinning-manager/PinningManager.js @@ -21,7 +21,7 @@ import './PinningManager.css' const ROW_HEIGHT = 50 const HEADER_HEIGHT = 32 -export const PinningManager = ({ pinningServices, ipfsReady, arePinningServicesSupported, doFetchPinningServices, doFetchPinningServicesStats, doRemovePinningService, pinsSize, numberOfPins, t }) => { +export const PinningManager = ({ pinningServices, ipfsReady, arePinningServicesSupported, doFetchPinningServices, doFetchPinningServicesStats, doFetchLocalPinsStats, doRemovePinningService, localPinsSize, localNumberOfPins, t }) => { const [isModalOpen, setModalOpen] = useState(false) const [isToggleModalOpen, setToggleModalOpen] = useState(false) const onModalOpen = () => setModalOpen(true) @@ -35,12 +35,12 @@ export const PinningManager = ({ pinningServices, ipfsReady, arePinningServicesS }) useEffect(() => { - ipfsReady && doFetchPinningServices() && doFetchPinningServicesStats() - }, [ipfsReady, doFetchPinningServices, doFetchPinningServicesStats]) + ipfsReady && doFetchPinningServices() && doFetchPinningServicesStats() && doFetchLocalPinsStats() + }, [ipfsReady, doFetchPinningServices, doFetchPinningServicesStats, doFetchLocalPinsStats]) const localPinning = useMemo(() => - ({ name: t('localPinning'), type: 'LOCAL', totalSize: pinsSize, numberOfPins }), - [numberOfPins, pinsSize, t]) + ({ name: t('localPinning'), type: 'LOCAL', totalSize: localPinsSize, numberOfPins: localNumberOfPins }), + [localNumberOfPins, localPinsSize, t]) const sortedServices = useMemo(() => (pinningServices || []).sort(sortByProperty(sortSettings.sortBy, sortSettings.sortDirection === SortDirection.ASC ? 1 : -1)), @@ -187,12 +187,13 @@ const OptionsCell = ({ doRemovePinningService, name, visitServiceUrl, autoUpload export default connect( 'selectIpfsReady', - 'selectPinsSize', - 'selectNumberOfPins', + 'selectLocalPinsSize', + 'selectLocalNumberOfPins', 'selectPinningServices', 'selectArePinningServicesSupported', 'doFetchPinningServices', 'doFetchPinningServicesStats', + 'doFetchLocalPinsStats', 'doRemovePinningService', PinningManager )