Skip to content

Commit 2d8f00b

Browse files
committed
generate api pages
1 parent 2b377db commit 2d8f00b

File tree

19 files changed

+1600
-120
lines changed

19 files changed

+1600
-120
lines changed

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ Finally, open [http://localhost:3000](http://localhost:3000) in your browser to
2121
## Editing docs content
2222
Our docs are generated. Use the following steps to make adjustments to the content and update the website to match:
2323

24-
- make your edits to the documentation in the `command-code-examples/commands.mjs` file
24+
- make your edits to the documentation in the `api-code-examples/api.mjs` file
2525
- cd into the `scripts` folder
2626
- run `npm install` if you have not run it in this folder previously
27-
- run `node generate-commands-pages.js` to generate the doc files for the website
27+
- run `node generate-api-pages.js` to generate the doc files for the website
2828

2929
### Style / grammar guide
3030
Follow the style that has already been layed out. But as a general rule of thumb, follow normal English punctuation, but favor brevity over proper grammar. In other words, use capital letters at the start of sentences, and end them with a period, but sentences can be fragments if that gets the point across quicker.

src/app/docs/api/author-list/page.mdx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,24 @@ wkl4cgrykxvcvr6pjnbvymrzm7h4je7d4ztszp35xfnk2rnflcxq
3030
```python {{ title: 'python' }}
3131
import iroh
3232

33-
IROH_DATA_DIR = "./iroh-data"
33+
IROH_DATA_DIR = "./iroh_data_dir"
3434

3535
node = iroh.IrohNode(IROH_DATA_DIR)
3636
print("Started Iroh node: {}".format(node.node_id()))
3737

38-
author = node.author_new()
38+
author = node.author_create()
3939
print("Created author: {}".format(author.to_string()))
4040

4141
authors = node.author_list()
42+
print("Authors:")
4243
for auth in authors:
43-
print("Author: {}".format(auth.to_string()))
44+
print("\t{}".format(auth.to_string()))
45+
46+
# Output:
47+
# Started Iroh node: wbwpkauwmitrwwhmw534w3u6sxyhvbivuepcdze5jd3zeqpgxyfa
48+
# Created author: z2h3f3tozgz67g3ewvu7yxj5vtoddwoohzi2jgyrtgfl7tzocpda
49+
# Authors:
50+
# z2h3f3tozgz67g3ewvu7yxj5vtoddwoohzi2jgyrtgfl7tzocpd
4451

4552
```
4653

@@ -50,26 +57,29 @@ package main
5057
import (
5158
"fmt"
5259

53-
"github.com/n0-computer/iroh-ffi/iroh"
60+
"github.com/n0-computer/iroh-ffi/iroh-go/iroh"
5461
)
5562

5663
func main() {
57-
node, err := iroh.NewIrohNode()
64+
node, err := iroh.NewIrohNode("iroh_data_dir")
5865
if err != nil {
5966
panic(err)
6067
}
6168

62-
if _, err := node.AuthorNew(); err != nil {
69+
author, err := node.AuthorCreate()
70+
if err != nil {
6371
panic(err)
6472
}
73+
fmt.Println("Created author:", author.ToString())
6574

6675
authors, err := node.AuthorList()
6776
if err != nil {
6877
panic(err)
6978
}
7079

80+
fmt.Println("Authors:")
7181
for _, author := range authors {
72-
fmt.Println(author.ToString())
82+
fmt.Println("\t", author.ToString())
7383
}
7484
}
7585

src/app/docs/api/author-new/page.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ author:2rkuvpk4…
4040
```python {{ title: 'python' }}
4141
import iroh
4242

43-
IROH_DATA_DIR = "./iroh-data"
43+
IROH_DATA_DIR = "./iroh_data_dir"
4444

4545
node = iroh.IrohNode(IROH_DATA_DIR)
4646
print("Started Iroh node: {}".format(node.node_id()))
4747

48-
author = node.author_new()
48+
author = node.author_create()
4949
print("Created author: {}".format(author.to_string()))
5050

5151
```
@@ -56,16 +56,16 @@ package main
5656
import (
5757
"fmt"
5858

59-
"github.com/n0-computer/iroh-ffi/iroh"
59+
"github.com/n0-computer/iroh-ffi/iroh-go/iroh"
6060
)
6161

6262
func main() {
63-
node, err := iroh.NewIrohNode()
63+
node, err := iroh.NewIrohNode("iroh_data_dir")
6464
if err != nil {
6565
panic(err)
6666
}
6767

68-
author, err := node.AuthorNew()
68+
author, err := node.AuthorCreate()
6969
if err != nil {
7070
panic(err)
7171
}

src/app/docs/api/blob-add/page.mdx

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,247 @@ Total: 328 B
3838
Collection: bafkr4ie3xsx3vdsbflainnk6p4xs4h2hq3hdmuasuoflkgybvnsbljb3ke
3939
```
4040

41+
```python {{ title: 'python' }}
42+
import os
43+
import sys
44+
import threading
45+
import time
46+
import shutil
47+
import datetime
48+
from iroh import IrohNode, SetTagOption, WrapOption, AddProgressType
49+
50+
class AddCallback:
51+
def progress(self, event):
52+
t = event.type()
53+
if t == AddProgressType.FOUND:
54+
print("AddProgress - Found:")
55+
found = event.as_found()
56+
print(f"\tid: {found.id}, name: {found.name}, size: {found.size}")
57+
elif t == AddProgressType.PROGRESS:
58+
print("AddProgress - Progress:")
59+
progress = event.as_progress()
60+
print(f"\tid: {progress.id}, offset: {progress.offset}")
61+
elif t == AddProgressType.DONE:
62+
print("AddProgress - Done:")
63+
done = event.as_done()
64+
print(f"\tid: {done.id}, hash: {done.hash.to_string()}")
65+
elif t == AddProgressType.ALL_DONE:
66+
print("AddProgress - AllDone:")
67+
all_done = event.as_all_done()
68+
print(f"\thash: {all_done.hash.to_string()}, format: {all_done.format}, tag: {all_done.tag.to_string()}")
69+
elif t == AddProgressType.ABORT:
70+
print("AddProgress - Abort:")
71+
abort = event.as_abort()
72+
print(f"\terror: {abort.error}")
73+
else:
74+
print("Unknown AddProgress event:", event)
75+
76+
# Create folder
77+
os.mkdir("tmp")
78+
79+
try:
80+
path = os.path.abspath(os.path.join("tmp"))
81+
print("Created dir \"tmp\"")
82+
83+
file_names = ["foo", "bar", "bat"]
84+
85+
# Create three files in the folder
86+
for file_name in file_names:
87+
file_path = os.path.join("tmp", file_name)
88+
with open(file_path, "w") as f:
89+
f.write(f"{file_name}")
90+
print(f"Created file {file_path}")
91+
92+
node = IrohNode("iroh_data_dir")
93+
94+
# When `in_place` is True, iroh will NOT copy over the files into its
95+
# internal database. Only use this option when you know the file will never
96+
# move or change.
97+
in_place = False
98+
99+
# Iroh blobs can be "tagged" with human-readable names, this creates a tag
100+
# automatically.
101+
tag = SetTagOption.auto()
102+
103+
# When adding a single file, if you use `WrapOption.wrap()`, you will turn
104+
# the single file into a collection with one entry.
105+
wrap = WrapOption.no_wrap()
106+
107+
# You can use this callback to react to progress updates.
108+
callback = AddCallback()
109+
110+
# Import the directory, creating one blob for each file, and one metadata
111+
# blob that stores the file names for each blob.
112+
# Also creates a 'collection' from the directory, grouping together the
113+
# blobs.
114+
115+
node.blobs_add_from_path(path, in_place, tag, wrap, callback)
116+
except Exception as e:
117+
print("error: ", e)
118+
119+
# cleanup dir
120+
shutil.rmtree("tmp")
121+
122+
# Output:
123+
# Created dir "tmp"
124+
# Created file tmp/foo
125+
# Created file tmp/bar
126+
# Created file tmp/bat
127+
# AddProgress - Found:
128+
# id: 1, name: $HOME/tmp/bar, size: 3
129+
# AddProgress - Found:
130+
# id: 0, name: $HOME/tmp/foo, size: 3
131+
# AddProgress - Found:
132+
# id: 2, name: $HOME/tmp/bat, size: 3
133+
# AddProgress - Progress:
134+
# id: 2, offset: 3
135+
# AddProgress - Progress:
136+
# id: 0, offset: 3
137+
# AddProgress - Done:
138+
# id: 0, hash: bafkr4iae4c5tt4yldi76xcpvg3etxykqkvec352im5fqbutolj2xo5yc5e
139+
# AddProgress - Done:
140+
# id: 2, hash: bafkr4iabccdb2eyeu764xoewbcqv62sjaggxibtmxx5tnmwer3wp3rquq4
141+
# AddProgress - Progress:
142+
# id: 1, offset: 3
143+
# AddProgress - Done:
144+
# id: 1, hash: bafkr4ihs5cl65v6sa3gykxkecwmpuuq2xr22vfuvh2l4amgjmewdbqjjhu
145+
# AddProgress - AllDone:
146+
# hash: bafkr4iaotzhxuiak7eusnngngnwsqdu4crf4lmdxzkbhuebunevecjzkim, format: BlobFormat.HASH_SEQ, tag: "auto-2023-12-09T22:25:45.296Z"
147+
148+
```
149+
150+
```swift {{ title: 'go' }}
151+
package main
152+
153+
import (
154+
"fmt"
155+
"os"
156+
"path/filepath"
157+
158+
"github.com/n0-computer/iroh-ffi/iroh-go/iroh"
159+
)
160+
161+
type addCallback struct {
162+
}
163+
164+
func (a addCallback) Progress(event *iroh.AddProgress) *iroh.IrohError {
165+
switch t := event.Type(); t {
166+
case iroh.AddProgressTypeFound:
167+
fmt.Println("AddProgress - Found:")
168+
found := event.AsFound()
169+
fmt.Printf("\tid: %d, name: %s, size: %d\n", found.Id, found.Name, found.Size)
170+
case iroh.AddProgressTypeProgress:
171+
fmt.Println("AddProgress - Progress:")
172+
progress := event.AsProgress()
173+
fmt.Printf("\tid: %d, offset: %d\n", progress.Id, progress.Offset)
174+
case iroh.AddProgressTypeDone:
175+
fmt.Println("AddProgress - Done:")
176+
done := event.AsDone()
177+
fmt.Printf("\tid: %d, hash: %s\n", done.Id, done.Hash.ToString())
178+
case iroh.AddProgressTypeAllDone:
179+
fmt.Println("AddProgress - AllDone:")
180+
allDone := event.AsAllDone()
181+
fmt.Printf("\thash: %s, format: %v, tag: %s\n", allDone.Hash.ToString(), allDone.Format, allDone.Tag.ToString())
182+
case iroh.AddProgressTypeAbort:
183+
fmt.Println("AddProgress - Abort:")
184+
abort := event.AsAbort()
185+
fmt.Printf("\terror: %s", abort.Error)
186+
default:
187+
fmt.Println("Unknown AddProgress event: %v", event)
188+
return &iroh.IrohError{}
189+
}
190+
return nil
191+
}
192+
193+
func main() {
194+
// create folder
195+
if err := os.Mkdir("tmp", os.ModePerm); err != nil {
196+
panic(err)
197+
}
198+
defer func() {
199+
os.RemoveAll("tmp")
200+
fmt.Println("Removed dir 'tmp'")
201+
}()
202+
203+
path, err := filepath.Abs(filepath.Join("tmp"))
204+
if err != nil {
205+
panic(err)
206+
}
207+
208+
fmt.Println("Created dir \"tmp\"")
209+
210+
fileNames := []string{"foo", "bar", "bat"}
211+
// create three files in the folder
212+
for _, fileName := range fileNames {
213+
path := filepath.Join("tmp", fileName)
214+
f, err := os.Create(path)
215+
if err != nil {
216+
panic(err)
217+
}
218+
_, err = f.WriteString(fmt.Sprintf("%s", fileName))
219+
if err != nil {
220+
panic(err)
221+
}
222+
fmt.Printf("Created file %q\n", path)
223+
}
224+
225+
node, err := iroh.NewIrohNode("iroh_data_dir")
226+
if err != nil {
227+
panic(err)
228+
}
229+
230+
// when `inPlace` is true, iroh will NOT copy over the files into its
231+
// internal database. Only use this option when you know the file will never
232+
// move or change
233+
inPlace := false
234+
// iroh blobs can be "tagged" with human readable names, this creates a tag
235+
// automatically
236+
tag := iroh.SetTagOptionAuto()
237+
// when adding a single file, if you use `iroh.WrapOptionWrap`, you will turn
238+
// the single file into a collection with one entry
239+
wrap := iroh.WrapOptionNoWrap()
240+
// you can use this callback to react to progress updates
241+
callback := addCallback{}
242+
243+
// import the directory, creating one blob for each file, and one metadata
244+
// blob that stores the file names for each blob
245+
// also creates a 'collection' from the directory, grouping together the
246+
// blobs
247+
248+
err = node.BlobsAddFromPath(path, inPlace, tag, wrap, callback)
249+
if err != nil {
250+
panic(err)
251+
}
252+
253+
// Output:
254+
// Created dir "tmp"
255+
// Created file "tmp/foo"
256+
// Created file "tmp/bar"
257+
// Created file "tmp/bat"
258+
// AddProgress - Found:
259+
// id: 2, name: $HOME/tmp/bar, size: 3
260+
// AddProgress - Found:
261+
// id: 0, name: $HOME/tmp/foo, size: 3
262+
// AddProgress - Found:
263+
// id: 1, name: $HOME/tmp/bat, size: 3
264+
// AddProgress - Progress:
265+
// id: 1, offset: 3
266+
// AddProgress - Done:
267+
// id: 1, hash: bafkr4iabccdb2eyeu764xoewbcqv62sjaggxibtmxx5tnmwer3wp3rquq4
268+
// AddProgress - Progress:
269+
// id: 2, offset: 3
270+
// AddProgress - Progress:
271+
// id: 0, offset: 3
272+
// AddProgress - Done:
273+
// id: 2, hash: bafkr4ihs5cl65v6sa3gykxkecwmpuuq2xr22vfuvh2l4amgjmewdbqjjhu
274+
// AddProgress - Done:
275+
// id: 0, hash: bafkr4iae4c5tt4yldi76xcpvg3etxykqkvec352im5fqbutolj2xo5yc5e
276+
// AddProgress - AllDone:
277+
// hash: bafkr4iaotzhxuiak7eusnngngnwsqdu4crf4lmdxzkbhuebunevecjzkim, format: 2, tag: "auto-2023-12-09T17:37:42.432Z"
278+
// Removed dir 'tmp'
279+
}
280+
281+
```
282+
41283

42284
</CodeGroup>

0 commit comments

Comments
 (0)