Skip to content

Commit

Permalink
Return a base64-encoded fileid in /app/new to be coherent to other we…
Browse files Browse the repository at this point in the history
…b endpoints
  • Loading branch information
glpatcern committed Sep 24, 2021
1 parent 79ba3fd commit db194e9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/http/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ import (
"github.com/rs/zerolog/log"
)

const (
idDelimiter string = ":"
)

func init() {
global.Register("appprovider", New)
}
Expand Down Expand Up @@ -199,14 +203,17 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) {
return
}

// Stat created file and return its file id
// Stat the newly created file
statRes, ocmderr, err := statRef(ctx, provider.Reference{Path: target}, client)
if err != nil {
log.Error().Err(err).Msg("error statting created file")
ocmd.WriteError(w, r, ocmderr, "Created file not found", errtypes.NotFound("Created file not found"))
return
}
js, err := json.Marshal(map[string]interface{}{"file_id": statRes.Id})

// Base64-encode the fileid for the web to consume it
b64id := base64.StdEncoding.EncodeToString([]byte(statRes.Id.StorageId + idDelimiter + statRes.Id.OpaqueId))
js, err := json.Marshal(map[string]interface{}{"file_id": b64id})
if err != nil {
ocmd.WriteError(w, r, ocmd.APIErrorServerError, "error marshalling JSON response", err)
return
Expand Down

0 comments on commit db194e9

Please sign in to comment.