-
Notifications
You must be signed in to change notification settings - Fork 67
feat: Non MFS Files API tutorial #303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
da63860
feat: first draft of first lesson
dominguesgm 07788f6
feat: draft of the second lesson done. also bumped ipfs version
dominguesgm a485251
feat: first draft of the 3rd lesson
dominguesgm 9c83fd5
chore: first draft of the 4th lesson
dominguesgm f312363
chore: first draft of the 5th lesson
dominguesgm 99c83b4
feat: first draft of 6th and last lesson
dominguesgm 603cdb1
chore: revisit lesson 2: change information on add method argument
dominguesgm 7979d0b
Er suggestions nonmfs (#304)
443d50c
chore: made several revisions from feedback. missing discussion on di…
dominguesgm 38421ac
copy edits to lesson 1
terichadbourne 2cb95f8
copy edits to lesson 2
terichadbourne 3598c68
copy edits to lesson 3
terichadbourne 721179a
fix typos
terichadbourne 270d7b2
remove old comments from Vue files
terichadbourne e952f8b
add MFS tutorial to resources page
terichadbourne 372a164
update featured courses
terichadbourne 383d196
fix typo
terichadbourne ae27adb
copy edits to lesson 4
terichadbourne 60518e3
chore: update approach to lesson 5
dominguesgm 5ac8aa5
Merge branch 'feat/tutorial-nonmfs' of github.com:ProtoSchool/protosc…
dominguesgm c844570
chore: update lesson 6 to match lesson 5
dominguesgm ca3d27e
chore: added content to lesson 5
dominguesgm 2f1c7bf
copy edits to Lesson 5k
terichadbourne 8e32c38
fix tutorial path
terichadbourne 6fb2b60
add IPFS Camp course to resources
terichadbourne 8e5c7e9
fix: fixed bug causing race conditions on fast executing user code
dominguesgm 69de401
copy edits to lesson 6
terichadbourne aae72cb
add resulting code block sample to L6
terichadbourne a82f488
chore: added lesson on cat file inside directory
dominguesgm 64297d8
Merge branch 'feat/tutorial-nonmfs' of github.com:ProtoSchool/protosc…
dominguesgm 7134742
copy edits to lesson 7
terichadbourne 0990fda
feat: improved lessons 7 and 8
dominguesgm a2f0191
feat: made some improvements to lesson 5
dominguesgm 19d7afb
lesson 7 copy edits
dominguesgm 3ee0f22
copy edit to lesson 5 success msg
terichadbourne d9863fc
lesson 8 copy edits, adding ls comparison
terichadbourne 325620b
fix merge issue
terichadbourne db2907a
update references to Regular Files API
terichadbourne e36ba80
update tutorial description
terichadbourne 8cf4920
fix: lesson 1: add format for mfs files API method calls
dominguesgm 8164af5
fix copy paste errors
terichadbourne 30dde25
mention IPLD when describing DAG API
terichadbourne b9851ff
change tutorial url
terichadbourne 4ba1e8e
chore: minor changes
dominguesgm 9c17177
Merge branch 'feat/tutorial-nonmfs' of github.com:ProtoSchool/protosc…
dominguesgm 21ea889
chore: update with most of the changes suggested by Alan
dominguesgm 4e66138
Merge branch 'code' into feat/tutorial-nonmfs
terichadbourne 845489e
Use ipfs in path in src/tutorials/0005/07.md
terichadbourne 7f83c47
Apply suggestions from code review
terichadbourne 873b6e9
add /ipfs/ to paths
terichadbourne 98f17d3
incorporate feedback from Alan & Marcin
terichadbourne d9b45ec
chore: change main solution in lesson 05
dominguesgm 90ed173
chore: updated file structure and contents
dominguesgm 75bb007
chore: update src/tutorials/0005/07-exercise.md
dominguesgm 59c83f5
chore: updated validation for lessons 3, 4, and 5. Fixed a bug in val…
dominguesgm 9a09a62
Merge branch 'feat/tutorial-nonmfs' of github.com:ProtoSchool/protosc…
dominguesgm f72672f
chore: update to lesson 6 validation
dominguesgm 898990b
chore: update feedback on lesson 7
dominguesgm cc946fa
chore: update lesson 8 validation
dominguesgm a26cdca
remove all references to 'root' directory
terichadbourne 07d5112
imrpove catch-all error msg
terichadbourne f085853
tweaks to error messages
terichadbourne a4bbd17
move javascript hints from solution to hints in exercise
terichadbourne de3e8e5
chore: update validation for lessons 5 and 7 according to comments
dominguesgm 6df2537
validation tweaks + new override
terichadbourne 721ef5a
rename variable
terichadbourne 6cd313c
minor copy edit
terichadbourne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"all": ["0004", "0001", "0002", "0003"], | ||
"featured": ["0004", "0001", "0002", "0003"] | ||
"all": ["0004", "0005", "0001", "0002", "0003"], | ||
"featured": ["0001", "0004", "0005", "0002"] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
## IPFS: The InterPlanetary File System | ||
|
||
[IPFS](https://ipfs.io/) is a peer-to-peer (P2P) networking protocol used to share data on the distributed web. You can think of it as a file system with some unique characteristics that make it ideal for safe, decentralized sharing. | ||
|
||
If you haven't yet done so, we encourage you to check out our [Decentralized Data Structures](https://proto.school/#/data-structures/) tutorial to learn all about the decentralized web and how it compares to the web you're accustomed to. There you'll learn all about content addressing, cryptographic hashing, Content Identifiers (CIDs), and sharing with peers, all of which you'll need to understand to make the most of this tutorial. | ||
|
||
## The Files API vs the DAG API | ||
|
||
You can store multiple types of data with IPFS. If you've explored our [P2P Data Links with Content Addressing](https://proto.school/#/basics) or [Blogging on the Decentralized Web](https://proto.school/#/blog) tutorial, you've already seen how you can store primitives, objects and arrays on the network using the DAG API. | ||
|
||
The DAG API allows you to use the unique and versatile primitive data structures offered by [IPLD](https://github.com/ipld/ipld) (InterPlanetary Linked Data) within IPFS. You can recognize its methods in js-ipfs (the JavaScript implementation of IPFS) because they take the following format: `ipfs.dag.someMethod()` | ||
|
||
The DAG API is the most generic and flexible approach to adding data to the IPFS node, but it's not the most efficient when it comes to the very common use case of sharing files. What if you wanted to share a picture of a kitten, or a larger file like a funny video of your favorite celebrity dog? How would you add these files to the network and provide a way for your friends to see them? How should each file be placed in the Directed Acyclic Graph (DAG), in a single block or split into chunks? These are optimization details that fall beyond the scope of the DAG API. Though it would be possible to use the DAG API to add files to an IPFS node, it would be a labor-intensive task. | ||
|
||
The Files API, on the other hand, is custom-built for a more specific use case. The Files API prepares files to be placed in the network and ensures that IPFS knows how to access them and handle them efficiently. The Files API is made of two parts: the Regular Files API, which we'll cover in this tutorial, and the Mutable File System (MFS). | ||
|
||
## The Regular Files API vs the MFS Files API | ||
|
||
If you've read our [Mutable File System tutorial](https://proto.school/#/mutable-file-system), you may be thinking, "I've already learned how to work with files on IPFS. How will this be any different?" | ||
|
||
The Mutable File System (MFS) provides an API designed to replicate familiar file system operations such as `mkdir`, `ls`, `cp`, and others, mimicking the way you organize files and directories on a computer. However, the way that content is addressed in IPFS makes it an immutable file system. The address to a file or directory depends on its contents, so any change to a file or directory will result in an entirely new address. The MFS Files API works on a familiar-looking file system with regular paths — like `/some/stuff` — in the local IPFS node, which hides the complexity of immutable content addressing. | ||
|
||
Although MFS is very useful, the abstraction it provides hides some of the inner workings of IPFS. The Regular Files API we will discuss here is instead a bare bones approach to managing files in IPFS. It trades the powerful abstractions of MFS for a scheme which helps you understand what is actually happening in the file system. In the Regular Files API you'll find methods like `add`, `cat`, `get` and `ls`. | ||
|
||
Unlike the MFS API, which can be recognized in js-ipfs by the format `ipfs.files.someMethod()`, the Regular Files API uses top-level methods that take the format `ipfs.someMethod()`. | ||
|
||
The distinction between these two versions of the Files APIs is a bit confusing the moment, but the IPFS team is currently working on revamping them to make the whole Files API more user-friendly. We'll be sure to update our tutorials when things change! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<template> | ||
<Lesson :text="text" /> | ||
</template> | ||
|
||
<script> | ||
import Lesson from '../../components/Lesson' | ||
import text from './01.md' | ||
|
||
export default { | ||
components: { | ||
Lesson | ||
}, | ||
data: () => { | ||
return { text } | ||
} | ||
} | ||
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
First, upload one or more files by dragging and dropping below or clicking to make a selection from your file explorer. Next, in the code editor, remove the comment markers (`//`) that precede `return files` within the `run` function. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
As a matter of security, web browsers don't let us directly change files that live in your computer's file system. Therefore, you'll need to upload one or more files to the browser that you can use throughout this tutorial. | ||
|
||
Within each exercise, you'll see that you can upload files from your computer either by dragging and dropping or selecting them from your file explorer. If you look closely at the `run` function in the code editor, you'll notice that it now takes an argument `files`. When you upload files from your computer, we'll make sure they're passed into the function as the `files` array. As long as you don't refresh your browser, these files will remain accessible for the next lesson in the tutorial, but you'll also have the option to upload different files to work with for each lesson. | ||
|
||
Each element in this `files` array will be a `File` object, as defined by the browser's [File API](https://developer.mozilla.org/en-US/docs/Web/API/File) (not to be confused with the IPFS Files API). Aside from the contents of the uploaded file, a `File` object also contains the following attributes: | ||
|
||
* **name** (name of the uploaded file) | ||
* **lastModified** (date the uploaded file was last modified) | ||
* **size** (size of the uploaded file) | ||
* **type** (type of the uploaded file) | ||
|
||
To practice, let's upload one or more files from your computer and take a look at what's been received by the browser as the `files` array. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<template> | ||
<FileLesson | ||
:text="text" | ||
:code="code" | ||
:validate="validate" | ||
:modules="modules" | ||
:exercise="exercise" | ||
:solution="solution"/> | ||
</template> | ||
|
||
<script> | ||
import FileLesson from '../../components/FileLesson.vue' | ||
import text from './02.md' | ||
import exercise from './02-exercise.md' | ||
import { logFiles } from '../../utils/files' | ||
|
||
const validate = async (result, ipfs) => { | ||
if (!result) { | ||
return { fail: 'Looks like you forgot to return a result. Did you forget to remove the `//` before `return files`?' } | ||
} else if (typeof result.length === 'number') { | ||
const fileCount = result.length > 1 ? `${result.length} files` : '1 file' | ||
return { | ||
success: `You successfully uploaded ${fileCount}!`, | ||
logDesc: "Check out the data below to see the data now accessible in the `files` array. Note that these files are only in the browser right now. In the next lesson we'll see how to add them to IPFS.", | ||
log: logFiles(result) | ||
} | ||
} else { | ||
return { fail: `Something seems to be wrong. Please click "Reset Code" and try again, taking another look at the instructions and editing only the portion of code indicated. Feeling really stuck? You can click "View Solution" to see our suggested code.` } | ||
} | ||
} | ||
|
||
const code = `const run = async (files) => { | ||
/* remove the '//' on the line below to complete this challenge */ | ||
// return files | ||
} | ||
return run | ||
` | ||
|
||
const solution = `const run = async (files) => { | ||
return files | ||
} | ||
|
||
return run | ||
` | ||
|
||
const modules = { cids: require('cids') } | ||
|
||
export default { | ||
components: { | ||
FileLesson | ||
}, | ||
data: () => { | ||
return { text, validate, code, modules, exercise, solution } | ||
} | ||
} | ||
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Add the files in your browser (available in the `files` array below) to your IPFS node using the `add` method. | ||
|
||
**Hint:** You can pass either a single `File` object or an array of `File` objects to the `add` method. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.