diff options
author | Blaster4385 <venkatesh@tablaster.dev> | 2024-06-02 21:34:04 +0530 |
---|---|---|
committer | Blaster4385 <venkatesh@tablaster.dev> | 2024-07-23 01:19:34 +0530 |
commit | c9e5938dbab49c2735507943de7d6b0b4150978e (patch) | |
tree | 7e304207245328c1f09ccadbfcf549e68c2c4267 | |
parent | f0f7c2e2a079033fcfc40795077ba304d4228b8a (diff) |
refactor: return file id and key as json
-rw-r--r-- | server/main.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/server/main.go b/server/main.go index bfc827a..53d1c3d 100644 --- a/server/main.go +++ b/server/main.go @@ -109,8 +109,22 @@ func handleUpload(w http.ResponseWriter, r *http.Request) { } encodedKey := hex.EncodeToString(key) - url := fmt.Sprintf("/download/%s?key=%s", id, encodedKey) - fmt.Fprintf(w, "File uploaded successfully. Download URL: %s", url) + + type UploadResponse struct { + ID string `json:"id"` + Key string `json:"key"` + } + + response := UploadResponse{ + ID: id, + Key: encodedKey, + } + + w.Header().Set("Content-Type", "application/json") + if err := json.NewEncoder(w).Encode(response); err != nil { + handleError(w, fmt.Errorf("error encoding response: %v", err), http.StatusInternalServerError) + return + } } func handleDownload(w http.ResponseWriter, r *http.Request) { |