Skip to content

Commit

Permalink
feat: track remote pins in progress (#1919)
Browse files Browse the repository at this point in the history
Co-authored-by: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com>
Co-authored-by: Marcin Rataj <lidel@lidel.org>
  • Loading branch information
3 people authored Oct 4, 2022
1 parent b27f3be commit d3a6524
Show file tree
Hide file tree
Showing 167 changed files with 2,187 additions and 1,071 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"internal-nav-helper": "^3.1.0",
"intl-messageformat": "^9.11.3",
"ip": "^1.1.5",
"ipfs-css": "^1.3.0",
"ipfs-css": "^1.4.0",
"ipfs-geoip": "^8.0.0",
"ipfs-http-client": "49.0.2",
"ipfs-provider": "^2.1.0",
Expand Down
10 changes: 9 additions & 1 deletion public/locales/en/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,16 @@
"checkboxLabel": "View more options for {name}",
"pinned": "Pinned",
"pinnedRemotely": "Pinned remotely",
"pinningRemotely": "Pinning remotely",
"pinningCompleted": "Pinning completed",
"pinningFailed": "Pinning failed",
"clickToDismiss": "Click to dismiss",
"clickToCancel": "Click to cancel",
"blocks": "Blocks",
"allBlocks": "All blocks",
"allBlocksDescription": "Total size of blocks on your entire IPFS node; this includes everything in Files, plus all locally pinned items and any temporary cached data",
"filesDescription": "Total size of data in the current directory (if a subdirectory, the size of all data in Files is also displayed)",
"pinningQueue": "Pinning queue",
"more": "More",
"files": "Files",
"cidNotFileNorDir": "The current link isn't a file, nor a directory. Try to <1>inspect</1> it instead.",
Expand All @@ -125,5 +131,7 @@
"linkCopied": "Link copied!",
"sharingPrompt": "Copy the link below and share it with others. The IPNS address will resolve as long as your node remains available on the network once a day to refresh the IPNS record.",
"pleaseWait": "Please wait while the initial 20 copies of the updated IPNS record are stored with the help of DHT peers…"
}
},
"noPinsInProgress": "All done, no remote pins in progress.",
"remotePinningInProgress": "Remote pinning in progress:"
}
26 changes: 2 additions & 24 deletions src/bundles/files/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,6 @@ const getRawPins = async function * (ipfs) {
*/
const getPinCIDs = (ipfs) => map(getRawPins(ipfs), (pin) => pin.cid)

/**
* @param {IPFSService} ipfs
* @returns {AsyncIterable<FileStat>}
*/
const getPins = async function * (ipfs) {
for await (const cid of getPinCIDs(ipfs)) {
const info = await stat(ipfs, cid)
yield fileFromStats({ ...info, pinned: true }, '/pins')
}
}

/**
* @typedef {import('./protocol').Message} Message
* @typedef {import('./protocol').Model} Model
Expand Down Expand Up @@ -201,22 +190,11 @@ const actions = () => ({
* @param {Info} info
* @returns {function(Context): *}
*/
doFetch: ({ path, realPath, isMfs, isPins, isRoot }) => perform(ACTIONS.FETCH, async (ipfs, { store }) => {
if (isRoot && !isMfs && !isPins) {
doFetch: ({ path, realPath, isMfs, isRoot }) => perform(ACTIONS.FETCH, async (ipfs, { store }) => {
if (isRoot && !isMfs) {
throw new Error('not supposed to be here')
}

if (isRoot && isPins) {
const pins = await all(getPins(ipfs)) // FIX: pins path

return {
path: '/pins',
fetched: Date.now(),
type: 'directory',
content: pins
}
}

const resolvedPath = realPath.startsWith('/ipns')
? await last(ipfs.name.resolve(realPath))
: realPath
Expand Down
10 changes: 3 additions & 7 deletions src/bundles/files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,15 @@ const createFilesBundle = () => {
const result = task.status === 'Exit' && task.result.ok
? task.result.value
: null
const { pageContent, pins } = result
const { pageContent } = result
? {
pageContent: result,
pins: result.type === 'directory' && result.path === '/pins'
? result.content.map($ => $.cid.toString())
: state.pins
pageContent: result
}
: state

return {
...updateJob(state, task, type),
pageContent,
pins
pageContent
}
}
case ACTIONS.DISMISS_ERRORS: {
Expand Down
9 changes: 0 additions & 9 deletions src/bundles/files/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ export const sortFiles = (files, sorting) => {
* @property {string} path
* @property {string} realPath
* @property {boolean} isMfs
* @property {boolean} isPins
* @property {boolean} isRoot
*
* @param {string} path
Expand All @@ -201,7 +200,6 @@ export const infoFromPath = (path, uriDecode = true) => {
path,
realPath: '',
isMfs: false,
isPins: false,
isRoot: false
}

Expand All @@ -219,13 +217,6 @@ export const infoFromPath = (path, uriDecode = true) => {
} else if (info.path.startsWith('/files')) {
check('/files')
info.isMfs = true
} else if (info.path.startsWith('/pins')) {
check('/pins')
info.isPins = true

if (info.realPath !== '/') {
info.realPath = `/ipfs${info.realPath}`
}
} else {
return
}
Expand Down
Loading

0 comments on commit d3a6524

Please sign in to comment.