Skip to content

Commit

Permalink
Addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Sep 23, 2021
1 parent 3b2879b commit ceb8dfa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 43 deletions.
47 changes: 4 additions & 43 deletions internal/http/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
"path"
"strconv"
"strings"
"unicode/utf8"

Expand All @@ -34,12 +31,10 @@ import (
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/internal/http/services/datagateway"
"github.com/cs3org/reva/internal/http/services/ocmd"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/rgrpc/status"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
"github.com/cs3org/reva/pkg/rhttp"
"github.com/cs3org/reva/pkg/rhttp/global"
"github.com/cs3org/reva/pkg/rhttp/router"
"github.com/cs3org/reva/pkg/sharedconf"
Expand Down Expand Up @@ -138,22 +133,15 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) {
errtypes.UserRequired("Missing filename"))
return
}
// stat the container
_, ocmderr, err := statRef(ctx, provider.Reference{Path: r.URL.Query().Get("container")}, client)
if err != nil {
log.Error().Err(err).Msg("error statting container")
ocmd.WriteError(w, r, ocmderr, "Container not found", errtypes.NotFound("Container not found"))
return
}
// Create empty file via storageprovider: obtain the HTTP URL for a PUT
target = path.Join(r.URL.Query().Get("container"), target)

// Create empty file via storageprovider
createReq := &provider.InitiateFileUploadRequest{
Ref: &provider.Reference{Path: target},
Opaque: &typespb.Opaque{
Map: map[string]*typespb.OpaqueEntry{
"Upload-Length": {
Decoder: "plain",
Value: []byte(strconv.FormatInt(0, 10)),
Value: []byte("0"),
},
},
},
Expand All @@ -168,34 +156,6 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) {
return
}

// Do a HTTP PUT with an empty body
var ep, token string
for _, p := range createRes.Protocols {
if p.Protocol == "simple" {
ep, token = p.UploadEndpoint, p.Token
}
}
httpReq, err := rhttp.NewRequest(ctx, http.MethodPut, ep, nil)
if err != nil {
ocmd.WriteError(w, r, ocmd.APIErrorServerError, "error executing PUT", err)
return
}

httpReq.Header.Set(datagateway.TokenTransportHeader, token)
httpRes, err := rhttp.GetHTTPClient().Do(httpReq)
if err != nil {
log.Error().Err(err).Msg("error doing PUT request to data service")
ocmd.WriteError(w, r, ocmd.APIErrorServerError, "error executing PUT", err)
return
}
defer httpRes.Body.Close()
if httpRes.StatusCode != http.StatusOK {
log.Error().Msg("PUT request to data server failed")
ocmd.WriteError(w, r, ocmd.APIErrorServerError, "error executing PUT",
errtypes.InternalError(fmt.Sprint(httpRes.StatusCode)))
return
}

// Stat created file and return its file id
statRes, ocmderr, err := statRef(ctx, provider.Reference{Path: target}, client)
if err != nil {
Expand Down Expand Up @@ -307,6 +267,7 @@ func filterAppsByUserAgent(mimeTypes []*appregistry.MimeTypeInfo, userAgent stri
}
}
if len(apps) > 0 {
m.AppProviders = apps
res = append(res, m)
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/app/registry/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func (b *reg) ListSupportedMimeTypes(ctx context.Context) ([]*registrypb.MimeTyp
mtmap[m].AppProviders = append(mtmap[m].AppProviders, &t)
} else {
mtmap[m] = &registrypb.MimeTypeInfo{
MimeType: m,
AppProviders: []*registrypb.ProviderInfo{&t},
Ext: "", // TODO fetch from config
Name: "",
Expand Down

0 comments on commit ceb8dfa

Please sign in to comment.