Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
897e0f86
Commit
897e0f86
authored
10 years ago
by
Matt Bell
Committed by
Juan Batiz-Benet
10 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmds/ipfs2: Added '/ipfs' HTTP handling
parent
5a18554f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
2 deletions
+91
-2
cmd/ipfs2/daemon.go
cmd/ipfs2/daemon.go
+5
-2
cmd/ipfs2/ipfsHandler.go
cmd/ipfs2/ipfsHandler.go
+86
-0
No files found.
cmd/ipfs2/daemon.go
View file @
897e0f86
...
...
@@ -50,8 +50,11 @@ func daemonFunc(res cmds.Response, req cmds.Request) {
return
}
handler
:=
cmdsHttp
.
NewHandler
(
*
ctx
,
commands
.
Root
)
http
.
Handle
(
cmdsHttp
.
ApiPath
+
"/"
,
handler
)
cmdHandler
:=
cmdsHttp
.
NewHandler
(
*
ctx
,
commands
.
Root
)
http
.
Handle
(
cmdsHttp
.
ApiPath
+
"/"
,
cmdHandler
)
ifpsHandler
:=
&
ipfsHandler
{
node
}
http
.
Handle
(
"/ipfs/"
,
ifpsHandler
)
fmt
.
Printf
(
"API server listening on '%s'
\n
"
,
host
)
...
...
This diff is collapsed.
Click to expand it.
cmd/ipfs2/ipfsHandler.go
0 → 100644
View file @
897e0f86
package
main
import
(
"io"
"net/http"
mh
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
core
"github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/importer"
dag
"github.com/jbenet/go-ipfs/merkledag"
uio
"github.com/jbenet/go-ipfs/unixfs/io"
u
"github.com/jbenet/go-ipfs/util"
)
type
ipfs
interface
{
ResolvePath
(
string
)
(
*
dag
.
Node
,
error
)
NewDagFromReader
(
io
.
Reader
)
(
*
dag
.
Node
,
error
)
AddNodeToDAG
(
nd
*
dag
.
Node
)
(
u
.
Key
,
error
)
NewDagReader
(
nd
*
dag
.
Node
)
(
io
.
Reader
,
error
)
}
type
ipfsHandler
struct
{
node
*
core
.
IpfsNode
}
func
(
i
*
ipfsHandler
)
ResolvePath
(
path
string
)
(
*
dag
.
Node
,
error
)
{
return
i
.
node
.
Resolver
.
ResolvePath
(
path
)
}
func
(
i
*
ipfsHandler
)
NewDagFromReader
(
r
io
.
Reader
)
(
*
dag
.
Node
,
error
)
{
return
importer
.
NewDagFromReader
(
r
)
}
func
(
i
*
ipfsHandler
)
AddNodeToDAG
(
nd
*
dag
.
Node
)
(
u
.
Key
,
error
)
{
return
i
.
node
.
DAG
.
Add
(
nd
)
}
func
(
i
*
ipfsHandler
)
NewDagReader
(
nd
*
dag
.
Node
)
(
io
.
Reader
,
error
)
{
return
uio
.
NewDagReader
(
nd
,
i
.
node
.
DAG
)
}
func
(
i
*
ipfsHandler
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
path
:=
r
.
URL
.
Path
[
5
:
]
nd
,
err
:=
i
.
ResolvePath
(
path
)
if
err
!=
nil
{
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
log
.
Error
(
err
)
w
.
Write
([]
byte
(
err
.
Error
()))
return
}
dr
,
err
:=
i
.
NewDagReader
(
nd
)
if
err
!=
nil
{
// TODO: return json object containing the tree data if it's a directory (err == ErrIsDir)
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
log
.
Error
(
err
)
w
.
Write
([]
byte
(
err
.
Error
()))
return
}
io
.
Copy
(
w
,
dr
)
}
func
(
i
*
ipfsHandler
)
postHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
nd
,
err
:=
i
.
NewDagFromReader
(
r
.
Body
)
if
err
!=
nil
{
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
log
.
Error
(
err
)
w
.
Write
([]
byte
(
err
.
Error
()))
return
}
k
,
err
:=
i
.
AddNodeToDAG
(
nd
)
if
err
!=
nil
{
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
log
.
Error
(
err
)
w
.
Write
([]
byte
(
err
.
Error
()))
return
}
//TODO: return json representation of list instead
w
.
WriteHeader
(
http
.
StatusCreated
)
w
.
Write
([]
byte
(
mh
.
Multihash
(
k
)
.
B58String
()))
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment