From 04f4873616af57061d0adede77ed6d6af312f6fe Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Fri, 24 Sep 2021 16:33:24 +0200 Subject: [PATCH] Return a base64-encoded fileid in /app/new to be coherent to other web endpoints --- internal/http/services/appprovider/appprovider.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/http/services/appprovider/appprovider.go b/internal/http/services/appprovider/appprovider.go index c06b808fc06..0bcba7b453c 100644 --- a/internal/http/services/appprovider/appprovider.go +++ b/internal/http/services/appprovider/appprovider.go @@ -49,6 +49,10 @@ import ( "github.com/rs/zerolog/log" ) +const ( + idDelimiter string = ":" +) + func init() { global.Register("appprovider", New) } @@ -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