-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpost.go
40 lines (33 loc) · 905 Bytes
/
post.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"strings"
"github.com/eris-ltd/toadserver/Godeps/_workspace/src/github.com/eris-ltd/common/go/ipfs"
)
func postHandler(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {
//TODO get amt from url
str := r.URL.Path[1:]
fn := strings.Split(str, "/")[0]
body := r.Body
b, err := ioutil.ReadAll(body)
if err != nil {
fmt.Printf("error reading body: %v\n", err)
}
// which file perms?
err = ioutil.WriteFile(fn, b, 0666)
if err != nil {
fmt.Printf("error writing temp file: %v\n", err)
}
//should just put on whoever is doing the sending's gateway; since cacheHash won't send it there anyways
hash, err := ipfs.SendToIPFS(fn, "eris", bytes.NewBuffer([]byte{}))
if err != nil {
fmt.Printf("error sending to IPFS: %v\n", err)
}
//TODO rm file
_, _ = UpdateNameReg(fn, hash, "")
}
}