Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: photo endpoints, mutex fixes, makefile updates #363

Merged
merged 5 commits into from
Apr 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jobs:
build:
working_directory: /go/src/github.com/qri-io/qri
docker:
- image: circleci/golang:1.9
- image: circleci/golang:1.10.1
environment:
GOLANG_ENV: test
PORT: 3000
Expand Down
7 changes: 7 additions & 0 deletions DEVELOPERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ The `yarn dev` command will launch a development version of the Qri electron app

To get access to Chrome Developer Tools, use the keyboard shortcut Command-Shift-C.

## <a name="Updating"></a> Updating Builds
From time to time versions of packages we depend on may fall out of sync, causing `make build` to fail. In that case, the following should get you back up to speed:

```shell
make update-qri-deps
make install-deps
```


## <a name="rules"></a> Coding Rules
Expand Down
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GOFILES = $(shell find . -name '*.go' -not -path './vendor/*')
GOPACKAGES = $(shell go list ./... | grep -v /vendor/ | grep qri/core)
GOPACKAGES = github.com/briandowns/spinner github.com/datatogether/api/apiutil github.com/fatih/color github.com/ipfs/go-datastore github.com/olekukonko/tablewriter github.com/qri-io/analytics github.com/qri-io/bleve github.com/qri-io/dataset github.com/qri-io/doggos github.com/qri-io/dsdiff github.com/qri-io/varName github.com/sirupsen/logrus github.com/spf13/cobra github.com/spf13/cobra/doc github.com/ugorji/go/codec

default: build

Expand All @@ -12,7 +12,7 @@ build: require-gopath
@echo ""
@echo "1/5 install non-gx deps:"
@echo ""
go get -v -u github.com/briandowns/spinner github.com/datatogether/api/apiutil github.com/fatih/color github.com/ipfs/go-datastore github.com/olekukonko/tablewriter github.com/qri-io/analytics github.com/qri-io/bleve github.com/qri-io/dataset github.com/qri-io/doggos github.com/sirupsen/logrus github.com/spf13/cobra github.com/spf13/viper github.com/qri-io/varName github.com/qri-io/dsdiff github.com/datatogether/cdxj github.com/ugorji/go/codec
go get -v -u $(GOPACKAGES)
@echo ""
@echo "2/5 install gx:"
@echo ""
Expand All @@ -32,8 +32,17 @@ build: require-gopath
go install
@echo "done!"

update-qri-deps: require-gopath
cd $$GOPATH/src/github.com/qri-io/qri && git checkout master && git pull && gx install
cd $$GOPATH/src/github.com/qri-io/cafs && git checkout master && git pull
cd $$GOPATH/src/github.com/qri-io/dataset && git checkout master && git pull
cd $$GOPATH/src/github.com/qri-io/varName && git checkout master && git pull
cd $$GOPATH/src/github.com/qri-io/dsdiff && git checkout master && git pull
cd $$GOPATH/src/github.com/qri-io/jsonschema && git checkout master && git pull
cd $$GOPATH/src/github.com/qri-io/qri

install-deps:
go get -v github.com/briandowns/spinner github.com/datatogether/api/apiutil github.com/fatih/color github.com/ipfs/go-datastore github.com/olekukonko/tablewriter github.com/qri-io/analytics github.com/qri-io/bleve github.com/qri-io/dataset github.com/qri-io/doggos github.com/sirupsen/logrus github.com/spf13/cobra github.com/spf13/viper github.com/qri-io/varName github.com/datatogether/cdxj github.com/spf13/cobra/doc github.com/qri-io/dsdiff github.com/ugorji/go/codec
go get -v -u $(GOPACKAGES)

install-gx:
go get -v -u github.com/whyrusleeping/gx github.com/whyrusleeping/gx-go
Expand Down
42 changes: 38 additions & 4 deletions api/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,35 @@ func (h *ProfileHandlers) saveProfileHandler(w http.ResponseWriter, r *http.Requ
util.WriteResponse(w, res)
}

// SetProfilePhotoHandler is the endpoint for uploading this peer's profile photo
func (h *ProfileHandlers) SetProfilePhotoHandler(w http.ResponseWriter, r *http.Request) {
// ProfilePhotoHandler is the endpoint for uploading this peer's profile photo
func (h *ProfileHandlers) ProfilePhotoHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "OPTIONS":
util.EmptyOkHandler(w, r)
case "GET":
h.getProfilePhotoHandler(w, r)
case "PUT", "POST":
h.setProfilePhotoHandler(w, r)
default:
util.NotFoundHandler(w, r)
}
}

func (h *ProfileHandlers) getProfilePhotoHandler(w http.ResponseWriter, r *http.Request) {
data := []byte{}
req := &core.Profile{
Peername: r.FormValue("peername"),
ID: r.FormValue("id"),
}
if err := h.ProfilePhoto(req, &data); err != nil {
util.WriteErrResponse(w, http.StatusInternalServerError, err)
return
}

w.Header().Set("Content-Type", "image/jpeg")
w.Write(data)
}

