Skip to content

Commit 9b13981

Browse files
authored
Merge pull request #2 from specious/modern-update
Updated everything so it runs again
2 parents d5582c6 + d85405e commit 9b13981

11 files changed

Lines changed: 353 additions & 398 deletions

File tree

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
2-
dist/
1+
/tipfs
2+
/tipfs.exe

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ go get github.com/treethought/tipfs
1111
```
1212

1313
## Features
14+
1415
- Browse, viewing Mutable File System
1516
- Exploring DAG nodes
1617
- Viewing peers
@@ -31,10 +32,3 @@ go get github.com/treethought/tipfs
3132
| G | Go to bottom of panel |
3233
| 1 | Switch to files mode |
3334
| 2 | Switch to peers mode |
34-
35-
36-
37-
38-
39-
40-

go.mod

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ module github.com/treethought/tipfs
33
go 1.17
44

55
require (
6-
code.rocketnine.space/tslocum/cbind v0.1.5
7-
code.rocketnine.space/tslocum/cview v1.5.7
86
github.com/JohannesKaufmann/html-to-markdown v1.3.0
97
github.com/atotto/clipboard v0.1.4
108
github.com/eliukblau/pixterm v1.3.1
11-
github.com/gdamore/tcell/v2 v2.4.1-0.20210828201608-73703f7ed490
9+
github.com/gdamore/tcell/v2 v2.8.1
1210
github.com/ipfs/go-ipfs-api v0.2.0
1311
github.com/ipfs/go-ipld-format v0.2.0
12+
github.com/rivo/tview v0.42.0
1413
github.com/spf13/cobra v1.2.1
1514
gopkg.in/yaml.v2 v2.4.0
1615
)
@@ -21,7 +20,7 @@ require (
2120
github.com/btcsuite/btcd v0.20.1-beta // indirect
2221
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 // indirect
2322
github.com/disintegration/imaging v1.6.2 // indirect
24-
github.com/gdamore/encoding v1.0.0 // indirect
23+
github.com/gdamore/encoding v1.0.1 // indirect
2524
github.com/gogo/protobuf v1.3.2 // indirect
2625
github.com/inconshreveable/mousetrap v1.0.0 // indirect
2726
github.com/ipfs/go-block-format v0.0.2 // indirect
@@ -33,7 +32,7 @@ require (
3332
github.com/libp2p/go-libp2p-core v0.6.1 // indirect
3433
github.com/libp2p/go-openssl v0.0.7 // indirect
3534
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
36-
github.com/mattn/go-runewidth v0.0.14-0.20210830053702-dc8fe66265af // indirect
35+
github.com/mattn/go-runewidth v0.0.16 // indirect
3736
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
3837
github.com/minio/sha256-simd v0.1.1 // indirect
3938
github.com/mitchellh/go-homedir v1.1.0 // indirect
@@ -45,16 +44,16 @@ require (
4544
github.com/multiformats/go-multibase v0.0.3 // indirect
4645
github.com/multiformats/go-multihash v0.0.14 // indirect
4746
github.com/multiformats/go-varint v0.0.6 // indirect
48-
github.com/rivo/uniseg v0.2.0 // indirect
47+
github.com/rivo/uniseg v0.4.7 // indirect
4948
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
5049
github.com/spaolacci/murmur3 v1.1.0 // indirect
5150
github.com/spf13/pflag v1.0.5 // indirect
5251
github.com/whyrusleeping/tar-utils v0.0.0-20180509141711-8c6c8ba81d5c // indirect
5352
go.opencensus.io v0.23.0 // indirect
54-
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
53+
golang.org/x/crypto v0.23.0 // indirect
5554
golang.org/x/image v0.0.0-20191206065243-da761ea9ff43 // indirect
56-
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
57-
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect
58-
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
59-
golang.org/x/text v0.3.7 // indirect
55+
golang.org/x/net v0.25.0 // indirect
56+
golang.org/x/sys v0.29.0 // indirect
57+
golang.org/x/term v0.28.0 // indirect
58+
golang.org/x/text v0.21.0 // indirect
6059
)

go.sum

Lines changed: 67 additions & 29 deletions
Large diffs are not rendered by default.

ipfs/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ipfs
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"io/ioutil"
78

@@ -11,7 +12,7 @@ import (
1112
)
1213

1314
type DagData struct {
14-
Data string
15+
Data json.RawMessage
1516
Links []ipld.Link
1617
}
1718

ui/content.go

Lines changed: 48 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -8,113 +8,91 @@ import (
88
"log"
99
"net/http"
1010

11-
"code.rocketnine.space/tslocum/cview"
1211
md "github.com/JohannesKaufmann/html-to-markdown"
1312
"github.com/eliukblau/pixterm/pkg/ansimage"
1413
"github.com/gdamore/tcell/v2"
14+
"github.com/rivo/tview"
1515
)
1616

1717
type Content struct {
18-
*cview.TextView
19-
18+
*tview.TextView
2019
app *App
2120
}
2221

2322
func NewContentView(app *App) *Content {
2423
m := &Content{
25-
TextView: cview.NewTextView(),
24+
TextView: tview.NewTextView(),
2625
app: app,
2726
}
28-
2927
m.SetBorder(true)
30-
m.SetPadding(1, 1, 1, 1)
3128
m.SetTitle("content")
3229
m.SetBackgroundColor(tcell.ColorDefault)
33-
3430
return m
3531
}
3632

3733
func (c *Content) Update() {
3834
current := c.app.state.currentFile
39-
path, entry := current.path, current.entry
40-
c.Clear()
41-
42-
data, err := c.app.ipfs.ReadFile(path, entry)
43-
if err != nil {
44-
panic(err)
45-
}
46-
contentType, err := getFileContentType(data)
47-
if err != nil {
48-
c.SetText(err.Error())
49-
}
50-
51-
c.SetTextAlign(cview.AlignLeft)
52-
53-
switch contentType {
54-
case "image/png", "image/jpeg":
55-
56-
c.SetTextAlign(cview.AlignCenter)
57-
c.SetDynamicColors(true)
58-
_, _, w, h := c.GetRect()
59-
r := bytes.NewReader(data)
60-
img := translateImage(r, w, h)
61-
c.SetText(img)
62-
case "text/html; charset=utf-8":
63-
converter := md.NewConverter("", true, nil)
64-
markdown, err := converter.ConvertBytes(data)
65-
if err != nil {
66-
log.Fatal(err)
67-
}
68-
c.SetText(string(markdown))
69-
70-
case "text/plain; charset=utf-8":
71-
c.Write(data)
72-
73-
case "audio/wave", "audio/mp3", "audio/ogg":
74-
c.SetText(fmt.Sprintf("contentType: %s\nPress 'o' to play in browser", contentType))
75-
76-
default:
77-
c.SetText(fmt.Sprintf("ContentType: %s\nPress 'o' to open in browser", contentType))
35+
if current.entry == nil {
36+
return
7837
}
38+
c.Clear()
7939

80-
c.ScrollToBeginning()
81-
40+
go func() {
41+
data, err := c.app.ipfs.ReadFile(current.path, current.entry)
42+
c.app.ui.QueueUpdateDraw(func() {
43+
if err != nil {
44+
c.SetText(fmt.Sprintf("error: %v", err))
45+
return
46+
}
47+
contentType, err := getFileContentType(data)
48+
if err != nil {
49+
c.SetText(err.Error())
50+
return
51+
}
52+
c.SetTextAlign(tview.AlignLeft)
53+
switch contentType {
54+
case "image/png", "image/jpeg":
55+
c.SetTextAlign(tview.AlignCenter)
56+
c.SetDynamicColors(true)
57+
_, _, w, h := c.GetRect()
58+
img := translateImage(bytes.NewReader(data), w, h)
59+
c.SetText(img)
60+
case "text/html; charset=utf-8":
61+
converter := md.NewConverter("", true, nil)
62+
markdown, err := converter.ConvertBytes(data)
63+
if err != nil {
64+
log.Fatal(err)
65+
}
66+
c.SetText(string(markdown))
67+
case "text/plain; charset=utf-8":
68+
c.Write(data)
69+
case "audio/wave", "audio/mp3", "audio/ogg":
70+
c.SetText(fmt.Sprintf("contentType: %s\nPress 'o' to play in browser", contentType))
71+
default:
72+
c.SetText(fmt.Sprintf("ContentType: %s\nPress 'o' to open in browser", contentType))
73+
}
74+
c.ScrollToBeginning()
75+
})
76+
}()
8277
}
8378

8479
func translateImage(reader io.Reader, x, y int) string {
8580
img, err := buildImage(reader, x, y)
8681
if err != nil {
8782
return ""
8883
}
89-
ansi := img.Render()
90-
return cview.TranslateANSI(ansi)
91-
84+
return tview.TranslateANSI(img.Render())
9285
}
9386

9487
func buildImage(reader io.Reader, x, y int) (*ansimage.ANSImage, error) {
95-
pix, err := ansimage.NewScaledFromReader(reader, y, x, color.Transparent, ansimage.ScaleModeFit, ansimage.NoDithering)
96-
if err != nil {
97-
return nil, err
98-
}
99-
return pix, nil
100-
88+
return ansimage.NewScaledFromReader(reader, y, x, color.Transparent, ansimage.ScaleModeFit, ansimage.NoDithering)
10189
}
10290

10391
func getFileContentType(data []byte) (string, error) {
104-
105-
s := bytes.NewBuffer(data)
106-
107-
// Only the first 512 bytes are used to sniff the content type.
108-
buffer := make([]byte, 512)
109-
110-
_, err := s.Read(buffer)
92+
buf := make([]byte, 512)
93+
n, err := bytes.NewBuffer(data).Read(buf)
11194
if err != nil {
11295
return "", err
11396
}
114-
115-
// Use the net/http package's handy DectectContentType function. Always returns a valid
116-
// content-type by returning "application/octet-stream" if no others seemed to match.
117-
contentType := http.DetectContentType(buffer)
118-
119-
return contentType, nil
97+
return http.DetectContentType(buf[:n]), nil
12098
}

0 commit comments

Comments
 (0)