@@ -11,12 +11,13 @@ import (
1111 "expo-open-ota/internal/types"
1212 "expo-open-ota/internal/update"
1313 "fmt"
14- "github.com/google/uuid"
15- "github.com/gorilla/mux"
1614 "log"
1715 "net/http"
1816 "path/filepath"
1917 "time"
18+
19+ "github.com/google/uuid"
20+ "github.com/gorilla/mux"
2021)
2122
2223type FileNamesRequest struct {
@@ -38,17 +39,12 @@ func MarkUpdateAsUploadedHandler(w http.ResponseWriter, r *http.Request) {
3839 http .Error (w , "No branch provided" , http .StatusBadRequest )
3940 return
4041 }
41- err := branch .UpsertBranch (branchName )
42- if err != nil {
43- log .Printf ("[RequestID: %s] Error upserting branch: %v" , requestID , err )
44- http .Error (w , "Error upserting branch" , http .StatusInternalServerError )
45- return
46- }
4742 expoAuth := helpers .GetExpoAuth (r )
4843 expoAccount , err := services .ValidateExpoAuth (expoAuth )
4944 if err != nil {
5045 log .Printf ("[RequestID: %s] Error validating expo auth: %v" , requestID , err )
5146 http .Error (w , "Error validating expo auth" , http .StatusUnauthorized )
47+ return
5248 }
5349 if expoAccount == nil {
5450 log .Printf ("[RequestID: %s] No expo account found" , requestID )
@@ -67,6 +63,12 @@ func MarkUpdateAsUploadedHandler(w http.ResponseWriter, r *http.Request) {
6763 http .Error (w , "No update id provided" , http .StatusBadRequest )
6864 return
6965 }
66+ err = branch .UpsertBranch (branchName )
67+ if err != nil {
68+ log .Printf ("[RequestID: %s] Error upserting branch: %v" , requestID , err )
69+ http .Error (w , "Error upserting branch" , http .StatusInternalServerError )
70+ return
71+ }
7072 currentUpdate , err := update .GetUpdate (branchName , runtimeVersion , updateId )
7173 if err != nil {
7274 log .Printf ("[RequestID: %s] Error getting update: %v" , requestID , err )
@@ -149,6 +151,7 @@ func RequestUploadLocalFileHandler(w http.ResponseWriter, r *http.Request) {
149151 if err != nil || expoAccount == nil {
150152 log .Printf ("[RequestID: %s] Error validating expo auth: %v" , requestID , err )
151153 http .Error (w , "Error validating expo auth" , http .StatusUnauthorized )
154+ return
152155 }
153156 token := r .URL .Query ().Get ("token" )
154157 if token == "" {
@@ -207,25 +210,14 @@ func RequestUploadUrlHandler(w http.ResponseWriter, r *http.Request) {
207210 if err != nil || expoAccount == nil {
208211 log .Printf ("[RequestID: %s] Error validating expo auth: %v" , requestID , err )
209212 http .Error (w , "Error validating expo auth" , http .StatusUnauthorized )
210- }
211-
212- err = branch .UpsertBranch (branchName )
213- if err != nil {
214- log .Printf ("[RequestID: %s] Error upserting branch: %v" , requestID , err )
215- http .Error (w , "Error upserting branch" , http .StatusInternalServerError )
216- return
217- }
218-
219- if expoAccount == nil {
220- log .Printf ("[RequestID: %s] No expo account found" , requestID )
221- http .Error (w , "No expo account found" , http .StatusUnauthorized )
222213 return
223214 }
224215
225216 platform := r .URL .Query ().Get ("platform" )
226217 if platform != "" && (platform != "ios" && platform != "android" ) {
227218 log .Printf ("[RequestID: %s] Invalid platform: %s" , requestID , platform )
228219 http .Error (w , "Invalid platform" , http .StatusBadRequest )
220+ return
229221 }
230222 commitHash := r .URL .Query ().Get ("commitHash" )
231223 runtimeVersion := r .URL .Query ().Get ("runtimeVersion" )
@@ -248,6 +240,13 @@ func RequestUploadUrlHandler(w http.ResponseWriter, r *http.Request) {
248240 return
249241 }
250242
243+ err = branch .UpsertBranch (branchName )
244+ if err != nil {
245+ log .Printf ("[RequestID: %s] Error upserting branch: %v" , requestID , err )
246+ http .Error (w , "Error upserting branch" , http .StatusInternalServerError )
247+ return
248+ }
249+
251250 updateId := update .GenerateUpdateTimestamp ()
252251 updateRequests , err := bucket .RequestUploadUrlsForFileUpdates (branchName , runtimeVersion , update .ConvertUpdateTimestampToString (updateId ), request .FileNames )
253252 if err != nil {
@@ -274,6 +273,12 @@ func RequestUploadUrlHandler(w http.ResponseWriter, r *http.Request) {
274273 CreatedAt : time .Duration (updateId ) * time .Millisecond ,
275274 }, "update-metadata.json" , metadataReader )
276275
276+ if err != nil {
277+ log .Printf ("[RequestID: %s] Error uploading file update metadata: %v" , requestID , err )
278+ http .Error (w , "Error uploading file update metadata" , http .StatusInternalServerError )
279+ return
280+ }
281+
277282 cache := cache2 .GetCache ()
278283 cacheKey := update .ComputeLastUpdateCacheKey (branchName , runtimeVersion , platform )
279284 cache .Delete (cacheKey )
0 commit comments