-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alan Shaw
committed
Nov 15, 2023
1 parent
85d0445
commit 4e7150e
Showing
6 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,7 @@ | ||
/\_____/\ | ||
/ o o \ | ||
( == ^ == ) | ||
) ( | ||
( ) | ||
( ( ) ( ) ) | ||
(__(__)___(__)__) |
This file contains 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,35 @@ | ||
import fs from 'node:fs' | ||
import path from 'node:path' | ||
import { Buffer } from 'node:buffer' | ||
import { execaNode } from 'execa' | ||
import msee from 'msee' | ||
import * as Link from 'multiformats/link' | ||
|
||
const cat = Link.parse('bafkreicn5krrora5gx47hrbj6kbfwrrskh7iawngpdudmzqp72i6jaalyu') | ||
const catData = fs.readFileSync(new URL('./cat.txt', import.meta.url), 'utf8') | ||
|
||
export const problem = msee.parse(fs.readFileSync(new URL('./problem.md', import.meta.url), 'utf8')) | ||
|
||
export const solution = msee.parse(fs.readFileSync(new URL('./solution.md', import.meta.url), 'utf8')) | ||
|
||
/** | ||
* @param {string[]} args | ||
* @param {(success: boolean) => void} cb | ||
*/ | ||
export const verify = (args, cb) => { | ||
(async () => { | ||
const filepath = path.resolve(args[0]) | ||
console.log(`Verifying ${filepath}...\n`) | ||
const { stdout, all } = await execaNode(filepath, [], { | ||
input: Buffer.from(cat.bytes), | ||
all: true | ||
}) | ||
console.log(all ?? '') | ||
|
||
if (stdout !== catData) { | ||
return cb(false) | ||
} | ||
|
||
cb(true) | ||
})() | ||
} |
This file contains 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,22 @@ | ||
# Memes for my eyes | ||
|
||
Any meme you upload is almost instantly available for retrieval. Other files also. Content is made available by root CID and by CAR shard CID. In this exercise you are going to fetch a text file from the public gateway by it's root CID and log it to the console. | ||
|
||
You can use the `w3s.link` gateway to retrieve the data but the magic of decentralized peer to peer networking means that you should be able to use any gateway. | ||
|
||
To retrieve data from a gateway you should format the request like: | ||
|
||
``` | ||
https://w3s.link/ipfs/<CID> | ||
``` | ||
|
||
The CID of the data to fetch will be provided to `process.stdin`. | ||
|
||
You should use the `multiformats` library to `decode` the CID from it's compact binary form and then format it as a string in the URL. | ||
|
||
Finally send a HTTP request to fetch the content and write the data directly to `process.stdout`. | ||
|
||
───────────────────────────────────────────────────────────────────────────── | ||
* To print these instructions again, run: `$ADVENTURE_NAME print` | ||
* To verify your program, run: `$ADVENTURE_NAME verify program.js` | ||
* For help run: `$ADVENTURE_NAME help` |
This file contains 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,6 @@ | ||
import fs from 'node:fs' | ||
import { CID } from 'multiformats' | ||
|
||
const cid = CID.decode(fs.readFileSync(process.stdin.fd)) | ||
const res = await fetch(`https://w3s.link/ipfs/${cid}`) | ||
process.stdout.write(await res.text()) |
This file contains 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,14 @@ | ||
Here's the official solution in case you want to compare notes: | ||
|
||
```js | ||
import fs from 'node:fs' | ||
import { CID } from 'multiformats' | ||
|
||
const cid = CID.decode(fs.readFileSync(process.stdin.fd)) | ||
const res = await fetch(`https://w3s.link/ipfs/${cid}`) | ||
process.stdout.write(await res.text()) | ||
``` | ||
|
||
# YOU DID IT! | ||
|
||
Type `$ADVENTURE_NAME` to show the menu. |