func (h *ProfileHandlers) setProfilePhotoHandler(w http.ResponseWriter, r *http.Request) {
p := &core.FileParams{}
if r.Header.Get("Content-Type") == "application/json" {
Expand Down Expand Up @@ -106,18 +123,35 @@ func (h *ProfileHandlers) setProfilePhotoHandler(w http.ResponseWriter, r *http.
util.WriteResponse(w, res)
}

// SetPosterHandler is the endpoint for uploading this peer's poster photo
func (h *ProfileHandlers) SetPosterHandler(w http.ResponseWriter, r *http.Request) {
// PosterHandler is the endpoint for uploading this peer's poster photo
func (h *ProfileHandlers) PosterHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "OPTIONS":
util.EmptyOkHandler(w, r)
case "GET":
h.getPosterHandler(w, r)
case "PUT", "POST":
h.setPosterHandler(w, r)
default:
util.NotFoundHandler(w, r)
}
}

func (h *ProfileHandlers) getPosterHandler(w http.ResponseWriter, r *http.Request) {
data := []byte{}
req := &core.Profile{
Peername: r.FormValue("peername"),
ID: r.FormValue("id"),
}
if err := h.PosterPhoto(req, &data); err != nil {
util.WriteErrResponse(w, http.StatusInternalServerError, err)
return
}

w.Header().Set("Content-Type", "image/jpeg")
w.Write(data)
}

func (h *ProfileHandlers) setPosterHandler(w http.ResponseWriter, r *http.Request) {
p := &core.FileParams{}
if r.Header.Get("Content-Type") == "application/json" {
Expand Down
6 changes: 3 additions & 3 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ func NewServerRoutes(s *Server) *http.ServeMux {
m.Handle("/ipns/", s.middleware(s.HandleIPNSPath))

proh := NewProfileHandlers(s.qriNode.Repo, s.cfg.API.ReadOnly)
m.Handle("/profile", s.middleware(proh.ProfileHandler))
m.Handle("/me", s.middleware(proh.ProfileHandler))
m.Handle("/profile/photo", s.middleware(proh.SetProfilePhotoHandler))
m.Handle("/profile/poster", s.middleware(proh.SetPosterHandler))
m.Handle("/profile", s.middleware(proh.ProfileHandler))
m.Handle("/profile/photo", s.middleware(proh.ProfilePhotoHandler))
m.Handle("/profile/poster", s.middleware(proh.PosterHandler))

ph := NewPeerHandlers(s.qriNode.Repo, s.qriNode, s.cfg.API.ReadOnly)
m.Handle("/peers", s.middleware(ph.PeersHandler))
Expand Down
2 changes: 1 addition & 1 deletion api/testdata/profileResponse.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"homeUrl": "http://test.url",
"color": "default",
"thumb": "/map/QmRdexT18WuAKVX3vPusqmJTWLeNSeJgjmMbaF5QLGHna1",
"profile": "",
"photo": "/map/QmRdexT18WuAKVX3vPusqmJTWLeNSeJgjmMbaF5QLGHna1",
"poster": "/map/QmdJgfxj4rocm88PLeEididS7V2cc9nQosA46RpvAnWvDL",
"twitter": "test"
},
Expand Down
1 change: 1 addition & 0 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func TestCommandsIntegration(t *testing.T) {

path := filepath.Join(os.TempDir(), "qri_test_commands_integration")

// fmt.Printf("temp path: %s", path)
t.Logf("temp path: %s", path)
os.Setenv("IPFS_PATH", filepath.Join(path, "ipfs"))
os.Setenv("QRI_PATH", filepath.Join(path, "qri"))
Expand Down
8 changes: 4 additions & 4 deletions config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Profile struct {
// Thumb path for user's thumbnail
Thumb string `json:"thumb"`
// Profile photo
Profile string `json:"profile"`
Photo string `json:"photo"`
// Poster photo for users's profile page
Poster string `json:"poster"`
// Twitter is a peer's twitter handle
Expand Down Expand Up @@ -107,8 +107,8 @@ func (cfg *Profile) DecodeProfile() (*profile.Profile, error) {
p.Poster = datastore.NewKey(cfg.Poster)
}

if cfg.Profile != "" {
p.Profile = datastore.NewKey(cfg.Profile)
if cfg.Photo != "" {
p.Photo = datastore.NewKey(cfg.Photo)
}

return p, nil
Expand Down Expand Up @@ -292,7 +292,7 @@ func (cfg Profile) Validate() error {
"description": "Location of thumbnail of peer's profile picture, an ipfs hash",
"type": "string"
},
"profile": {
"photo": {
"description": "Location of peer's profile picture, an ipfs hash",
"type": "string"
},
Expand Down
12 changes: 6 additions & 6 deletions config/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ func TestProfileDecodeProfile(t *testing.T) {
}

p = &Profile{
ID: "QmTwtwLMKHHKCrugNxyAaZ31nhBqRUQVysT2xK911n4m6F",
Poster: "foo",
Profile: "bar",
Thumb: "baz",
ID: "QmTwtwLMKHHKCrugNxyAaZ31nhBqRUQVysT2xK911n4m6F",
Poster: "foo",
Photo: "bar",
Thumb: "baz",
}

pro, err := p.DecodeProfile()
Expand All @@ -36,8 +36,8 @@ func TestProfileDecodeProfile(t *testing.T) {
if pro.Poster.String() != "/foo" {
t.Error("poster mismatch")
}
if pro.Profile.String() != "/bar" {
t.Error("profile mismatch")
if pro.Photo.String() != "/bar" {
t.Error("photo mismatch")
}
if pro.Thumb.String() != "/baz" {
t.Error("thumb mismatch")
Expand Down
2 changes: 1 addition & 1 deletion core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestReceivers(t *testing.T) {
}

func testQriNode(cfgs ...func(c *config.P2P)) (*p2p.QriNode, error) {
r, err := repo.NewMemRepo(&profile.Profile{}, cafs.NewMapstore(), profile.MemStore{})
r, err := repo.NewMemRepo(&profile.Profile{}, cafs.NewMapstore(), profile.NewMemStore())
if err != nil {
return nil, err
}
Expand Down
Loading