@@ -3,20 +3,15 @@ package commands
3
3
import (
4
4
"fmt"
5
5
"io"
6
- "net/http "
6
+ "net/url "
7
7
8
8
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
9
9
filestore "github.com/ipfs/go-ipfs/filestore"
10
- pin "github.com/ipfs/go-ipfs/pin"
11
10
12
- cid "github.com/ipfs/go-cid"
13
- chunk "github.com/ipfs/go-ipfs-chunker"
14
11
cmdkit "github.com/ipfs/go-ipfs-cmdkit"
15
12
cmds "github.com/ipfs/go-ipfs-cmds"
16
- balanced "github.com/ipfs/go-unixfs/importer/balanced"
17
- ihelper "github.com/ipfs/go-unixfs/importer/helpers"
18
- trickle "github.com/ipfs/go-unixfs/importer/trickle"
19
- mh "github.com/multiformats/go-multihash"
13
+ files "github.com/ipfs/go-ipfs-files"
14
+ "github.com/ipfs/interface-go-ipfs-core/options"
20
15
)
21
16
22
17
var urlStoreCmd = & cmds.Command {
@@ -32,17 +27,15 @@ var urlAdd = &cmds.Command{
32
27
Helptext : cmdkit.HelpText {
33
28
Tagline : "Add URL via urlstore." ,
34
29
LongDescription : `
30
+ DEPRECATED: Use 'ipfs add --nocopy --cid-version=1 URL'.
31
+
35
32
Add URLs to ipfs without storing the data locally.
36
33
37
34
The URL provided must be stable and ideally on a web server under your
38
35
control.
39
36
40
37
The file is added using raw-leaves but otherwise using the default
41
38
settings for 'ipfs add'.
42
-
43
- This command is considered temporary until a better solution can be
44
- found. It may disappear or the semantics can change at any
45
- time.
46
39
` ,
47
40
},
48
41
Options : []cmdkit.Option {
@@ -55,87 +48,52 @@ time.
55
48
Type : & BlockStat {},
56
49
57
50
Run : func (req * cmds.Request , res cmds.ResponseEmitter , env cmds.Environment ) error {
58
- url := req .Arguments [0 ]
59
- n , err := cmdenv .GetNode (env )
60
- if err != nil {
61
- return err
62
- }
51
+ log .Error ("The 'ipfs urlstore' command is deprecated, please use 'ipfs add --nocopy --cid-version=1" )
63
52
64
- if ! filestore .IsURL (url ) {
65
- return fmt .Errorf ("unsupported url syntax: %s" , url )
53
+ urlString := req .Arguments [0 ]
54
+ if ! filestore .IsURL (req .Arguments [0 ]) {
55
+ return fmt .Errorf ("unsupported url syntax: %s" , urlString )
66
56
}
67
57
68
- cfg , err := n . Repo . Config ( )
58
+ url , err := url . Parse ( urlString )
69
59
if err != nil {
70
60
return err
71
61
}
72
62
73
- if ! cfg .Experimental .UrlstoreEnabled {
74
- return filestore .ErrUrlstoreNotEnabled
75
- }
76
-
77
- useTrickledag , _ := req .Options [trickleOptionName ].(bool )
78
- dopin , _ := req .Options [pinOptionName ].(bool )
79
-
80
63
enc , err := cmdenv .GetCidEncoder (req )
81
64
if err != nil {
82
65
return err
83
66
}
84
67
85
- hreq , err := http . NewRequest ( "GET" , url , nil )
68
+ api , err := cmdenv . GetApi ( env , req )
86
69
if err != nil {
87
70
return err
88
71
}
89
72
90
- hres , err := http .DefaultClient .Do (hreq )
91
- if err != nil {
92
- return err
93
- }
94
- if hres .StatusCode != http .StatusOK {
95
- return fmt .Errorf ("expected code 200, got: %d" , hres .StatusCode )
96
- }
97
-
98
- if dopin {
99
- // Take the pinlock
100
- defer n .Blockstore .PinLock ().Unlock ()
101
- }
73
+ useTrickledag , _ := req .Options [trickleOptionName ].(bool )
74
+ dopin , _ := req .Options [pinOptionName ].(bool )
102
75
103
- chk := chunk .NewSizeSplitter (hres .Body , chunk .DefaultBlockSize )
104
- prefix := cid .NewPrefixV1 (cid .DagProtobuf , mh .SHA2_256 )
105
- dbp := & ihelper.DagBuilderParams {
106
- Dagserv : n .DAG ,
107
- RawLeaves : true ,
108
- Maxlinks : ihelper .DefaultLinksPerBlock ,
109
- NoCopy : true ,
110
- CidBuilder : & prefix ,
111
- URL : url ,
76
+ opts := []options.UnixfsAddOption {
77
+ options .Unixfs .Pin (dopin ),
78
+ options .Unixfs .CidVersion (1 ),
79
+ options .Unixfs .RawLeaves (true ),
80
+ options .Unixfs .Nocopy (true ),
112
81
}
113
82
114
- layout := balanced .Layout
115
83
if useTrickledag {
116
- layout = trickle . Layout
84
+ opts = append ( opts , options . Unixfs . Layout ( options . TrickleLayout ))
117
85
}
118
86
119
- db , err := dbp .New (chk )
120
- if err != nil {
121
- return err
122
- }
123
- root , err := layout (db )
87
+ file := files .NewWebFile (url )
88
+
89
+ path , err := api .Unixfs ().Add (req .Context , file , opts ... )
124
90
if err != nil {
125
91
return err
126
92
}
127
-
128
- c := root .Cid ()
129
- if dopin {
130
- n .Pinning .PinWithMode (c , pin .Recursive )
131
- if err := n .Pinning .Flush (); err != nil {
132
- return err
133
- }
134
- }
135
-
93
+ size , _ := file .Size ()
136
94
return cmds .EmitOnce (res , & BlockStat {
137
- Key : enc .Encode (c ),
138
- Size : int (hres . ContentLength ),
95
+ Key : enc .Encode (path . Cid () ),
96
+ Size : int (size ),
139
97
})
140
98
},
141
99
Encoders : cmds.EncoderMap {
0 commit comments