Skip to content

Commit 04f4873

Browse files
committed
Return a base64-encoded fileid in /app/new to be coherent to other web endpoints
1 parent 28eb9fc commit 04f4873

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

internal/http/services/appprovider/appprovider.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ import (
4949
"github.com/rs/zerolog/log"
5050
)
5151

52+
const (
53+
idDelimiter string = ":"
54+
)
55+
5256
func init() {
5357
global.Register("appprovider", New)
5458
}
@@ -199,14 +203,17 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) {
199203
return
200204
}
201205

202-
// Stat created file and return its file id
206+
// Stat the newly created file
203207
statRes, ocmderr, err := statRef(ctx, provider.Reference{Path: target}, client)
204208
if err != nil {
205209
log.Error().Err(err).Msg("error statting created file")
206210
ocmd.WriteError(w, r, ocmderr, "Created file not found", errtypes.NotFound("Created file not found"))
207211
return
208212
}
209-
js, err := json.Marshal(map[string]interface{}{"file_id": statRes.Id})
213+
214+
// Base64-encode the fileid for the web to consume it
215+
b64id := base64.StdEncoding.EncodeToString([]byte(statRes.Id.StorageId + idDelimiter + statRes.Id.OpaqueId))
216+
js, err := json.Marshal(map[string]interface{}{"file_id": b64id})
210217
if err != nil {
211218
ocmd.WriteError(w, r, ocmd.APIErrorServerError, "error marshalling JSON response", err)
212219
return

0 commit comments

Comments
 (0)